Changeset 386

Show
Ignore:
Timestamp:
09/02/06 13:52:52 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/cherokee/connection-protected.h

    r384 r386  
    192192/* Basic functions 
    193193 */ 
    194 ret_t cherokee_connection_new                    (cherokee_connection_t **cnt); 
    195 ret_t cherokee_connection_free                   (cherokee_connection_t  *cnt); 
    196 ret_t cherokee_connection_clean                  (cherokee_connection_t  *cnt); 
    197 ret_t cherokee_connection_mrproper               (cherokee_connection_t  *cnt); 
     194ret_t cherokee_connection_new                    (cherokee_connection_t **conn); 
     195ret_t cherokee_connection_free                   (cherokee_connection_t  *conn); 
     196ret_t cherokee_connection_clean                  (cherokee_connection_t  *conn); 
     197ret_t cherokee_connection_mrproper               (cherokee_connection_t  *conn); 
    198198 
    199199/* Close 
    200200 */ 
    201 ret_t cherokee_connection_pre_lingering_close    (cherokee_connection_t *cnt); 
     201ret_t cherokee_connection_pre_lingering_close    (cherokee_connection_t *conn); 
     202ret_t cherokee_connection_linger_read            (cherokee_connection_t *conn); 
    202203 
    203204/* Connection I/O 
    204205 */ 
    205 ret_t cherokee_connection_send                   (cherokee_connection_t *cnt); 
    206 ret_t cherokee_connection_send_header            (cherokee_connection_t *cnt); 
    207 ret_t cherokee_connection_send_header_and_mmaped (cherokee_connection_t *cnt); 
    208 ret_t cherokee_connection_send_switching         (cherokee_connection_t *cnt); 
    209 ret_t cherokee_connection_recv                   (cherokee_connection_t *cnt, cherokee_buffer_t *buffer, off_t *len); 
     206ret_t cherokee_connection_send                   (cherokee_connection_t *conn); 
     207ret_t cherokee_connection_send_header            (cherokee_connection_t *conn); 
     208ret_t cherokee_connection_send_header_and_mmaped (cherokee_connection_t *conn); 
     209ret_t cherokee_connection_send_switching         (cherokee_connection_t *conn); 
     210ret_t cherokee_connection_recv                   (cherokee_connection_t *conn, cherokee_buffer_t *buffer, off_t *len); 
    210211 
    211212/* Internal 
    212213 */ 
    213 ret_t cherokee_connection_get_dir_entry          (cherokee_connection_t *cnt, cherokee_dirs_table_t *dirs, cherokee_config_entry_t *config_entry); 
    214 ret_t cherokee_connection_get_ext_entry          (cherokee_connection_t *cnt, cherokee_exts_table_t *exts, cherokee_config_entry_t *config_entry); 
    215 ret_t cherokee_connection_get_req_entry          (cherokee_connection_t *cnt, cherokee_reqs_list_t  *reqs, cherokee_config_entry_t *config_entry); 
    216  
    217 ret_t cherokee_connection_create_handler         (cherokee_connection_t *cnt, cherokee_config_entry_t *config_entry); 
    218 ret_t cherokee_connection_setup_error_handler    (cherokee_connection_t *cnt); 
    219 ret_t cherokee_connection_check_authentication   (cherokee_connection_t *cnt, cherokee_config_entry_t *config_entry); 
    220 ret_t cherokee_connection_check_ip_validation    (cherokee_connection_t *cnt, cherokee_config_entry_t *config_entry); 
    221 ret_t cherokee_connection_check_only_secure      (cherokee_connection_t *cnt, cherokee_config_entry_t *config_entry); 
    222 ret_t cherokee_connection_check_http_method      (cherokee_connection_t *cnt, cherokee_config_entry_t *config_entry); 
     214ret_t cherokee_connection_get_dir_entry          (cherokee_connection_t *conn, cherokee_dirs_table_t *dirs, cherokee_config_entry_t *config_entry); 
     215ret_t cherokee_connection_get_ext_entry          (cherokee_connection_t *conn, cherokee_exts_table_t *exts, cherokee_config_entry_t *config_entry); 
     216ret_t cherokee_connection_get_req_entry          (cherokee_connection_t *conn, cherokee_reqs_list_t  *reqs, cherokee_config_entry_t *config_entry); 
     217 
     218ret_t cherokee_connection_create_handler         (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 
     219ret_t cherokee_connection_setup_error_handler    (cherokee_connection_t *conn); 
     220ret_t cherokee_connection_check_authentication   (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 
     221ret_t cherokee_connection_check_ip_validation    (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 
     222ret_t cherokee_connection_check_only_secure      (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 
     223ret_t cherokee_connection_check_http_method      (cherokee_connection_t *conn, cherokee_config_entry_t *config_entry); 
    223224 
    224225/* Iteration 
    225226 */ 
    226 ret_t cherokee_connection_open_request           (cherokee_connection_t *cnt); 
    227 ret_t cherokee_connection_reading_check          (cherokee_connection_t *cnt); 
    228 ret_t cherokee_connection_step                   (cherokee_connection_t *cnt); 
     227ret_t cherokee_connection_open_request           (cherokee_connection_t *conn); 
     228ret_t cherokee_connection_reading_check          (cherokee_connection_t *conn); 
     229ret_t cherokee_connection_step                   (cherokee_connection_t *conn); 
    229230 
    230231/* Headers 
    231232 */ 
    232 ret_t cherokee_connection_build_header           (cherokee_connection_t *cnt); 
    233 ret_t cherokee_connection_get_request            (cherokee_connection_t *cnt); 
    234 ret_t cherokee_connection_parse_header           (cherokee_connection_t *cnt, cherokee_encoder_table_t *encoders); 
    235 int   cherokee_connection_is_userdir             (cherokee_connection_t *cnt); 
    236 ret_t cherokee_connection_build_local_directory  (cherokee_connection_t *cnt, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry); 
    237 ret_t cherokee_connection_build_local_directory_userdir (cherokee_connection_t *cnt, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry); 
    238 ret_t cherokee_connection_clean_for_respin       (cherokee_connection_t *cnt); 
     233ret_t cherokee_connection_build_header           (cherokee_connection_t *conn); 
     234ret_t cherokee_connection_get_request            (cherokee_connection_t *conn); 
     235ret_t cherokee_connection_parse_header           (cherokee_connection_t *conn, cherokee_encoder_table_t *encoders); 
     236int   cherokee_connection_is_userdir             (cherokee_connection_t *conn); 
     237ret_t cherokee_connection_build_local_directory  (cherokee_connection_t *conn, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry); 
     238ret_t cherokee_connection_build_local_directory_userdir (cherokee_connection_t *conn, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry); 
     239ret_t cherokee_connection_clean_for_respin       (cherokee_connection_t *conn); 
    239240 
    240241/* Log 
    241242 */ 
    242 ret_t cherokee_connection_log_or_delay           (cherokee_connection_t *cnt); 
    243 ret_t cherokee_connection_log_delayed            (cherokee_connection_t *cnt); 
    244 ret_t cherokee_connection_update_vhost_traffic   (cherokee_connection_t *cnt); 
     243ret_t cherokee_connection_log_or_delay           (cherokee_connection_t *conn); 
     244ret_t cherokee_connection_log_delayed            (cherokee_connection_t *conn); 
     245ret_t cherokee_connection_update_vhost_traffic   (cherokee_connection_t *conn); 
    245246 
    246247/* Transfers 
    247248 */ 
    248 void cherokee_connection_rx_add                  (cherokee_connection_t *cnt, ssize_t rx); 
    249 void cherokee_connection_tx_add                  (cherokee_connection_t *cnt, ssize_t tx); 
     249void cherokee_connection_rx_add                  (cherokee_connection_t *conn, ssize_t rx); 
     250void cherokee_connection_tx_add                  (cherokee_connection_t *conn, ssize_t tx); 
    250251 
    251252#endif /* CHEROKEE_CONNECTION_PROTECTED_H */ 
  • cherokee/trunk/cherokee/connection.c

    r379 r386  
    824824        conn->socket.is_tls = non_TLS; 
    825825 
    826         /* Shut down the socket for write, which will send a FIN 
    827          * to 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
    828828         */ 
    829829        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 
     840ret_t  
     841cherokee_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        } 
    854871} 
    855872 
  • cherokee/trunk/cherokee/server.c

    r385 r386  
    16941694 
    16951695                        if (conn->id == id) { 
     1696                                cherokee_connection_pre_lingering_close (conn); 
    16961697                                conn->phase = phase_lingering; 
    16971698                                return ret_ok; 
  • cherokee/trunk/cherokee/socket.c

    r370 r386  
    751751        ssize_t len; 
    752752 
     753        if (unlikely (socket->status == socket_closed)) 
     754                return ret_eof; 
     755 
    753756        if ((socket->is_tls == TLS) && (buf != NULL)) { 
    754757#ifdef HAVE_GNUTLS 
     
    807810         */ 
    808811        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); 
    811814        } else { 
    812815                len = recv (SOCKET_FD(socket), buf, buf_size, 0); 
     
    924927         */ 
    925928        if (buf == NULL) { 
    926                 return cherokee_read (socket, NULL, count, NULL); 
     929                return cherokee_read (socket, NULL, count, done); 
    927930        } 
    928931 
     
    12341237 
    12351238 
     1239ret_t 
     1240cherokee_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  
    12361250ret_t  
    1237 cherokee_socket_set_timeout (cherokee_socket_t *socket, cuint_t timeout) 
     1251cherokee_socket_set_block_timeout (cherokee_socket_t *socket, cuint_t timeout) 
    12381252{ 
    12391253        int            re; 
     
    12471261        if (timeout < 0) 
    12481262                timeout = 0; 
    1249          
     1263 
     1264#if defined(SO_RCVTIMEO) && !defined(HAVE_BROKEN_SO_RCVTIMEO) 
    12501265        /* Set the socket to blocking 
    12511266         */ 
    12521267        block = 0; 
    1253  
     1268                 
    12541269#ifdef _WIN32 
    12551270        re = ioctlsocket (socket->socket, FIONBIO, &block);      
     
    12651280        /* Set the send / receive timeouts 
    12661281         */ 
    1267 #if defined(SO_RCVTIMEO) && !defined(HAVE_BROKEN_SO_RCVTIMEO) 
    12681282        tv.tv_sec  = timeout / 1000; 
    12691283        tv.tv_usec = timeout % 1000; 
     
    12741288                PRINT_ERROR ("Couldn't set SO_RCVTIMEO, fd=%d, timeout=%d: %s\n",  
    12751289                             socket->socket, timeout, strerror(err)); 
    1276         } 
     1290                return ret_error; 
     1291        } 
     1292#else 
     1293        return no_esys; 
    12771294#endif 
    12781295         
  • cherokee/trunk/cherokee/socket.h

    r203 r386  
    182182ret_t cherokee_socket_sendfile      (cherokee_socket_t *socket, int fd, size_t size, off_t *offset, ssize_t *sent); 
    183183ret_t cherokee_socket_connect       (cherokee_socket_t *socket); 
    184 ret_t cherokee_socket_set_timeout   (cherokee_socket_t *socket, cuint_t timeout); 
     184 
     185ret_t cherokee_socket_has_block_timeout (cherokee_socket_t *socket); 
     186ret_t cherokee_socket_set_block_timeout (cherokee_socket_t *socket, cuint_t timeout); 
    185187 
    186188ret_t cherokee_socket_ntop          (cherokee_socket_t *socket, char *buf, size_t buf_size); 
  • cherokee/trunk/cherokee/thread.c

    r385 r386  
    323323purge_connection (cherokee_thread_t *thread, cherokee_connection_t *conn) 
    324324{ 
     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 
    325332        /* Maybe have a delayed log 
    326333         */ 
     
    419426purge_maybe_lingering (cherokee_thread_t *thread, cherokee_connection_t *conn) 
    420427{ 
     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 
    421436        if (conn->keepalive <= 0) { 
    422437                purge_closed_connection (thread, conn); 
     
    424439        } 
    425440 
    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        }        
    428456} 
    429457 
     
    432460maybe_purge_closed_connection (cherokee_thread_t *thread, cherokee_connection_t *conn) 
    433461{ 
     462        ret_t              ret; 
    434463        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--; 
    435490 
    436491        /* TCP cork 
     
    439494                cherokee_connection_set_cork (conn, 0); 
    440495        } 
    441  
    442         /* Log if it was delayed and update vserver traffic counters 
    443          */ 
    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 to 
    448          * perform a lingering close 
    449          */ 
    450         if (conn->keepalive <= 0) { 
    451                 conn->phase = phase_lingering; 
    452                 return; 
    453         }        
    454  
    455         conn->keepalive--; 
    456496 
    457497        /* Clean the connection 
     
    547587                } 
    548588 
    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 
    552591                 */ 
    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) || ? 
    555595                         
    556596                /* Process the connection? 
     
    575615                 
    576616                /* Process the connection? 
    577                  * Finial.-  
     617                 * Final. 
    578618                 */ 
    579619                if (process == false) { 
     
    11691209                case phase_lingering:  
    11701210 
    1171                         ret = cherokee_connection_pre_lingering_close (conn); 
     1211                        ret = cherokee_connection_linger_read (conn); 
    11721212                        switch (ret) { 
    11731213                        case ret_ok: 
     1214                        case ret_eagain: 
     1215                                continue; 
     1216                        case ret_eof: 
     1217                        case ret_error: 
    11741218                                purge_closed_connection (thd, conn); 
    11751219                                continue; 
    1176                         case ret_eagain: 
    1177                                 continue; 
    11781220                        default: 
     1221                                purge_closed_connection (thd, conn); 
    11791222                                RET_UNKNOWN(ret); 
    11801223                        }