Skip to content

Commit

Permalink
Better timeout support while handling POSTs.
Browse files Browse the repository at this point in the history
git-svn-id: svn://cherokee-project.com/cherokee/trunk@4179 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Jan 26, 2010
1 parent bedf48f commit f9f8902
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 20 deletions.
12 changes: 8 additions & 4 deletions cherokee/handler_cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ read_from_cgi (cherokee_handler_cgi_base_t *cgi_base, cherokee_buffer_t *buffer)

switch (ret) {
case ret_eagain:
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi), HANDLER_CONN(cgi), cgi->pipeInput, 0, false);
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi),
HANDLER_CONN(cgi), cgi->pipeInput,
FDPOLL_MODE_READ, false);
return ret_eagain;

case ret_ok:
Expand Down Expand Up @@ -438,15 +440,17 @@ cherokee_handler_cgi_read_post (cherokee_handler_cgi_t *cgi)
return ret_ok;
}

ret = cherokee_post_send_to_fd (&conn->post, &conn->socket,
ret = cherokee_post_send_to_fd (&conn->post, conn, &conn->socket,
cgi->pipeOutput, NULL, &blocking);
switch (ret) {
case ret_ok:
break;
case ret_eagain:
if (blocking == socket_writing) {
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi), conn,
cgi->pipeOutput, 1, false);
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi),
conn, cgi->pipeOutput,
FDPOLL_MODE_WRITE, false);
return ret_deny;
}
return ret_eagain;
default:
Expand Down
20 changes: 13 additions & 7 deletions cherokee/handler_fcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ connect_to_server (cherokee_handler_fcgi_t *hdl)


static ret_t
do_send (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
do_send (cherokee_handler_fcgi_t *hdl,
cherokee_buffer_t *buffer)
{
ret_t ret;
size_t written = 0;
Expand All @@ -582,10 +583,6 @@ do_send (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
cherokee_buffer_move_to_begin (buffer, written);
TRACE (ENTRIES, "sent=%d, remaining=%d\n", written, buffer->len);

if (! cherokee_buffer_is_empty (buffer)) {
return ret_eagain;
}

return ret_ok;
}

Expand Down Expand Up @@ -662,7 +659,11 @@ send_post (cherokee_handler_fcgi_t *hdl,
/* Next iteration
*/
if (! cherokee_buffer_is_empty (buf)) {
return ret_eagain;
cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
HANDLER_CONN(hdl),
hdl->socket.socket,
FDPOLL_MODE_WRITE, false);
return ret_deny;
}

if (! cherokee_post_read_finished (&conn->post)) {
Expand Down Expand Up @@ -731,8 +732,13 @@ cherokee_handler_fcgi_init (cherokee_handler_fcgi_t *hdl)
/* Send the header
*/
ret = do_send (hdl, &hdl->write_buffer);
if (ret != ret_ok)
if (ret != ret_ok) {
return ret;
}

if (! cherokee_buffer_is_empty (&hdl->write_buffer)) {
return ret_eagain;
}

break;
}
Expand Down
3 changes: 2 additions & 1 deletion cherokee/handler_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ send_post (cherokee_handler_proxy_t *hdl)
cherokee_connection_t *conn = HANDLER_CONN(hdl);
cherokee_socket_status_t blocking = socket_closed;

ret = cherokee_post_send_to_socket (&conn->post, &conn->socket,
ret = cherokee_post_send_to_socket (&conn->post, conn, &conn->socket,
&hdl->pconn->socket, NULL, &blocking);
switch (ret) {
case ret_ok:
Expand All @@ -642,6 +642,7 @@ send_post (cherokee_handler_proxy_t *hdl)
cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl), conn,
hdl->pconn->socket.socket,
FDPOLL_MODE_WRITE, false);
return ret_deny;
}
return ret_eagain;

Expand Down
9 changes: 6 additions & 3 deletions cherokee/handler_scgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ read_from_scgi (cherokee_handler_cgi_base_t *cgi_base, cherokee_buffer_t *buffer

switch (ret) {
case ret_eagain:
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base), HANDLER_CONN(cgi_base),
scgi->socket.socket, 0, false);
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base),
HANDLER_CONN(cgi_base),
scgi->socket.socket,
FDPOLL_MODE_READ, false);
return ret_eagain;

case ret_ok:
Expand Down Expand Up @@ -395,7 +397,7 @@ cherokee_handler_scgi_read_post (cherokee_handler_scgi_t *hdl)
cherokee_connection_t *conn = HANDLER_CONN(hdl);
cherokee_socket_status_t blocking = socket_closed;

ret = cherokee_post_send_to_socket (&conn->post, &conn->socket,
ret = cherokee_post_send_to_socket (&conn->post, conn, &conn->socket,
&hdl->socket, NULL, &blocking);
switch (ret) {
case ret_ok:
Expand All @@ -406,6 +408,7 @@ cherokee_handler_scgi_read_post (cherokee_handler_scgi_t *hdl)
cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
conn, hdl->socket.socket,
FDPOLL_MODE_WRITE, false);
return ret_deny;
}
return ret_eagain;

