Browse Source

Fix handling network-write return values (#2024)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2596 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.24
Stefan Bühler 13 years ago
parent
commit
9e6b2c63f0
  1. 1
      NEWS
  2. 5
      src/mod_fastcgi.c
  3. 15
      src/mod_proxy.c
  4. 13
      src/mod_scgi.c
  5. 5
      src/network_backends.h
  6. 70
      src/network_write.c

1
NEWS

@ -27,6 +27,7 @@ NEWS
* Remove strptime failed message (fixes #2031)
* Fix issues found with clang analyzer
* Try to fix server.tag issue with localized svnversion
* Fix handling network-write return values (#2024)
- 1.4.23 - 2009-06-19
* Added some extra warning options in cmake and fix the resulting warnings (unused/static functions)

5
src/mod_fastcgi.c

@ -3049,11 +3049,6 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
"reconnect attempts:", hctx->reconnects);
return HANDLER_ERROR;
case EAGAIN:
case EINTR:
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd",
"write failed:", strerror(errno), errno);

15
src/mod_proxy.c

@ -842,17 +842,14 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
chunkqueue_remove_finished_chunks(hctx->wb);
if (-1 == ret) {
if (errno != EAGAIN &&
errno != EINTR) {
log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
if (-1 == ret) { /* error on our side */
log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
return HANDLER_ERROR;
} else {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
} else if (-2 == ret) { /* remote close */
log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed, remote connection close:", strerror(errno), errno);
return HANDLER_WAIT_FOR_EVENT;
}
return HANDLER_WAIT_FOR_EVENT;
}
if (hctx->wb->bytes_out == hctx->wb->bytes_in) {

13
src/mod_scgi.c

@ -2344,19 +2344,12 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
"reconnect attempts:", hctx->reconnects);
return HANDLER_ERROR;
}
if ((errno != EAGAIN) &&
(errno != EINTR)) {
} else {
/* -1 == ret => error on our side */
log_error_write(srv, __FILE__, __LINE__, "ssd",
"write failed:", strerror(errno), errno);
"write failed:", strerror(errno), errno);
return HANDLER_ERROR;
} else {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
return HANDLER_WAIT_FOR_EVENT;
}
}

5
src/network_backends.h

@ -45,6 +45,11 @@
#include "base.h"
/* return values:
* >= 0 : chunks completed
* -1 : error (on our side)
* -2 : remote close
*/
int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqueue *cq);
int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq);

70
src/network_write.c

@ -46,15 +46,27 @@ int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqu
toSend = c->mem->used - 1 - c->offset;
#ifdef __WIN32
if ((r = send(fd, offset, toSend, 0)) < 0) {
log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed: ", strerror(errno), fd);
/* no error handling for windows... */
log_error_write(srv, __FILE__, __LINE__, "ssd", "send failed: ", strerror(errno), fd);
return -1;
}
#else
if ((r = write(fd, offset, toSend)) < 0) {
log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed: ", strerror(errno), fd);
return -1;
switch (errno) {
case EAGAIN:
case EINTR:
r = 0;
break;
case EPIPE:
case ECONNRESET:
return -2;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd",
"write failed:", strerror(errno), fd);
return -1;
}
}
#endif
@ -98,7 +110,7 @@ int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqu
return -1;
}
#if defined USE_MMAP
#ifdef USE_MMAP
if (MAP_FAILED == (p = mmap(0, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
log_error_write(srv, __FILE__, __LINE__, "ss", "mmap failed: ", strerror(errno));
@ -109,13 +121,26 @@ int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqu
close(ifd);
if ((r = write(fd, p + offset, toSend)) <= 0) {
log_error_write(srv, __FILE__, __LINE__, "ss", "write failed: ", strerror(errno));
munmap(p, sce->st.st_size);
return -1;
switch (errno) {
case EAGAIN:
case EINTR:
r = 0;
break;
case EPIPE:
case ECONNRESET:
munmap(p, sce->st.st_size);
return -2;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd",
"write failed:", strerror(errno), fd);
munmap(p, sce->st.st_size);
return -1;
}
}
munmap(p, sce->st.st_size);
#else
#else /* USE_MMAP */
buffer_prepare_copy(srv->tmp_buf, toSend);
lseek(ifd, offset, SEEK_SET);
@ -127,12 +152,33 @@ int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqu
}
close(ifd);
if (-1 == (r = send(fd, srv->tmp_buf->ptr, toSend, 0))) {
log_error_write(srv, __FILE__, __LINE__, "ss", "write: ", strerror(errno));
#ifdef __WIN32
if ((r = send(fd, srv->tmp_buf->ptr, toSend, 0)) < 0) {
/* no error handling for windows... */
log_error_write(srv, __FILE__, __LINE__, "ssd", "send failed: ", strerror(errno), fd);
return -1;
}
#endif
#else /* __WIN32 */
if ((r = write(fd, srv->tmp_buf->ptr, toSend)) < 0) {
switch (errno) {
case EAGAIN:
case EINTR:
r = 0;
break;
case EPIPE:
case ECONNRESET:
return -2;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd",
"write failed:", strerror(errno), fd);
return -1;
}
}
#endif /* __WIN32 */
#endif /* USE_MMAP */
c->offset += r;
cq->bytes_out += r;

Loading…
Cancel
Save