diff --git a/src/tcp.c b/src/tcp.c index cab3c5ff..88f37a02 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -181,13 +181,33 @@ int tcp_write_queue(int fd, htsbuf_queue_t *q) { htsbuf_data_t *hd; - int l, r = 0; + int l, r = 0, l2; + uint8_t* p; while((hd = TAILQ_FIRST(&q->hq_q)) != NULL) { TAILQ_REMOVE(&q->hq_q, hd, hd_link); l = hd->hd_data_len - hd->hd_data_off; - r |= !!write(fd, hd->hd_data + hd->hd_data_off, l); + p = hd->hd_data + hd->hd_data_off; + + while(l > 0) { + l2 = write(fd, p, l); + if(l2 < 0) { + perror("tcp_write_queue"); + if(errno == EINTR) { + continue; + } else { + break; + } + } + l -= l2; + p += l2; + } + + if(l == 0) { + r = 1; + } + free(hd->hd_data); free(hd); } diff --git a/src/webui/webui.c b/src/webui/webui.c index fbd0416f..c6f2b8d5 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -98,12 +98,12 @@ page_root2(http_connection_t *hc, const char *remain, void *opaque) static int page_static_file(http_connection_t *hc, const char *remain, void *opaque) { - int ret = 0; + int ret = 0, r; const char *base = opaque; char path[500]; ssize_t size; const char *content = NULL, *postfix; - char buf[4096]; + char buf[4096], *p; const char *gzip; if(remain == NULL) @@ -139,7 +139,21 @@ page_static_file(http_connection_t *hc, const char *remain, void *opaque) ret = 500; break; } - if (write(hc->hc_fd, buf, c) != c) { + p = buf; + while(c > 0) { + r = write(hc->hc_fd, p, c); + if(r < 0) { + perror("page_static_file"); + if(errno == EINTR) { + continue; + } else { + break; + } + } + c -= r; + p += r; + } + if (c != 0) { ret = 500; break; }