Changeset 852

Show
Ignore:
Timestamp:
07/21/07 21:33:41 (1 year ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r851 r852  
    112007-07-21  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
    22 
     3        * cherokee/regex.c (cherokee_regex_table_free): Again, another 
     4        little tiny memory leak. The server leaked 41 bytes on each 
     5        reload. Fixed. 
     6 
     7        * cherokee/plugin_loader.c (cherokee_plugin_loader_mrproper): 
     8        Fixed nano memory leak - no more than 30 or 40 bytes. 
     9 
     10        * cherokee/avl.c, cherokee/avl.h, cherokee/dirs_table.c, 
     11        cherokee/encoder_table.c, cherokee/handler_fastcgi.c, 
     12        cherokee/iocache.c, cherokee/thread.h: Converted to use 
     13        cherokee_func_free() 
     14 
     15        * cherokee/common.h: Added new function type: cherokee_func_free. 
     16 
     17        * cherokee/source_interpreter.c, cherokee/source_interpreter.h, 
     18        cherokee/source.h, cherokee/source.c: Another little tiny memory 
     19        leak has been fixed here. The freed object wasn't calling its 
     20        predecessor destructor. 
     21 
     22        * cherokee/balancer.c (cherokee_balancer_mrproper): Memory leak 
     23        fixed. It wasn't freeing the source objects. 
     24 
     25        * cherokee/validator_plain.c (cherokee_validator_plain_check): 
     26        Rewritten from scratch. Now, it uses temporal buffers instead of a 
     27        fixed size temporal array - among other improvements. 
     28 
     29        * cherokee/validator.c (cherokee_validator_digest_check), 
     30        cherokee/validator_plain.c (cherokee_validator_plain_check), 
     31        cherokee/validator_mysql.c (cherokee_validator_mysql_check), 
     32        cherokee/validator.h: The battle against char * continues! Another 
     33        parameter char * converted to our sweet cherokee_buffer_t *. 
     34 
     35        * cherokee/validator.c (digest_HA2, 
     36        cherokee_validator_digest_check): Slightly optimized, a call to 
     37        cherokee_buffer_add_va() has been replaced. 
     38 
     39        * cherokee/validator.c (cherokee_validator_digest_response): Fixed 
     40        a 32 bytes memory leak. 
     41 
     42        * cherokee/iocache.c (cherokee_iocache_free): Now it uses 
     43        cherokee_avl_mrproper() instead of cherokee_avl_while() plus 
     44        free(). Besides the correctness, it fixed a memory leak. 
     45 
     46        * cherokee/avl.c: Clean up: avl_node_* static methods renamed. 
     47        Rewritten as _new/_free instead of _init/_mrproper. 
     48        (cherokee_avl_mrproper): Rewritten to use node_free(). 
     49 
     50        * cherokee/thread.c (process_active_connections), 
     51        cheroke/server.c, cherokee/server-protected.h: Reworked in order 
     52        to remove the call to cherokee_server_get_conns_num(). A thread 
     53        should never query or access other threads (and that's exactly 
     54        what method was doing). 
     55 
     56        * cherokee/thread.c (cherokee_thread_free): It wasn't freeing the 
     57        reusable connections. Fixed. 
     58 
     59        * qa/util.py (count_down): Refactored. There were two places in 
     60        which it needed count-downs. This is the common function. 
     61 
     62        * qa/run-tests.py (clean_up): Added a little pause. We should give 
     63        the server sometime to die gratefully between the SIGTERM and 
     64        SIGKILL signals. 
     65 
     66        * qa/Makefile.am, qa/143-ContentRange-NoIO.py, 
     67        qa/144-ContentRange2-NoIO.py, qa/145-ContentRange3-NoIO.py, 
     68        qa/146-ContentRange4-NoIO.py, qa/147-ContentRange-Double-NoIO.py, 
     69        qa/148-ContentRange-Double2-NoIO.py: Added 6 new test to check 
     70        partial file management without IOcache. 
     71 
    372        * cherokee/icons.c (cherokee_icons_free), 
    4         cherokee/avl.c (node_first): Protected. I was crashing when it was 
    5         NULL. 
     73        cherokee/avl.c (node_first): Protected against NULL pointers.  
    674 
    775        * cherokee/server.c (cherokee_server_handle_panic): PRINT_ERROR_S 
  • cherokee/trunk/cherokee/avl.c

    r851 r852  
    5151 */ 
    5252static ret_t  
    53 cherokee_avl_node_init (cherokee_avl_node_t *node, cherokee_buffer_t *key, void *value) 
    54 
    55         node->balance     = 0; 
    56         node->left        = NULL; 
    57         node->right       = NULL; 
    58         node->left_child  = false; 
    59         node->right_child = false; 
    60         node->value       = value; 
    61  
    62         cherokee_buffer_init (&node->id); 
    63         cherokee_buffer_add_buffer (&node->id, key); 
     53node_new (cherokee_avl_node_t **node, cherokee_buffer_t *key, void *value) 
     54
     55        CHEROKEE_NEW_STRUCT (n, avl_node); 
     56 
     57        n->balance     = 0; 
     58        n->left        = NULL; 
     59        n->right       = NULL; 
     60        n->left_child  = false; 
     61        n->right_child = false; 
     62        n->value       = value; 
     63 
     64        cherokee_buffer_init (&n->id); 
     65        cherokee_buffer_add_buffer (&n->id, key); 
     66 
     67        *node = n; 
    6468        return ret_ok; 
    6569} 
    6670 
    6771static ret_t  
    68 cherokee_avl_node_mrproper (cherokee_avl_node_t *node) 
     72node_free (cherokee_avl_node_t *node) 
    6973{ 
    7074        cherokee_buffer_mrproper (&node->id); 
    71         return ret_ok; 
    72 
    73  
    74  
     75 
     76        free (node); 
     77        return ret_ok; 
     78
    7579 
    7680/* Tree constructor / destructor  
     
    9094 
    9195ret_t  
    92 cherokee_avl_mrproper (cherokee_avl_t *avl, cherokee_avl_value_free_func_t free_func) 
     96cherokee_avl_mrproper (cherokee_avl_t *avl, cherokee_func_free_t free_func) 
    9397{ 
    9498        cherokee_avl_node_t *node; 
     
    103107                next = node_next (node); 
    104108 
    105                 cherokee_buffer_mrproper (&node->id); 
    106109                if (free_func) 
    107110                        free_func (node->value); 
    108  
    109                 free (node); 
     111                node_free (node); 
     112 
    110113                node = next; 
    111114        } 
     
    115118 
    116119ret_t  
    117 cherokee_avl_free (cherokee_avl_t *avl, cherokee_avl_value_free_func_t free_func) 
     120cherokee_avl_free (cherokee_avl_t *avl, cherokee_func_free_t free_func) 
    118121{ 
    119122        cherokee_avl_mrproper (avl, free_func); 
     
    136139                return - (B->len - A->len); 
    137140        else { 
    138                 if (unlikely(case_insensitive)
     141                if (case_insensitive
    139142                        return strcasecmp (A->buf, B->buf); 
    140143                else 
     
    341344 
    342345                } else { 
    343                         cherokee_avl_node_mrproper (child); 
    344                         free (child); 
     346                        node_free (child); 
    345347                        return; 
    346348                } 
     
    381383cherokee_avl_add (cherokee_avl_t *avl, cherokee_buffer_t *key, void *value) 
    382384{ 
    383         ret_t ret; 
    384         CHEROKEE_NEW_STRUCT (n, avl_node)
     385        ret_t                ret; 
     386        cherokee_avl_node_t *n = NULL
    385387 
    386388        /* Create the new AVL node 
    387389         */ 
    388         ret = cherokee_avl_node_init (n, key, value); 
     390        ret = node_new (&n, key, value); 
    389391        if (unlikely (ret != ret_ok)) return ret; 
    390392 
     
    557559        } 
    558560         
     561        node_free (node); 
    559562        return ret_ok; 
    560563} 
     
    771774} 
    772775 
    773  
  • cherokee/trunk/cherokee/avl.h

    r838 r852  
    4545 
    4646typedef ret_t (* cherokee_avl_while_func_t)      (cherokee_buffer_t *key, void *value, void *param); 
    47 typedef void  (* cherokee_avl_value_free_func_t) (void *param); 
     47//typedef void  (* cherokee_avl_value_free_func_t) (void *param); 
    4848 
    4949ret_t cherokee_avl_new       (cherokee_avl_t **avl); 
    50 ret_t cherokee_avl_free      (cherokee_avl_t  *avl, cherokee_avl_value_free_func_t free_func); 
     50ret_t cherokee_avl_free      (cherokee_avl_t  *avl, cherokee_func_free_t free_func); 
    5151 
    5252ret_t cherokee_avl_init      (cherokee_avl_t  *avl); 
    53 ret_t cherokee_avl_mrproper  (cherokee_avl_t  *avl, cherokee_avl_value_free_func_t free_func); 
     53ret_t cherokee_avl_mrproper  (cherokee_avl_t  *avl, cherokee_func_free_t free_func); 
    5454 
    5555ret_t cherokee_avl_add       (cherokee_avl_t *avl, cherokee_buffer_t *key, void  *value); 
  • cherokee/trunk/cherokee/balancer.c

    r597 r852  
    5656cherokee_balancer_mrproper (cherokee_balancer_t *balancer) 
    5757{ 
     58        cuint_t            i; 
     59        cherokee_source_t *source; 
     60 
     61        /* Free sources 
     62         */ 
    5863        if (balancer->sources != NULL) { 
     64                for (i=0; i < balancer->sources_len; i++) { 
     65                        source = balancer->sources[i]; 
     66                        cherokee_source_free (source); 
     67                } 
     68 
    5969                free (balancer->sources); 
    6070        } 
  • cherokee/trunk/cherokee/common.h

    r597 r852  
    6969typedef unsigned long long  cullong_t; 
    7070 
     71typedef void (*cherokee_func_free_t) (void *); 
    7172 
    7273CHEROKEE_END_DECLS 
  • cherokee/trunk/cherokee/dirs_table.c

    r841 r852  
    4949{ 
    5050        return cherokee_avl_mrproper (AVL(pt),  
    51                                       (cherokee_avl_value_free_func_t) cherokee_config_entry_free); 
     51                                      (cherokee_func_free_t) cherokee_config_entry_free); 
    5252} 
    5353 
  • cherokee/trunk/cherokee/encoder_table.c

    r841 r852  
    3939cherokee_encoder_table_mrproper (cherokee_encoder_table_t *et) 
    4040{ 
    41         return cherokee_avl_mrproper (et, (cherokee_avl_value_free_func_t)cherokee_encoder_table_entry_free); 
     41        return cherokee_avl_mrproper (et, (cherokee_func_free_t)cherokee_encoder_table_entry_free); 
    4242} 
    4343 
  • cherokee/trunk/cherokee/handler_fastcgi.c

    r841 r852  
    277277         */ 
    278278        if (CONN_THREAD(cnt)->fastcgi_servers == NULL) { 
    279                 CONN_THREAD(cnt)->fastcgi_free_func = (cherokee_avl_value_free_func_t) cherokee_fcgi_dispatcher_free; 
     279                CONN_THREAD(cnt)->fastcgi_free_func = (cherokee_func_free_t) cherokee_fcgi_dispatcher_free; 
    280280                cherokee_avl_new (&CONN_THREAD(cnt)->fastcgi_servers); 
    281281        } 
  • cherokee/trunk/cherokee/iocache.c

    r834 r852  
    165165} 
    166166 
     167static ret_t 
     168iocache_entry_free (cherokee_iocache_entry_t *entry) 
     169{ 
     170        /* Free the object 
     171         */ 
     172        if (entry->mmaped != NULL) { 
     173                munmap (entry->mmaped, entry->mmaped_len); 
     174 
     175                entry->mmaped     = NULL; 
     176                entry->mmaped_len = 0; 
     177        } 
     178 
     179        /* Free the entry object 
     180         */ 
     181        free (entry); 
     182        return ret_ok; 
     183} 
    167184 
    168185static ret_t 
     
    190207iocache_free_entry (cherokee_iocache_t *iocache, cherokee_iocache_entry_t *entry) 
    191208{ 
    192         /* Free the object 
    193          */ 
    194         if (entry->mmaped != NULL) { 
    195                 munmap (entry->mmaped, entry->mmaped_len); 
    196  
    197                 entry->mmaped     = NULL; 
    198                 entry->mmaped_len = 0; 
    199         } 
    200  
    201         /* Free the entry object 
    202          */ 
    203         free (entry); 
     209        ret_t ret; 
     210 
     211        ret = iocache_entry_free (entry); 
    204212 
    205213        /* Update the obj counter 
     
    207215        iocache->files_num--; 
    208216 
    209         return ret_ok
     217        return ret
    210218} 
    211219 
     
    422430 
    423431 
    424 static ret_t 
    425 free_while_func (const char *key, void *value, void *param) 
    426 { 
    427         iocache_free_entry (IOCACHE(param), IOCACHE_ENTRY(value)); 
    428         return ret_ok; 
    429 } 
    430  
    431  
    432432static ret_t  
    433433cherokee_iocache_free (cherokee_iocache_t *iocache) 
    434434{ 
    435         cherokee_avl_while (&iocache->files,  
    436                             (cherokee_avl_while_func_t)free_while_func,  
    437                             iocache,  
    438                             NULL, NULL); 
    439  
     435        cherokee_avl_mrproper (&iocache->files,  
     436                               (cherokee_func_free_t) iocache_entry_free); 
    440437        CHEROKEE_MUTEX_DESTROY (&iocache->files_lock); 
    441438 
  • cherokee/trunk/cherokee/plugin_loader.c

    r839 r852  
    208208{ 
    209209        cherokee_buffer_mrproper (&loader->module_dir); 
     210        cherokee_buffer_mrproper (&loader->deps_dir); 
     211 
    210212        cherokee_avl_mrproper (&loader->table, free_entry); 
    211213        return ret_ok; 
  • cherokee/trunk/cherokee/regex.c

    r841 r852  
    5858 
    5959        cherokee_avl_mrproper (&table->cache, free); 
     60 
     61        free(table); 
    6062        return ret_ok; 
    6163} 
  • cherokee/trunk/cherokee/server-protected.h

    r811 r852  
    8383         */ 
    8484        cherokee_thread_t         *main_thread; 
    85         int                        thread_num; 
     85        cint_t                     thread_num; 
    8686        cherokee_list_t            thread_list; 
    87         int                        thread_policy; 
     87        cint_t                     thread_policy; 
    8888 
    8989        /* Modules 
     
    123123        cherokee_poll_type_t       fdpoll_method; 
    124124 
    125         /* Connection related. 
     125        /* Connection related 
    126126         */ 
    127         int                        max_conns; 
    128         int                        max_keepalive_conns; 
     127        cint_t                     conns_max; 
     128        cint_t                     conns_reuse_max; 
     129        cint_t                     conns_keepalive_max; 
     130        cuint_t                    conns_num_bogo; 
    129131 
    130132        /* Networking config 
     
    183185        /* Performance 
    184186         */ 
    185         int                        max_conn_reuse; 
    186187 
    187188        /* PID 
  • cherokee/trunk/cherokee/server.c

    r850 r852  
    153153        n->fds_per_thread  = -1; 
    154154        n->system_fd_limit = -1; 
    155         n->max_conns       =  0; 
    156         n->max_keepalive_conns =  0; 
    157         n->max_conn_reuse  = -1; 
     155 
     156        n->conns_max           =  0; 
     157        n->conns_reuse_max     = -1; 
     158        n->conns_keepalive_max =  0; 
     159        n->conns_num_bogo      =  0; 
    158160 
    159161        n->listen_queue    = 1024; 
     
    642644        /* File descriptor limit 
    643645         */ 
    644         cherokee_buffer_add_va (&n, ", %d fds system limit, max. %d connections", srv->system_fd_limit, srv->max_conns); 
     646        cherokee_buffer_add_va (&n, ", %d fds system limit, max. %d connections", srv->system_fd_limit, srv->conns_max); 
    645647 
    646648        /* Threading stuff 
     
    747749        /* Reset max. conns value 
    748750         */ 
    749         srv->max_conns = 0; 
    750         srv->max_keepalive_conns = 0; 
     751        srv->conns_max           = 0; 
     752        srv->conns_num_bogo      = 0; 
     753        srv->conns_keepalive_max = 0; 
    751754 
    752755        /* Verify max_fds value 
     
    823826         */ 
    824827        conns_per_thread = fds_per_thread1 / 2; 
    825         srv->max_conns += conns_per_thread; 
     828        srv->conns_max += conns_per_thread; 
    826829        fds_per_thread1 += MAX_LISTEN_FDS; 
    827830 
     
    869872                } 
    870873                conns_per_thread = fds_per_thread1 / 2; 
    871                 srv->max_conns += conns_per_thread; 
     874                srv->conns_max += conns_per_thread; 
    872875                fds_per_thread1 += MAX_LISTEN_FDS; 
    873876 
     
    895898         *       than conns_accept limit (95% - 99%) used for threads. 
    896899         */ 
    897         srv->max_keepalive_conns = srv->max_conns - (srv->max_conns / 16); 
    898         if (srv->max_keepalive_conns + 6 > srv->max_conns
    899                 srv->max_keepalive_conns = srv->max_conns - 6; 
     900        srv->conns_keepalive_max = srv->conns_max - (srv->conns_max / 16); 
     901        if (srv->conns_keepalive_max + 6 > srv->conns_max
     902                srv->conns_keepalive_max = srv->conns_max - 6; 
    900903 
    901904        /* OK, return. 
     
    11151118        /* Check the number of reusable connections 
    11161119         */ 
    1117         if (srv->max_conn_reuse == -1) 
    1118                 srv->max_conn_reuse = DEFAULT_CONN_REUSE; 
    1119  
    1120         if (srv->max_conn_reuse > srv->max_fds) 
    1121                 srv->max_conn_reuse = srv->max_fds; 
     1120        if (srv->conns_reuse_max == -1) 
     1121                srv->conns_reuse_max = DEFAULT_CONN_REUSE; 
     1122 
     1123        if (srv->conns_reuse_max > srv->max_fds) 
     1124                srv->conns_reuse_max = srv->max_fds; 
    11221125 
    11231126        /* Get the passwd file entry before chroot 
     
    11321135         */ 
    11331136        if (! cherokee_buffer_is_empty (&srv->chroot)) { 
    1134                 srv->chrooted = (chroot (srv->chroot.buf) == 0); 
     1137                re = chroot (srv->chroot.buf); 
     1138                srv->chrooted = (re == 0); 
    11351139                if (srv->chrooted == 0) { 
    11361140                        char buferr[ERROR_MAX_BUFSIZE]; 
     
    12321236 
    12331237        return ret_ok; 
     1238} 
     1239 
     1240static void 
     1241update_bogo_conns_num (cherokee_server_t *srv) 
     1242{ 
     1243        cherokee_server_get_conns_num (srv, &srv->conns_num_bogo); 
    12341244} 
    12351245 
     
    12641274         
    12651275        cherokee_buffer_clean (&srv->bogo_now_string); 
    1266         cherokee_buffer_add_va_fixed (&srv->bogo_now_string, 
    1267                                 "%s, %02d %s %d %02d:%02d:%02d GMT%c%d", 
    1268                     cherokee_dtm_wday_name(srv->bogo_now_tm.tm_wday), 
    1269                     srv->bogo_now_tm.tm_mday, 
    1270                     cherokee_dtm_month_name(srv->bogo_now_tm.tm_mon), 
    1271                     srv->bogo_now_tm.tm_year + 1900, 
    1272                     srv->bogo_now_tm.tm_hour, 
    1273                     srv->bogo_now_tm.tm_min, 
    1274                     srv->bogo_now_tm.tm_sec, 
    1275                     sign, offset); 
     1276        cherokee_buffer_add_va_fixed ( 
     1277                &srv->bogo_now_string, 
     1278                "%s, %02d %s %d %02d:%02d:%02d GMT%c%d", 
     1279                cherokee_dtm_wday_name(srv->bogo_now_tm.tm_wday), 
     1280                srv->bogo_now_tm.tm_mday, 
     1281                cherokee_dtm_month_name(srv->bogo_now_tm.tm_mon), 
     1282                srv->bogo_now_tm.tm_year + 1900, 
     1283                srv->bogo_now_tm.tm_hour, 
     1284                srv->bogo_now_tm.tm_min, 
     1285                srv->bogo_now_tm.tm_sec, 
     1286                sign, offset); 
    12761287 
    12771288        CHEROKEE_RWLOCK_UNLOCK (&srv->bogo_now_mutex);      /* 2.- release */ 
     
    13081319         */ 
    13091320        update_bogo_now (srv); 
     1321        update_bogo_conns_num (srv); 
    13101322 
    13111323        /* Execute thread step. 
     
    15121524 
    15131525        } else if (equal_buf_str (&conf->key, "max_connection_reuse")) { 
    1514                 srv->max_conn_reuse = atoi (conf->val.buf); 
     1526                srv->conns_reuse_max = atoi (conf->val.buf); 
    15151527 
    15161528        } else if (equal_buf_str (&conf->key, "ipv6")) { 
     
    18081820         */ 
    18091821        *num = conns_num; 
    1810  
    18111822        return ret_ok; 
    18121823} 
  • cherokee/trunk/cherokee/source.c

    r718 r852  
    4646 
    4747        src->port = -1; 
     48        src->free = NULL; 
    4849 
    4950        return ret_ok; 
     
    5455cherokee_source_mrproper (cherokee_source_t *src) 
    5556{ 
     57        if (src->free) 
     58                src->free (src); 
     59 
    5660        cherokee_buffer_mrproper (&src->original); 
    5761        cherokee_buffer_mrproper (&src->unix_socket); 
  • cherokee/trunk/cherokee/source.h

    r690 r852  
    3939 
    4040typedef struct { 
    41         cherokee_list_t   list; 
     41        cherokee_list_t      list; 
    4242         
    43         cherokee_buffer_t original; 
    44         cherokee_buffer_t unix_socket; 
    45         cherokee_buffer_t host; 
    46         cint_t            port; 
     43        cherokee_buffer_t    original; 
     44        cherokee_buffer_t    unix_socket; 
     45        cherokee_buffer_t    host; 
     46        cint_t               port; 
     47 
     48        cherokee_func_free_t free; 
    4749} cherokee_source_t; 
    4850 
  • cherokee/trunk/cherokee/source_interpreter.c

    r597 r852  
    3333#define ENTRIES "source,src,interpreter" 
    3434 
     35static void interpreter_free (void *src); 
     36 
    3537 
    3638ret_t  
     
    4547        n->custom_env_len = 0; 
    4648 
     49        SOURCE(n)->free   = (cherokee_func_free_t)interpreter_free; 
     50 
    4751        *src = n; 
    4852        return ret_ok; 
     
    5155 
    5256static void 
    53 free_custon_env (cherokee_source_interpreter_t *src) 
    54 
    55         cuint_t i; 
     57free_custon_env (void *ptr) 
     58
     59        cuint_t                        i; 
     60        cherokee_source_interpreter_t *src = ptr; 
    5661         
    5762        for (i=0; src->custom_env[i] != NULL; i++) { 
     
    6368 
    6469 
    65 ret_t  
    66 cherokee_source_interpreter_free (cherokee_source_interpreter_t *src) 
    67 
    68         cherokee_source_mrproper (SOURCE(src)); 
     70static void 
     71interpreter_free (void *ptr) 
     72
     73        cherokee_source_interpreter_t *src = ptr; 
     74 
     75        /* Only frees its stuff, the rest will be freed by 
     76         * cherokee_source_t. 
     77         */ 
    6978        cherokee_buffer_mrproper (&src->interpreter); 
    7079 
    7180        if (src->custom_env) 
    7281                free_custon_env (src); 
    73  
    74         free (src); 
    75         return ret_ok; 
    7682} 
    7783 
  • cherokee/trunk/cherokee/source_interpreter.h

    r597 r852  
    4343 
    4444 
    45 ret_t cherokee_source_interpreter_new  (cherokee_source_interpreter_t **src); 
    46 ret_t cherokee_source_interpreter_free (cherokee_source_interpreter_t  *src); 
     45ret_t cherokee_source_interpreter_new       (cherokee_source_interpreter_t **src); 
     46ret_t cherokee_source_interpreter_configure (cherokee_source_interpreter_t  *src, cherokee_config_node_t *conf); 
    4747 
    48 ret_t cherokee_source_interpreter_configure (cherokee_source_interpreter_t *src, cherokee_config_node_t *conf); 
    4948ret_t cherokee_source_interpreter_add_env   (cherokee_source_interpreter_t *src, char *env, char *val); 
    5049ret_t cherokee_source_interpreter_spawn     (cherokee_source_interpreter_t *src); 
  • cherokee/trunk/cherokee/thread.c

    r847 r852  
    365365        /* Check the max connection reuse number 
    366366         */ 
    367         if (thread->reuse_list_num >= THREAD_SRV(thread)->max_conn_reuse) { 
     367        if (thread->reuse_list_num >= THREAD_SRV(thread)->conns_reuse_max) { 
    368368                return cherokee_connection_free (conn); 
    369369        } 
     
    628628{ 
    629629        ret_t                  ret; 
    630         cuint_t                srv_conns_num = 0; 
    631630        off_t                  len; 
    632631        cherokee_list_t       *i, *tmp; 
    633         cherokee_connection_t *conn = NULL; 
    634         cherokee_server_t     *srv  = SRV(thd->server); 
    635  
    636         /* Get total connection count. 
    637          * NOTE: when there are 2 or more threads, 
    638          *       the real connection count can change while this thread 
    639          *       is processing connections;  as taking and releasing 
    640          *       a lock might slow down things, we keep a private 
    641          *       counter (srv_conns_num) that we decrease on every 
    642          *       connection close; this should be enough for now. 
    643          */ 
    644         cherokee_server_get_conns_num (srv, &srv_conns_num); 
     632        cuint_t                conns_freed = 0; 
     633        cherokee_connection_t *conn        = NULL; 
     634        cherokee_server_t     *srv         = SRV(thd->server); 
    645635 
    646636        /* Process active connections 
     
    654644                 */ 
    655645                if (conn->timeout < thd->bogo_now) { 
    656                         srv_conns_num--
     646                        conns_freed++
    657647                        purge_closed_connection (thd, conn); 
    658648                        continue; 
     
    681671                        switch (num) { 
    682672                        case -1: 
    683                                 srv_conns_num--
     673                                conns_freed++
    684674                                purge_closed_connection(thd, conn); 
    685675                                continue; 
     
    708698                        case ret_eof: 
    709699                        case ret_error: 
    710                                 srv_conns_num--
     700                                conns_freed++
    711701                                purge_closed_connection (thd, conn); 
    712702                                continue; 
     
    714704                        default: 
    715705                                RET_UNKNOWN(ret); 
    716                                 srv_conns_num--
     706                                conns_freed++
    717707                                purge_closed_connection (thd, conn); 
    718708                                continue; 
     
    741731 
    742732                        case ret_error: 
    743                                 srv_conns_num--
     733                                conns_freed++
    744734                                purge_closed_connection (thd, conn); 
    745735                                continue; 
     
    747737                        default: 
    748738                                RET_UNKNOWN(ret); 
    749                                 srv_conns_num--
     739                                conns_freed++
    750740                                purge_closed_connection (thd, conn); 
    751741                                break; 
     
    772762                                 */ 
    773763                                if (!cherokee_post_got_all (&conn->post)) { 
    774                                         srv_conns_num--
     764                                        conns_freed++
    775765                                        purge_closed_connection (thd, conn); 
    776766                                        continue; 
     
    781771 
    782772                        case ret_error: 
    783                                 srv_conns_num--
     773                                conns_freed++
    784774                                purge_closed_connection (thd, conn); 
    785775                                continue; 
     
    787777                        default: 
    788778                                RET_UNKNOWN(ret); 
    789                                 srv_conns_num--
     779                                conns_freed++
    790780                                purge_closed_connection (thd, conn); 
    791781                                continue; 
     
    812802                                        break; 
    813803                                case ret_error: 
    814                                         srv_conns_num--
     804                                        conns_freed++
    815805                                        purge_closed_connection (thd, conn); 
    816806                                        continue; 
    817807                                default: 
    818808                                        RET_UNKNOWN(ret); 
    819                                         srv_conns_num--
     809                                        conns_freed++
    820810                                        purge_closed_connection (thd, conn); 
    821811                                        continue; 
     
    833823                        case ret_eof: 
    834824                        case ret_error: 
    835                                 srv_conns_num--
     825                                conns_freed++
    836826                                purge_closed_connection (thd, conn); 
    837827                                continue; 
    838828                        default: 
    839829                                RET_UNKNOWN(ret); 
    840                                 srv_conns_num--
     830                                conns_freed++
    841831                                purge_closed_connection (thd, conn); 
    842832                                continue; 
     
    863853                                continue; 
    864854                        case ret_error: 
    865                                 srv_conns_num--
     855                                conns_freed++
    866856                                purge_closed_connection (thd, conn); 
    867857                                continue; 
    868858                        default: 
    869859                                RET_UNKNOWN(ret); 
    870                                 srv_conns_num--
     860                                conns_freed++
    871861                                purge_closed_connection (thd, conn); 
    872862                                continue; 
     
    10911081                        /* Server's "Keep-Alive" could be turned "Off" 
    10921082                         */ 
    1093                         if (conn->keepalive != 0 && 
    1094                            (srv->keepalive == false || 
    1095                             srv_conns_num >= (cuint_t) srv->max_keepalive_conns)) { 
    1096                                 conn->keepalive = 0; 
     1083                        if (conn->keepalive != 0) { 
     1084                               if ((srv->keepalive == false) || 
     1085                                   ((srv->conns_num_bogo - conns_freed) >= srv->conns_keepalive_max)) 
     1086                                       conn->keepalive = 0; 
    10971087                        } 
    10981088