Changeset 386
- Timestamp:
- 09/02/06 13:52:52 (2 years ago)
- Files:
-
- cherokee/trunk/cherokee/connection-protected.h (modified) (1 diff)
- cherokee/trunk/cherokee/connection.c (modified) (1 diff)
- cherokee/trunk/cherokee/server.c (modified) (1 diff)
- cherokee/trunk/cherokee/socket.c (modified) (7 diffs)
- cherokee/trunk/cherokee/socket.h (modified) (1 diff)
- cherokee/trunk/cherokee/thread.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/cherokee/connection-protected.h
r384 r386 192 192 /* Basic functions 193 193 */ 194 ret_t cherokee_connection_new (cherokee_connection_t **c nt);195 ret_t cherokee_connection_free (cherokee_connection_t *c nt);196 ret_t cherokee_connection_clean (cherokee_connection_t *c nt);197 ret_t cherokee_connection_mrproper (cherokee_connection_t *c nt);194 ret_t cherokee_connection_new (cherokee_connection_t **conn); 195 ret_t cherokee_connection_free (cherokee_connection_t *conn); 196 ret_t cherokee_connection_clean (cherokee_connection_t *conn); 197 ret_t cherokee_connection_mrproper (cherokee_connection_t *conn); 198 198 199 199 /* Close 200 200 */ 201 ret_t cherokee_connection_pre_lingering_close (cherokee_connection_t *cnt); 201 ret_t cherokee_connection_pre_lingering_close (cherokee_connection_t *conn); 202 ret_t cherokee_connection_linger_read (cherokee_connection_t *conn); 202 203 203 204 /* Connection I/O 204 205 */ 205 ret_t cherokee_connection_send (cherokee_connection_t *c nt);206 ret_t cherokee_connection_send_header (cherokee_connection_t *c nt);207 ret_t cherokee_connection_send_header_and_mmaped (cherokee_connection_t *c nt);208 ret_t cherokee_connection_send_switching (cherokee_connection_t *c nt);209 ret_t cherokee_connection_recv (cherokee_connection_t *c nt, cherokee_buffer_t *buffer, off_t *len);206 ret_t cherokee_connection_send (cherokee_connection_t *conn); 207 ret_t cherokee_connection_send_header (cherokee_connection_t *conn); 208 ret_t cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn); 209 ret_t cherokee_connection_send_switching (cherokee_connection_t *conn); 210 ret_t cherokee_connection_recv (cherokee_connection_t *conn, cherokee_buffer_t *buffer, off_t *len); 210 211 211 212 /* Internal 212 213 */ 213 ret_t cherokee_connection_get_dir_entry (cherokee_connection_t *c nt, cherokee_dirs_table_t *dirs, cherokee_config_entry_t *config_entry);214 ret_t cherokee_connection_get_ext_entry (cherokee_connection_t *c nt, cherokee_exts_table_t *exts, cherokee_config_entry_t *config_entry);215 ret_t cherokee_connection_get_req_entry (cherokee_connection_t *c nt, cherokee_reqs_list_t *reqs, cherokee_config_entry_t *config_entry);216 217 ret_t cherokee_connection_create_handler (cherokee_connection_t *c nt, cherokee_config_entry_t *config_entry);218 ret_t cherokee_connection_setup_error_handler (cherokee_connection_t *c nt);219 ret_t cherokee_connection_check_authentication (cherokee_connection_t *c nt, cherokee_config_entry_t *config_entry);220 ret_t cherokee_connection_check_ip_validation (cherokee_connection_t *c nt, cherokee_config_entry_t *config_entry);221 ret_t cherokee_connection_check_only_secure (cherokee_connection_t *c nt, cherokee_config_entry_t *config_entry);222 ret_t cherokee_connection_check_http_method (cherokee_connection_t *c nt, cherokee_config_entry_t *config_entry);214 ret_t cherokee_connection_get_dir_entry (cherokee_connection_t *conn, cherokee_dirs_table_t *dirs, cherokee_config_entry_t *config_entry); 215 ret_t cherokee_connection_get_ext_entry (cherokee_connection_t *conn, cherokee_exts_table_t *exts, cherokee_config_entry_t *config_entry); 216 ret_t cherokee_connection_get_req_entry (cherokee_connection_t *conn, cherokee_reqs_list_t *reqs, cherokee_config_entry_t *config_entry); 217 218 ret_t cherokee_connection_create_handler (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 219 ret_t cherokee_connection_setup_error_handler (cherokee_connection_t *conn); 220 ret_t cherokee_connection_check_authentication (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 221 ret_t cherokee_connection_check_ip_validation (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 222 ret_t cherokee_connection_check_only_secure (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 223 ret_t cherokee_connection_check_http_method (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 223 224 224 225 /* Iteration 225 226 */ 226 ret_t cherokee_connection_open_request (cherokee_connection_t *c nt);227 ret_t cherokee_connection_reading_check (cherokee_connection_t *c nt);228 ret_t cherokee_connection_step (cherokee_connection_t *c nt);227 ret_t cherokee_connection_open_request (cherokee_connection_t *conn); 228 ret_t cherokee_connection_reading_check (cherokee_connection_t *conn); 229 ret_t cherokee_connection_step (cherokee_connection_t *conn); 229 230 230 231 /* Headers 231 232 */ 232 ret_t cherokee_connection_build_header (cherokee_connection_t *c nt);233 ret_t cherokee_connection_get_request (cherokee_connection_t *c nt);234 ret_t cherokee_connection_parse_header (cherokee_connection_t *c nt, cherokee_encoder_table_t *encoders);235 int cherokee_connection_is_userdir (cherokee_connection_t *c nt);236 ret_t cherokee_connection_build_local_directory (cherokee_connection_t *c nt, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry);237 ret_t cherokee_connection_build_local_directory_userdir (cherokee_connection_t *c nt, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry);238 ret_t cherokee_connection_clean_for_respin (cherokee_connection_t *c nt);233 ret_t cherokee_connection_build_header (cherokee_connection_t *conn); 234 ret_t cherokee_connection_get_request (cherokee_connection_t *conn); 235 ret_t cherokee_connection_parse_header (cherokee_connection_t *conn, cherokee_encoder_table_t *encoders); 236 int cherokee_connection_is_userdir (cherokee_connection_t *conn); 237 ret_t cherokee_connection_build_local_directory (cherokee_connection_t *conn, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry); 238 ret_t cherokee_connection_build_local_directory_userdir (cherokee_connection_t *conn, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry); 239 ret_t cherokee_connection_clean_for_respin (cherokee_connection_t *conn); 239 240 240 241 /* Log 241 242 */ 242 ret_t cherokee_connection_log_or_delay (cherokee_connection_t *c nt);243 ret_t cherokee_connection_log_delayed (cherokee_connection_t *c nt);244 ret_t cherokee_connection_update_vhost_traffic (cherokee_connection_t *c nt);243 ret_t cherokee_connection_log_or_delay (cherokee_connection_t *conn); 244 ret_t cherokee_connection_log_delayed (cherokee_connection_t *conn); 245 ret_t cherokee_connection_update_vhost_traffic (cherokee_connection_t *conn); 245 246 246 247 /* Transfers 247 248 */ 248 void cherokee_connection_rx_add (cherokee_connection_t *c nt, ssize_t rx);249 void cherokee_connection_tx_add (cherokee_connection_t *c nt, ssize_t tx);249 void cherokee_connection_rx_add (cherokee_connection_t *conn, ssize_t rx); 250 void cherokee_connection_tx_add (cherokee_connection_t *conn, ssize_t tx); 250 251 251 252 #endif /* CHEROKEE_CONNECTION_PROTECTED_H */ cherokee/trunk/cherokee/connection.c
r379 r386 824 824 conn->socket.is_tls = non_TLS; 825 825 826 /* Shut down the socket for write, which will send a FIN 827 * t o the peer.826 /* Shut down the socket for write, which will send a FIN to 827 * the peer. If shutdown fails then the socket is unusable. 828 828 */ 829 829 ret = cherokee_socket_shutdown (&conn->socket, SHUT_WR); 830 if (unlikely (ret != ret_ok)) return ret_ok; 831 832 /* Set the timeout 833 */ 834 ret = cherokee_socket_set_timeout (&conn->socket, MSECONS_TO_LINGER); 835 if (unlikely (ret != ret_ok)) return ret_ok; 836 837 /* Read from the socket to nowhere 838 */ 839 ret = cherokee_socket_read (&conn->socket, NULL, DEFAULT_RECV_SIZE, &readed); 840 switch (ret) { 841 case ret_eof: 842 case ret_error: 843 case ret_eagain: 844 TRACE(ENTRIES, "%s\n", "ok"); 845 return ret_ok; 846 case ret_ok: 847 TRACE(ENTRIES, "readed %d, eagain\n", readed); 848 return ret_eagain; 849 default: 850 RET_UNKNOWN(ret); 851 } 852 853 return ret_error; 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); 837 } 838 839 840 ret_t 841 cherokee_connection_linger_read (cherokee_connection_t *conn) 842 { 843 ret_t ret; 844 int retries = 2; 845 size_t readed = 0; 846 847 while (true) { 848 /* Read from the socket to nowhere 849 */ 850 ret = cherokee_socket_read (&conn->socket, NULL, DEFAULT_RECV_SIZE, &readed); 851 switch (ret) { 852 case ret_eof: 853 TRACE(ENTRIES, "%s\n", "eof"); 854 return ret; 855 case ret_error: 856 TRACE(ENTRIES, "%s\n", "error"); 857 return ret; 858 case ret_eagain: 859 TRACE(ENTRIES, "readed %d, eagain (linger)\n", readed); 860 return ret; 861 case ret_ok: 862 TRACE(ENTRIES, "readed %d, ok/eagain (linger)\n", readed); 863 if (readed > 0 && --retries > 0) 864 continue; 865 return ret; 866 default: 867 RET_UNKNOWN(ret); 868 } 869 return ret_error; 870 } 854 871 } 855 872 cherokee/trunk/cherokee/server.c
r385 r386 1694 1694 1695 1695 if (conn->id == id) { 1696 cherokee_connection_pre_lingering_close (conn); 1696 1697 conn->phase = phase_lingering; 1697 1698 return ret_ok; cherokee/trunk/cherokee/socket.c
r370 r386 751 751 ssize_t len; 752 752 753 if (unlikely (socket->status == socket_closed)) 754 return ret_eof; 755 753 756 if ((socket->is_tls == TLS) && (buf != NULL)) { 754 757 #ifdef HAVE_GNUTLS … … 807 810 */ 808 811 if (unlikely (buf == NULL)) { 809 static char trash[ 256];810 len = recv (SOCKET_FD(socket), trash, 256, 0);812 static char trash[4096]; 813 len = recv (SOCKET_FD(socket), trash, sizeof(trash), 0); 811 814 } else { 812 815 len = recv (SOCKET_FD(socket), buf, buf_size, 0); … … 924 927 */ 925 928 if (buf == NULL) { 926 return cherokee_read (socket, NULL, count, NULL);929 return cherokee_read (socket, NULL, count, done); 927 930 } 928 931 … … 1234 1237 1235 1238 1239 ret_t 1240 cherokee_socket_has_block_timeout (cherokee_socket_t *socket) 1241 { 1242 #if defined(SO_RCVTIMEO) && !defined(HAVE_BROKEN_SO_RCVTIMEO) 1243 return ret_ok; 1244 #else 1245 return ret_not_found; 1246 #endif 1247 } 1248 1249 1236 1250 ret_t 1237 cherokee_socket_set_ timeout (cherokee_socket_t *socket, cuint_t timeout)1251 cherokee_socket_set_block_timeout (cherokee_socket_t *socket, cuint_t timeout) 1238 1252 { 1239 1253 int re; … … 1247 1261 if (timeout < 0) 1248 1262 timeout = 0; 1249 1263 1264 #if defined(SO_RCVTIMEO) && !defined(HAVE_BROKEN_SO_RCVTIMEO) 1250 1265 /* Set the socket to blocking 1251 1266 */ 1252 1267 block = 0; 1253 1268 1254 1269 #ifdef _WIN32 1255 1270 re = ioctlsocket (socket->socket, FIONBIO, &block); … … 1265 1280 /* Set the send / receive timeouts 1266 1281 */ 1267 #if defined(SO_RCVTIMEO) && !defined(HAVE_BROKEN_SO_RCVTIMEO)1268 1282 tv.tv_sec = timeout / 1000; 1269 1283 tv.tv_usec = timeout % 1000; … … 1274 1288 PRINT_ERROR ("Couldn't set SO_RCVTIMEO, fd=%d, timeout=%d: %s\n", 1275 1289 socket->socket, timeout, strerror(err)); 1276 } 1290 return ret_error; 1291 } 1292 #else 1293 return no_esys; 1277 1294 #endif 1278 1295 cherokee/trunk/cherokee/socket.h
r203 r386 182 182 ret_t cherokee_socket_sendfile (cherokee_socket_t *socket, int fd, size_t size, off_t *offset, ssize_t *sent); 183 183 ret_t cherokee_socket_connect (cherokee_socket_t *socket); 184 ret_t cherokee_socket_set_timeout (cherokee_socket_t *socket, cuint_t timeout); 184 185 ret_t cherokee_socket_has_block_timeout (cherokee_socket_t *socket); 186 ret_t cherokee_socket_set_block_timeout (cherokee_socket_t *socket, cuint_t timeout); 185 187 186 188 ret_t cherokee_socket_ntop (cherokee_socket_t *socket, char *buf, size_t buf_size); cherokee/trunk/cherokee/thread.c
r385 r386 323 323 purge_connection (cherokee_thread_t *thread, cherokee_connection_t *conn) 324 324 { 325 /* Try last read, if last read returned eof, then no problem, 326 * otherwise it may avoid a nasty connection reset. 327 */ 328 if (conn->phase == phase_lingering) { 329 cherokee_connection_linger_read (conn); 330 } 331 325 332 /* Maybe have a delayed log 326 333 */ … … 419 426 purge_maybe_lingering (cherokee_thread_t *thread, cherokee_connection_t *conn) 420 427 { 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; 435 421 436 if (conn->keepalive <= 0) { 422 437 purge_closed_connection (thread, conn); … … 424 439 } 425 440 426 conn->phase = phase_lingering; 427 conn_set_mode (thread, conn, socket_reading); 441 /* Shutdown writting, and try to read some trash 442 */ 443 ret = cherokee_connection_pre_lingering_close (conn); 444 switch (ret) { 445 case ret_ok: 446 case ret_eagain: 447 /* Ok, really lingering 448 */ 449 conn_set_mode (thread, conn, socket_reading); 450 return; 451 default: 452 conn->phase = old_phase; 453 purge_closed_connection (thread, conn); 454 return; 455 } 428 456 } 429 457 … … 432 460 maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t *conn) 433 461 { 462 ret_t ret; 434 463 cherokee_server_t *srv = SRV(thread->server); 464 465 /* Log if it was delayed and update vserver traffic counters 466 */ 467 cherokee_connection_update_vhost_traffic (conn); 468 cherokee_connection_log_delayed (conn); 469 470 /* If it isn't a keep-alive connection, it should try to 471 * perform a lingering close. (There is no need to disable TCP 472 * cork before shutdown) 473 */ 474 if (conn->keepalive <= 0) { 475 ret = cherokee_connection_pre_lingering_close (conn); 476 switch (ret) { 477 case ret_ok: 478 case ret_eagain: 479 /* Ok, lingering 480 */ 481 conn->phase = phase_lingering; 482 return; 483 default: 484 purge_closed_connection (thread, conn); 485 return; 486 } 487 } 488 489 conn->keepalive--; 435 490 436 491 /* TCP cork … … 439 494 cherokee_connection_set_cork (conn, 0); 440 495 } 441 442 /* Log if it was delayed and update vserver traffic counters443 */444 cherokee_connection_update_vhost_traffic (conn);445 cherokee_connection_log_delayed (conn);446 447 /* If it isn't a keep-alive connection, it should try to448 * perform a lingering close449 */450 if (conn->keepalive <= 0) {451 conn->phase = phase_lingering;452 return;453 }454 455 conn->keepalive--;456 496 457 497 /* Clean the connection … … 547 587 } 548 588 549 /* Process the connection? 550 * 1.- Is there a pipelined connection? 551 * 2.- Is it closing the connection? 589 /* Process? 590 * Incoming buffer has information and it's reading the headers 552 591 */ 553 process = ((conn->phase == phase_lingering) || 554 ((conn->phase == phase_reading_header) && (conn->incoming_header.len > 0))); 592 process = ((conn->phase == phase_reading_header) && (conn->incoming_header.len > 0)); 593 594 // (conn->phase == phase_lingering) || ? 555 595 556 596 /* Process the connection? … … 575 615 576 616 /* Process the connection? 577 * Fin ial.-617 * Final. 578 618 */ 579 619 if (process == false) { … … 1169 1209 case phase_lingering: 1170 1210 1171 ret = cherokee_connection_ pre_lingering_close(conn);1211 ret = cherokee_connection_linger_read (conn); 1172 1212 switch (ret) { 1173 1213 case ret_ok: 1214 case ret_eagain: 1215 continue; 1216 case ret_eof: 1217 case ret_error: 1174 1218 purge_closed_connection (thd, conn); 1175 1219 continue; 1176 case ret_eagain:1177 continue;1178 1220 default: 1221 purge_closed_connection (thd, conn); 1179 1222 RET_UNKNOWN(ret); 1180 1223 }