Changeset 389
- Timestamp:
- 09/04/06 20:05:08 (2 years ago)
- Files:
-
- cherokee/trunk/cherokee/connection-protected.h (modified) (1 diff)
- cherokee/trunk/cherokee/connection.c (modified) (3 diffs)
- cherokee/trunk/cherokee/server.c (modified) (1 diff)
- cherokee/trunk/cherokee/socket.c (modified) (2 diffs)
- cherokee/trunk/cherokee/thread.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/cherokee/connection-protected.h
r386 r389 78 78 phase_send_headers, 79 79 phase_steping, 80 phase_shutdown, 80 81 phase_lingering 81 82 } cherokee_connection_phase_t; cherokee/trunk/cherokee/connection.c
r386 r389 816 816 cherokee_connection_pre_lingering_close (cherokee_connection_t *conn) 817 817 { 818 ret_t ret;819 size_t readed = 0;820 821 818 /* At this point, we don't want to follow the TLS protocol 822 819 * any longer. … … 824 821 conn->socket.is_tls = non_TLS; 825 822 823 /* Set the timeout for future linger read(s) leaving the 824 * non-blocking mode. 825 */ 826 conn->timeout = CONN_THREAD(conn)->bogo_now + (MSECONS_TO_LINGER / 1000) + 1; 827 826 828 /* Shut down the socket for write, which will send a FIN to 827 829 * the peer. If shutdown fails then the socket is unusable. 828 */ 829 ret = cherokee_socket_shutdown (&conn->socket, SHUT_WR); 830 if (unlikely (ret != ret_ok)) return ret; 831 832 /* Set the timeout leaving the non-blocking mode 833 */ 834 conn->timeout = CONN_THREAD(conn)->bogo_now + (MSECONS_TO_LINGER / 1000) + 1; 835 836 return cherokee_connection_linger_read (conn); 830 */ 831 return cherokee_socket_shutdown (&conn->socket, SHUT_WR); 837 832 } 838 833 … … 857 852 return ret; 858 853 case ret_eagain: 859 TRACE(ENTRIES, "readed %d, eagain (linger)\n", readed);854 TRACE(ENTRIES, "readed %d, eagain\n", readed); 860 855 return ret; 861 856 case ret_ok: 862 TRACE(ENTRIES, "readed %d, ok/eagain (linger)\n", readed);857 TRACE(ENTRIES, "readed %d, ok/eagain\n", readed); 863 858 if (readed > 0 && --retries > 0) 864 859 continue; cherokee/trunk/cherokee/server.c
r386 r389 1694 1694 1695 1695 if (conn->id == id) { 1696 cherokee_connection_pre_lingering_close (conn); 1697 conn->phase = phase_lingering; 1698 return ret_ok; 1696 if ((conn->phase != phase_nothing) && 1697 (conn->phase != phase_lingering)) 1698 { 1699 conn->phase = phase_shutdown; 1700 return ret_ok; 1701 } 1699 1702 } 1700 1703 } cherokee/trunk/cherokee/socket.c
r386 r389 484 484 int re; 485 485 486 if (socket->socket < 0) { 487 return ret_error; 488 } 486 /* If the read side of the socket has been closed but the 487 * write side is not, then don't bother to call shutdown 488 * because the socket is going to be closed anyway. 489 */ 490 if (unlikely (socket->status == socket_closed)) 491 return ret_eof; 492 493 if (unlikely (socket->socket < 0)) 494 return ret_error; 489 495 490 496 re = shutdown (socket->socket, how); 491 497 492 return (re == 0) ? ret_ok : ret_error;498 return (re == 0) ? ret_ok : ret_error; 493 499 } 494 500 … … 860 866 int re; 861 867 868 if (unlikely (socket->status == socket_closed)) 869 return ret_eof; 870 862 871 #ifdef _WIN32 863 872 int i; cherokee/trunk/cherokee/thread.c
r386 r389 65 65 case phase_send_headers: return "Send headers"; 66 66 case phase_steping: return "Step"; 67 case phase_shutdown: return "Shutdown connection"; 67 68 case phase_lingering: return "Lingering close"; 68 69 default: … … 323 324 purge_connection (cherokee_thread_t *thread, cherokee_connection_t *conn) 324 325 { 325 /* Try last read, if last read returned eof, then no problem,326 * otherwise it may avoid a nasty connection reset.326 /* Try last read, if previous read/write returned eof, then no 327 * problem, otherwise it may avoid a nasty connection reset. 327 328 */ 328 329 if (conn->phase == phase_lingering) { … … 426 427 purge_maybe_lingering (cherokee_thread_t *thread, cherokee_connection_t *conn) 427 428 { 428 ret_t ret; 429 cherokee_connection_phase_t old_phase; 430 431 /* Set lingering close 432 */ 433 old_phase = conn->phase; 434 conn->phase = phase_lingering; 429 ret_t ret; 435 430 436 431 if (conn->keepalive <= 0) { 432 conn->phase = phase_lingering; 437 433 purge_closed_connection (thread, conn); 438 434 return; 439 435 } 440 436 441 /* Shutdown writ ting, and try to read some trash437 /* Shutdown writing, and try to read some trash 442 438 */ 443 439 ret = cherokee_connection_pre_lingering_close (conn); … … 447 443 /* Ok, really lingering 448 444 */ 445 conn->phase = phase_lingering; 449 446 conn_set_mode (thread, conn, socket_reading); 450 447 return; 451 448 default: 452 conn->phase = old_phase; 449 /* Error: no linger and no last read, just close it 450 */ 453 451 purge_closed_connection (thread, conn); 454 452 return; … … 469 467 470 468 /* If it isn't a keep-alive connection, it should try to 471 * perform a lingering close . (There is no need to disable TCP472 * cork before shutdown )469 * perform a lingering close (there is no need to disable TCP 470 * cork before shutdown or before a close). 473 471 */ 474 472 if (conn->keepalive <= 0) { … … 479 477 /* Ok, lingering 480 478 */ 481 conn->phase = phase_lingering; 482 return; 479 conn->phase = phase_lingering; 480 conn_set_mode (thread, conn, socket_reading); 481 return; 483 482 default: 483 /* Error, no linger and no last read, just 484 * close the connection. 485 */ 484 486 purge_closed_connection (thread, conn); 485 487 return; … … 587 589 } 588 590 589 /* Process? 590 * Incoming buffer has information and it's reading the headers 591 /* Set process condition to true if it's shutdown 592 * phase or it's reading the headers and incoming 593 * buffer has data to be processed. 591 594 */ 592 process = ((conn->phase == phase_reading_header) && (conn->incoming_header.len > 0)); 593 594 // (conn->phase == phase_lingering) || ? 595 process = ((conn->phase == phase_shutdown) || 596 ((conn->phase == phase_reading_header) && (conn->incoming_header.len > 0))); 595 597 596 598 /* Process the connection? … … 1207 1209 break; 1208 1210 1211 case phase_shutdown: 1212 1213 ret = cherokee_connection_pre_lingering_close (conn); 1214 switch (ret) { 1215 case ret_ok: 1216 case ret_eagain: 1217 /* Ok, really lingering 1218 */ 1219 conn->phase = phase_lingering; 1220 conn_set_mode (thd, conn, socket_reading); 1221 break; 1222 default: 1223 /* Error, no linger and no last read, 1224 * just close the connection. 1225 */ 1226 purge_closed_connection (thd, conn); 1227 continue; 1228 } 1229 1209 1230 case phase_lingering: 1210 1231 … … 1227 1248 SHOULDNT_HAPPEN; 1228 1249 } 1250 1229 1251 } /* list */ 1230 1252