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;
}