|
|
|
@ -110,6 +110,7 @@ void connection_internal_error(connection *con) {
|
|
|
|
|
|
|
|
|
|
static gboolean connection_handle_read(connection *con) {
|
|
|
|
|
vrequest *vr = con->mainvr;
|
|
|
|
|
|
|
|
|
|
if (con->raw_in->length == 0) return TRUE;
|
|
|
|
|
|
|
|
|
|
if (con->state == CON_STATE_KEEP_ALIVE) {
|
|
|
|
@ -124,10 +125,7 @@ static gboolean connection_handle_read(connection *con) {
|
|
|
|
|
con->state = CON_STATE_READ_REQUEST_HEADER;
|
|
|
|
|
con->ts = CUR_TS(con->wrk);
|
|
|
|
|
|
|
|
|
|
connection_io_timeout_init(con);
|
|
|
|
|
} else {
|
|
|
|
|
if (vr->con->io_timeout.last_io != CUR_TS(vr->con->wrk))
|
|
|
|
|
connection_io_timeout_reset(con);
|
|
|
|
|
if (con->state == CON_STATE_REQUEST_START)
|
|
|
|
|
con->state = CON_STATE_READ_REQUEST_HEADER;
|
|
|
|
|
}
|
|
|
|
@ -325,6 +323,8 @@ connection* connection_new(worker *wrk) {
|
|
|
|
|
ev_init(&con->keep_alive_data.watcher, connection_keepalive_cb);
|
|
|
|
|
con->keep_alive_data.watcher.data = con;
|
|
|
|
|
|
|
|
|
|
con->io_timeout_elem.data = con;
|
|
|
|
|
|
|
|
|
|
return con;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -373,7 +373,7 @@ void connection_reset(connection *con) {
|
|
|
|
|
con->stats.last_avg = 0;
|
|
|
|
|
|
|
|
|
|
/* remove from timeout queue */
|
|
|
|
|
connection_io_timeout_remove(con);
|
|
|
|
|
waitqueue_remove(&con->wrk->io_timeout_queue, &con->io_timeout_elem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void server_check_keepalive(server *srv);
|
|
|
|
@ -425,7 +425,7 @@ void connection_reset_keep_alive(connection *con) {
|
|
|
|
|
con->stats.bytes_out_5s_diff = G_GUINT64_CONSTANT(0);
|
|
|
|
|
con->stats.last_avg = 0;
|
|
|
|
|
|
|
|
|
|
connection_io_timeout_remove(con);
|
|
|
|
|
waitqueue_remove(&con->wrk->io_timeout_queue, &con->io_timeout_elem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void connection_free(connection *con) {
|
|
|
|
@ -477,57 +477,3 @@ gchar *connection_state_str(connection_state_t state) {
|
|
|
|
|
|
|
|
|
|
return (gchar*)states[state];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void connection_io_timeout_init(connection *con) {
|
|
|
|
|
worker *wrk = con->wrk;
|
|
|
|
|
|
|
|
|
|
if (wrk->io_timeout_queue_tail)
|
|
|
|
|
wrk->io_timeout_queue_tail->io_timeout.next = con;
|
|
|
|
|
else
|
|
|
|
|
/* if there is no tail, it means the queue is empty */
|
|
|
|
|
wrk->io_timeout_queue_head = con;
|
|
|
|
|
|
|
|
|
|
wrk->io_timeout_queue_tail = con;
|
|
|
|
|
con->io_timeout.last_io = CUR_TS(wrk);
|
|
|
|
|
con->io_timeout.next = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void connection_io_timeout_reset(connection *con) {
|
|
|
|
|
/* move con to the end of the timeout queue */
|
|
|
|
|
worker *wrk = con->wrk;
|
|
|
|
|
|
|
|
|
|
if (con == wrk->io_timeout_queue_head && con != wrk->io_timeout_queue_tail)
|
|
|
|
|
wrk->io_timeout_queue_head = con->io_timeout.next;
|
|
|
|
|
|
|
|
|
|
if (con != wrk->io_timeout_queue_tail)
|
|
|
|
|
con->io_timeout.prev = wrk->io_timeout_queue_tail;
|
|
|
|
|
|
|
|
|
|
if (wrk->io_timeout_queue_tail)
|
|
|
|
|
wrk->io_timeout_queue_tail->io_timeout.next = con;
|
|
|
|
|
|
|
|
|
|
con->io_timeout.next = NULL;
|
|
|
|
|
wrk->io_timeout_queue_tail = con;
|
|
|
|
|
con->io_timeout.last_io = CUR_TS(wrk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void connection_io_timeout_remove(connection *con) {
|
|
|
|
|
/* remove con from the timeout queue */
|
|
|
|
|
worker *wrk = con->wrk;
|
|
|
|
|
|
|
|
|
|
/* check if connection is in the timeout queue, it might not be the case when it is in keep alive idle state */
|
|
|
|
|
if (con->io_timeout.prev == NULL && con->io_timeout.next == NULL && con != wrk->io_timeout_queue_head)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (con == wrk->io_timeout_queue_head)
|
|
|
|
|
wrk->io_timeout_queue_head = con->io_timeout.next;
|
|
|
|
|
else
|
|
|
|
|
con->io_timeout.prev->io_timeout.next = con->io_timeout.next;
|
|
|
|
|
|
|
|
|
|
if (con == wrk->io_timeout_queue_tail)
|
|
|
|
|
wrk->io_timeout_queue_tail = con->io_timeout.prev;
|
|
|
|
|
else
|
|
|
|
|
con->io_timeout.next->io_timeout.prev = con->io_timeout.prev;
|
|
|
|
|
|
|
|
|
|
con->io_timeout.prev = NULL;
|
|
|
|
|
con->io_timeout.next = NULL;
|
|
|
|
|
}
|
|
|
|
|