Browse Source

Fix connection/network_write state machine

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent
commit
2040c059d1
  1. 3
      include/lighttpd/network.h
  2. 8
      src/connection.c
  3. 3
      src/network.c

3
include/lighttpd/network.h

@ -13,7 +13,8 @@ typedef enum {
NETWORK_STATUS_SUCCESS, /**< some IO was actually done (read/write) or cq was empty for write */
NETWORK_STATUS_FATAL_ERROR,
NETWORK_STATUS_CONNECTION_CLOSE,
NETWORK_STATUS_WAIT_FOR_EVENT, /**< read/write returned -1 with errno=EAGAIN/EWOULDBLOCK; no real IO was done */
NETWORK_STATUS_WAIT_FOR_EVENT, /**< read/write returned -1 with errno=EAGAIN/EWOULDBLOCK; no real IO was done
internal: some io may be done */
NETWORK_STATUS_WAIT_FOR_AIO_EVENT, /**< nothing done yet, read/write will be done somewhere else */
NETWORK_STATUS_WAIT_FOR_FD, /**< need a fd to open a file */
} network_status_t;

8
src/connection.c

@ -206,7 +206,6 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) {
}
if (revents & EV_WRITE) {
ev_io_rem_events(loop, w, EV_WRITE);
if (con->raw_out->length > 0) {
switch (network_write(con->mainvr, w->fd, con->raw_out)) {
case NETWORK_STATUS_SUCCESS:
@ -222,12 +221,19 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) {
case NETWORK_STATUS_WAIT_FOR_EVENT:
break;
case NETWORK_STATUS_WAIT_FOR_AIO_EVENT:
ev_io_rem_events(loop, w, EV_WRITE);
CON_ERROR(con, "%s", "TODO: wait for aio");
/* TODO: aio */
break;
case NETWORK_STATUS_WAIT_FOR_FD:
ev_io_rem_events(loop, w, EV_WRITE);
CON_ERROR(con, "%s", "TODO: wait for fd");
/* TODO: wait for fd */
break;
}
} else {
CON_TRACE(con, "%s", "write event for empty queue");
ev_io_rem_events(loop, w, EV_WRITE);
}
}

3
src/network.c

@ -74,6 +74,8 @@ network_status_t network_write(vrequest *vr, int fd, chunkqueue *cq) {
#else
res = network_write_writev(con, fd, cq, &write_bytes);
#endif
wrote = write_max - write_bytes;
if (wrote > 0 && res == NETWORK_STATUS_WAIT_FOR_EVENT) res = NETWORK_STATUS_SUCCESS;
#ifdef TCP_CORK
if (corked) {
@ -92,7 +94,6 @@ network_status_t network_write(vrequest *vr, int fd, chunkqueue *cq) {
}
/* stats */
wrote = write_max - write_bytes;
wrk = vr->con->wrk;
wrk->stats.bytes_out += wrote;
vr->con->stats.bytes_out += wrote;

Loading…
Cancel
Save