Expand Down
14 changes: 9 additions & 5 deletions cherokee/handler_uwsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ read_from_uwsgi (cherokee_handler_cgi_base_t *cgi_base,

switch (ret) {
case ret_eagain:
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base), HANDLER_CONN(cgi_base),
uwsgi->socket.socket, 0, false);
cherokee_thread_deactive_to_polling (HANDLER_THREAD(cgi_base),
HANDLER_CONN(cgi_base),
uwsgi->socket.socket,
FDPOLL_MODE_READ, false);
return ret_eagain;

case ret_ok:
Expand Down Expand Up @@ -429,16 +431,18 @@ cherokee_handler_uwsgi_read_post (cherokee_handler_uwsgi_t *hdl)

/* Send it
*/
ret = cherokee_post_send_to_socket (&conn->post, &conn->socket,
ret = cherokee_post_send_to_socket (&conn->post, conn, &conn->socket,
&hdl->socket, NULL, &blocking);
switch (ret) {
case ret_ok:
break;

case ret_eagain:
if (blocking == socket_writing) {
cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl), conn,
hdl->socket.socket, 1, false);
cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
conn, hdl->socket.socket,
FDPOLL_MODE_WRITE, false);
return ret_deny;
}
return ret_eagain;

Expand Down
28 changes: 28 additions & 0 deletions cherokee/post.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ do_send_socket (cherokee_socket_t *sock,

ret_t
cherokee_post_send_to_socket (cherokee_post_t *post,
cherokee_connection_t *conn,
cherokee_socket_t *sock_in,
cherokee_socket_t *sock_out,
cherokee_buffer_t *tmp,
Expand All @@ -544,6 +545,8 @@ cherokee_post_send_to_socket (cherokee_post_t *post,
case cherokee_post_send_phase_read:
TRACE (ENTRIES, "Post send, phase: %s\n", "read");

/* Read from the client
*/
ret = cherokee_post_read (post, sock_in, buffer);
switch (ret) {
case ret_ok:
Expand All @@ -555,6 +558,12 @@ cherokee_post_send_to_socket (cherokee_post_t *post,
return ret;
}

/* Did something, increase timeout
*/
cherokee_connection_update_timeout (conn);

/* Write it
*/
TRACE (ENTRIES, "Post buffer.len %d\n", buffer->len);
post->send.phase = cherokee_post_send_phase_write;

Expand All @@ -575,6 +584,10 @@ cherokee_post_send_to_socket (cherokee_post_t *post,
RET_UNKNOWN(ret);
return ret_error;
}

/* Did something, increase timeout
*/
cherokee_connection_update_timeout (conn);
}

if (! cherokee_buffer_is_empty (buffer)) {
Expand All @@ -601,6 +614,7 @@ cherokee_post_send_to_socket (cherokee_post_t *post,

ret_t
cherokee_post_send_to_fd (cherokee_post_t *post,
cherokee_connection_t *conn,
cherokee_socket_t *sock_in,
int fd_out,
cherokee_buffer_t *tmp,
Expand All @@ -615,6 +629,8 @@ cherokee_post_send_to_fd (cherokee_post_t *post,
case cherokee_post_send_phase_read:
TRACE (ENTRIES, "Post send, phase: %s\n", "read");

/* Read from the client
*/
ret = cherokee_post_read (post, sock_in, buffer);
switch (ret) {
case ret_ok:
Expand All @@ -626,6 +642,12 @@ cherokee_post_send_to_fd (cherokee_post_t *post,
return ret;
}

/* Did something, increase timeout
*/
cherokee_connection_update_timeout (conn);

/* Write it
*/
TRACE (ENTRIES, "Post buffer.len %d\n", buffer->len);
post->send.phase = cherokee_post_send_phase_write;

Expand All @@ -648,8 +670,14 @@ cherokee_post_send_to_fd (cherokee_post_t *post,
}

cherokee_buffer_move_to_begin (buffer, r);

/* Did something, increase timeout
*/
cherokee_connection_update_timeout (conn);
}

/* Next iteration
*/
if (! cherokee_buffer_is_empty (buffer)) {
return ret_eagain;
}
Expand Down
2 changes: 2 additions & 0 deletions cherokee/post.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ ret_t cherokee_post_read (cherokee_post_t *post,
ret_t cherokee_post_send_reset (cherokee_post_t *post);

ret_t cherokee_post_send_to_socket (cherokee_post_t *post,
cherokee_connection_t *conn,
cherokee_socket_t *sock_in,
cherokee_socket_t *sock_out,
cherokee_buffer_t *buffer,
cherokee_socket_status_t *blocking);

ret_t cherokee_post_send_to_fd (cherokee_post_t *post,
cherokee_connection_t *conn,
cherokee_socket_t *sock_in,
int fd_out,
cherokee_buffer_t *tmp,
Expand Down
4 changes: 4 additions & 0 deletions cherokee/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,12 @@ process_active_connections (cherokee_thread_t *thd)
case ret_ok:
break;
case ret_eagain:
/* Blocking on socket read */
conn_set_mode (thd, conn, socket_reading);
continue;
case ret_deny:
/* Blocking on back-end write */
continue;
case ret_eof:
case ret_error:
conn->error_code = http_internal_error;
Expand Down

0 comments on commit f9f8902

Please sign in to comment.