tcp: socket writes get interrupted so must be retried

This commit is contained in:
Joakim Plate 2012-12-29 20:37:30 +01:00
parent 19fb12798b
commit f980a3abe3
2 changed files with 39 additions and 5 deletions

View file

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

View file

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