diff options
author | Leah Neukirchen <leah@vuxu.org> | 2020-05-09 23:50:48 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2020-05-09 23:50:48 +0200 |
commit | 418853dc10e8a9de715155f0820e44e7d66ae164 (patch) | |
tree | e674a2eee5b575c2ce3ea77887966e6c6e9569c2 | |
parent | 92e835113c095428b049f966c7976d9d169e8611 (diff) | |
download | hittpd-418853dc10e8a9de715155f0820e44e7d66ae164.tar.gz hittpd-418853dc10e8a9de715155f0820e44e7d66ae164.tar.xz hittpd-418853dc10e8a9de715155f0820e44e7d66ae164.zip |
better error handling in write_client
-rw-r--r-- | hittpd.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/hittpd.c b/hittpd.c index 9e3a90e..bbc94ac 100644 --- a/hittpd.c +++ b/hittpd.c @@ -795,15 +795,19 @@ write_client(int i) if (data->stream_fd >= 0) { #ifndef __linux__ char buf[16*4096]; - size_t n = pread(data->stream_fd, buf, sizeof buf, data->off); - if (n < 0) - ; // XXX - else if (n == 0) { + ssize_t n = pread(data->stream_fd, buf, sizeof buf, data->off); + if (n < 0) { + if (errno == EAGAIN) + return; + close_connection(i); + } else if (n == 0) { finish_response(i); } else if (n > 0) { w = write(sockfd, buf, n); if (w > 0) data->off += w; + if (w == 0 || data->off == data->last) + finish_response(i); } #else w = sendfile(sockfd, data->stream_fd, @@ -825,9 +829,9 @@ write_client(int i) } if (w < 0) { - if (errno == EPIPE) - close_connection(i); - // XXX other error handling + if (errno == EAGAIN) + return; + close_connection(i); // in particular, EPIPE and ECONNRESET } } |