2
0
Fork 0

Handle write errors (fixes ab keep-alive problems)

personal/stbuehler/wip
Stefan Bühler 2008-08-07 02:25:02 +02:00
parent 76dcab54fc
commit 1ed36c93b9
4 changed files with 26 additions and 6 deletions

View File

@ -61,7 +61,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) {
if (revents & EV_READ) {
if (con->in->is_closed) {
/* don't read the next request before current one is done */
ev_io_set(w, w->fd, w->events && ~EV_READ);
ev_io_rem_events(loop, w, EV_READ);
} else {
switch (network_read(srv, con, w->fd, con->raw_in)) {
case NETWORK_STATUS_SUCCESS:
@ -91,9 +91,30 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) {
if (revents & EV_WRITE) {
if (con->raw_out->length > 0) {
network_write(srv, con, w->fd, con->raw_out);
switch (network_write(srv, con, w->fd, con->raw_out)) {
case NETWORK_STATUS_SUCCESS:
dojoblist = TRUE;
break;
case NETWORK_STATUS_FATAL_ERROR:
connection_set_state(srv, con, CON_STATE_ERROR);
dojoblist = TRUE;
break;
case NETWORK_STATUS_CONNECTION_CLOSE:
connection_set_state(srv, con, CON_STATE_CLOSE);
dojoblist = TRUE;
break;
case NETWORK_STATUS_WAIT_FOR_EVENT:
break;
case NETWORK_STATUS_WAIT_FOR_AIO_EVENT:
/* TODO ? */
ev_io_rem_events(loop, w, EV_WRITE);
break;
case NETWORK_STATUS_WAIT_FOR_FD:
/* TODO */
ev_io_rem_events(loop, w, EV_WRITE);
break;
}
// CON_TRACE(srv, con, "cq->len: raw_out=%i, out=%i", (int) con->raw_out->length, (int) con->out->length);
dojoblist = TRUE;
}
if (con->raw_out->length == 0) {
// CON_TRACE(srv, con, "%s", "stop write");

View File

@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
TRACE(srv, "%s", "Test!");
//srv->log_stderr = log_new(srv, LOG_TYPE_FILE, g_string_new("lightytest.log"));
/* srv->log_stderr = log_new(srv, LOG_TYPE_FILE, g_string_new("lightytest.log")); */
log_write_(srv, NULL, LOG_LEVEL_WARNING, "test %s", "foo1");
log_warning(srv, NULL, "test %s", "foo1"); /* duplicate won't be logged */
log_warning(srv, NULL, "test %s", "foo2");

View File

@ -108,7 +108,6 @@ network_status_t network_read(server *srv, connection *con, int fd, chunkqueue *
}
g_string_truncate(buf, r);
chunkqueue_append_string(cq, buf);
CON_TRACE(srv, con, "read (%i) '%s'", (int) r, buf->str);
len += r;
} while (r == blocksize && len < max_read);

View File

@ -99,7 +99,7 @@ void request_validate_header(server *srv, connection *con) {
return;
} else if (hh) {
g_string_append_len(req->host, GSTR_LEN((GString*) g_queue_peek_head(&hh->values)));
CON_TRACE(srv, con, "hostname: '%s'", req->host->str);
// CON_TRACE(srv, con, "hostname: '%s'", req->host->str);
}
/* content-length */