Changeset 1657

Show
Ignore:
Timestamp:
07/17/08 18:30:50 (6 months ago)
Author:
alo
Message:

--

Files:

Legend:

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

    r1654 r1657  
     12008-07-17  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
     2 
     3        * cherokee/Makefile.am, cherokee/connector.c, 
     4        cherokee/connector.h, cherokee/avl_r.c, cherokee/source.c, 
     5        cherokee/downloader.c, cherokee/server-protected.h, 
     6        cherokee/server.c: Added a new cherokee_connector_t class. It 
     7        takes care of the number of concurrent connect() calls. It may 
     8        happen that all the threads try to connect() to unresponsive 
     9        resources, so the server would block. 
     10 
    1112008-07-16  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
    212 
  • cherokee/trunk/cherokee/Makefile.am

    r1654 r1657  
    10731073source_interpreter.c \ 
    10741074info.h \ 
    1075 info.c 
     1075info.c \ 
     1076connector.h \ 
     1077connector.c 
    10761078 
    10771079libcherokee_config_la_SOURCES = \ 
  • cherokee/trunk/cherokee/avl_r.c

    r1131 r1657  
    2727 
    2828typedef struct { 
    29            CHEROKEE_RWLOCK_T(lock); 
     29        CHEROKEE_RWLOCK_T(lock); 
     30        int dummy; 
    3031} cherokee_avl_r_priv_t; 
    3132 
     
    3738cherokee_avl_r_init (cherokee_avl_r_t *avl_r) 
    3839{ 
    39            ret_t ret; 
    40            CHEROKEE_NEW_STRUCT(n, avl_r_priv); 
     40        ret_t ret; 
     41        CHEROKEE_NEW_STRUCT(n, avl_r_priv); 
    4142 
    42            ret = cherokee_avl_init (&avl_r->avl); 
    43            if (ret != ret_ok)  
    44                         return ret; 
     43        ret = cherokee_avl_init (&avl_r->avl); 
     44        if (ret != ret_ok)  
     45                return ret; 
    4546 
    46            avl_r->priv = n; 
    47            CHEROKEE_RWLOCK_INIT (AVL_R_LOCK(avl_r), NULL); 
     47        avl_r->priv = n; 
     48        CHEROKEE_RWLOCK_INIT (AVL_R_LOCK(avl_r), NULL); 
    4849 
    49            return ret_ok; 
     50        return ret_ok; 
    5051} 
    5152 
     
    5455cherokee_avl_r_mrproper (cherokee_avl_r_t *avl_r, cherokee_func_free_t free_func) 
    5556{ 
    56            if (avl_r->priv) { 
    57                         CHEROKEE_RWLOCK_DESTROY (AVL_R_LOCK(avl_r)); 
    58                         free (avl_r->priv); 
    59            
     57        if (avl_r->priv) { 
     58                CHEROKEE_RWLOCK_DESTROY (AVL_R_LOCK(avl_r)); 
     59                free (avl_r->priv); 
     60       
    6061 
    61            return cherokee_avl_mrproper (&avl_r->avl, free_func); 
     62        return cherokee_avl_mrproper (&avl_r->avl, free_func); 
    6263} 
    6364 
     
    6667cherokee_avl_r_add (cherokee_avl_r_t *avl_r, cherokee_buffer_t *key, void *value) 
    6768{ 
    68            ret_t ret; 
     69        ret_t ret; 
    6970 
    70            CHEROKEE_RWLOCK_WRITER (AVL_R_LOCK(avl_r)); 
    71            ret = cherokee_avl_add (&avl_r->avl, key, value); 
    72            CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r)); 
     71        CHEROKEE_RWLOCK_WRITER (AVL_R_LOCK(avl_r)); 
     72        ret = cherokee_avl_add (&avl_r->avl, key, value); 
     73        CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r)); 
    7374 
    74            return ret; 
     75        return ret; 
    7576} 
    7677 
     
    7980cherokee_avl_r_del (cherokee_avl_r_t *avl_r, cherokee_buffer_t *key, void **value) 
    8081{ 
    81            ret_t ret; 
     82        ret_t ret; 
    8283 
    83            CHEROKEE_RWLOCK_WRITER (AVL_R_LOCK(avl_r)); 
    84            ret = cherokee_avl_del (&avl_r->avl, key, value); 
    85            CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r)); 
     84        CHEROKEE_RWLOCK_WRITER (AVL_R_LOCK(avl_r)); 
     85        ret = cherokee_avl_del (&avl_r->avl, key, value); 
     86        CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r)); 
    8687 
    87            return ret; 
     88        return ret; 
    8889} 
    8990 
     
    9293cherokee_avl_r_get (cherokee_avl_r_t *avl_r, cherokee_buffer_t *key, void **value) 
    9394{ 
    94            ret_t ret; 
     95        ret_t ret; 
    9596 
    96            CHEROKEE_RWLOCK_READER (AVL_R_LOCK(avl_r)); 
    97            ret = cherokee_avl_get (&avl_r->avl, key, value); 
    98            CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r)); 
     97        CHEROKEE_RWLOCK_READER (AVL_R_LOCK(avl_r)); 
     98        ret = cherokee_avl_get (&avl_r->avl, key, value); 
     99        CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r)); 
    99100 
    100            return ret; 
     101        return ret; 
    101102} 
  • cherokee/trunk/cherokee/downloader.c

    r1614 r1657  
    2929#include "url.h" 
    3030#include "header-protected.h" 
     31#include "connector.h" 
    3132#include "util.h" 
    3233 
     
    186187connect_to (cherokee_downloader_t *downloader, cherokee_buffer_t *host, cuint_t port, int protocol) 
    187188{ 
    188         ret_t               ret; 
    189         cherokee_socket_t  *sock = &downloader->socket; 
     189        ret_t                 ret; 
     190        cherokee_connector_t *connector = NULL; 
     191        cherokee_socket_t    *sock      = &downloader->socket; 
    190192 
    191193        TRACE(ENTRIES, "host=%s port=%d proto=%d\n", host->buf, port, protocol); 
     194 
     195        ret = cherokee_connector_get_default (&connector); 
     196        if (ret != ret_ok) 
     197                return ret; 
    192198 
    193199        /* Create the socket 
     
    213219        /* Connect to server 
    214220         */ 
    215         ret = cherokee_socket_connect (sock); 
     221        ret = cherokee_connector_connect (connector, socket); 
    216222        TRACE(ENTRIES, "socket=%p ret=%d\n", sock, ret); 
    217         if (unlikely(ret != ret_ok)) return ret; 
     223 
     224        if (unlikely(ret != ret_ok))  
     225                return ret; 
    218226 
    219227        /* Is this connection TLS? 
  • cherokee/trunk/cherokee/server-protected.h

    r1654 r1657  
    5656#include "config_node.h" 
    5757#include "version.h" 
     58#include "connector.h" 
    5859 
    5960 
     
    114115 
    115116        cherokee_poll_type_t       fdpoll_method; 
     117        cherokee_connector_t       client_connector; 
    116118 
    117119        /* Connection related 
  • cherokee/trunk/cherokee/server.c

    r1654 r1657  
    326326        cherokee_socket_mrproper (&srv->socket); 
    327327 
     328        cherokee_connector_mrproper (&srv->client_connector); 
    328329 
    329330#ifdef HAVE_TLS 
     
    345346 
    346347        cherokee_nonce_table_free (srv->nonces); 
    347          
     348 
    348349        /* Virtual servers 
    349350         */ 
     
    11301131        if (unlikely(ret < ret_ok)) 
    11311132                return ret; 
     1133 
     1134        /* Initialize the client connector 
     1135         */ 
     1136        cherokee_connector_init (&srv->client_connector, 
     1137                                 (srv->thread_num > 2)? srv->thread_num-1 : 1); 
     1138        cherokee_connector_set_default (&srv->client_connector); 
    11321139 
    11331140        /* Print the server banner 
     
    17571764#endif 
    17581765 
     1766        UNUSED(srv); 
    17591767        return ret_ok; 
    17601768} 
  • cherokee/trunk/cherokee/source.c

    r1131 r1657  
    2828#include "resolv_cache.h" 
    2929#include "util.h" 
     30#include "connector.h" 
    3031 
    3132#define ENTRIES "source,src" 
     
    7172        ret_t                    ret; 
    7273        cherokee_resolv_cache_t *resolv; 
     74        cherokee_connector_t    *connector; 
    7375 
    7476        ret = cherokee_resolv_cache_get_default (&resolv); 
    75         if (unlikely (ret!=ret_ok)) return ret; 
     77        if (unlikely (ret!=ret_ok))  
     78                return ret; 
     79 
     80        ret = cherokee_connector_get_default (&connector); 
     81        if (unlikely (ret!=ret_ok))  
     82                return ret; 
    7683 
    7784        /* UNIX socket 
     
    8592                if (ret != ret_ok) return ret; 
    8693 
    87                 return cherokee_socket_connect (sock); 
     94                return cherokee_connector_connect (connector, socket); 
    8895        } 
    8996 
     
    99106        SOCKET_ADDR_IPv4(sock)->sin_port = htons(src->port); 
    100107         
    101         return cherokee_socket_connect (sock); 
     108        return cherokee_connector_connect (connector, socket); 
    102109} 
    103110