HTSP: Handle partial write()s

This commit is contained in:
Andreas Öman 2012-11-05 13:05:43 +01:00
parent a9692b9514
commit d5deb9d19d

View file

@ -1469,24 +1469,30 @@ htsp_write_scheduler(void *aux)
r = htsmsg_binary_serialize(hm->hm_msg, &dptr, &dlen, INT32_MAX);
#if 0
if(hm->hm_pktref) {
usleep(hm->hm_payloadsize * 3);
}
#endif
htsp_msg_destroy(hm);
/* ignore return value */
r = write(htsp->htsp_fd, dptr, dlen);
if(r != dlen)
tvhlog(LOG_INFO, "htsp", "%s: Write error -- %s",
htsp->htsp_logname, strerror(errno));
free(dptr);
void *freeme = dptr;
while(dlen > 0) {
r = write(htsp->htsp_fd, dptr, dlen);
if(r < 1) {
tvhlog(LOG_INFO, "htsp", "%s: Write error -- %s",
htsp->htsp_logname, strerror(errno));
break;
}
dptr += r;
dlen -= r;
}
free(freeme);
pthread_mutex_lock(&htsp->htsp_out_mutex);
if(r != dlen)
if(dlen)
break;
}
// Shutdown socket to make receive thread terminate entire HTSP connection
shutdown(htsp->htsp_fd, SHUT_RDWR);
pthread_mutex_unlock(&htsp->htsp_out_mutex);
return NULL;
}