/[hydra]/hydra/src/request.c
ViewVC logotype

Diff of /hydra/src/request.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.24 by nmav, Wed Oct 2 20:20:45 2002 UTC revision 1.25 by nmav, Thu Oct 3 11:26:15 2002 UTC
# Line 66  request *new_request(server_params* para Line 66  request *new_request(server_params* para
66  }  }
67    
68  #ifdef ENABLE_SMP  #ifdef ENABLE_SMP
69   static pthread_mutex_t accept_mutex[2]  = {   static pthread_mutex_t accept_mutex  = PTHREAD_MUTEX_INITIALIZER;
         PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER };  
70  #endif  #endif
71    
72    static int total_global_connections = 0;
73    
74    /* Decreases total_global_connections, but does some locking
75     * too.
76     */
77    inline
78    static void decrease_global_total_connections()
79    {
80        /* if we do want to serv as much as possible, then
81         * don't bother counting connections.
82         */
83        if (max_connections == INT_MAX) return;
84    
85    #ifdef ENABLE_SMP
86        pthread_mutex_lock( &accept_mutex);
87    #endif
88        total_global_connections--;
89    #ifdef ENABLE_SMP
90        pthread_mutex_unlock( &accept_mutex);
91    #endif
92    
93    }
94    
95  /*  /*
96   * Name: get_request   * Name: get_request
97   *   *
# Line 97  void get_request(server_params* params, Line 119  void get_request(server_params* params,
119       * 0 or 1, and we have 2 mutexes, one for the secure port,       * 0 or 1, and we have 2 mutexes, one for the secure port,
120       * and one of the normal http port.       * and one of the normal http port.
121       */       */
122      pthread_mutex_lock( &accept_mutex[ server_s->secure]);      pthread_mutex_lock( &accept_mutex);
123  #endif  #endif
     fd = accept(server_s->socket, (struct sockaddr *) &remote_addr,  
                 &remote_addrlen);  
124    
125  #ifdef ENABLE_SMP      /* If we have reached our max connections limit
     /* No dead lock conditions here, since accept() is non blocking.  
126       */       */
127      pthread_mutex_unlock( &accept_mutex[ server_s->secure]);      if (total_global_connections >= max_connections) {
128  #endif          server_s->pending_requests = 0;
129            goto unlock;
130        }
131    
132        fd = accept(server_s->socket, (struct sockaddr *) &remote_addr,
133                    &remote_addrlen);
134    
135      if (fd == -1) {      if (fd == -1) {
136          if (errno != EAGAIN && errno != EWOULDBLOCK)          if (errno != EAGAIN && errno != EWOULDBLOCK)
# Line 115  void get_request(server_params* params, Line 139  void get_request(server_params* params,
139          else          else
140              /* no requests */              /* no requests */
141              server_s->pending_requests = 0;              server_s->pending_requests = 0;
142          return;          goto unlock;
143      }      }
144    
145        /* only count, if we have enabled a connection limit */
146        if (max_connections != INT_MAX)
147           total_global_connections++;
148    
149    #ifdef ENABLE_SMP
150        /* No dead lock conditions here, since accept() is non blocking.
151         */
152        pthread_mutex_unlock( &accept_mutex);
153    #endif
154    
155      if (fd >= FD_SETSIZE) {      if (fd >= FD_SETSIZE) {
156          WARN("Got fd >= FD_SETSIZE.");          WARN("Got fd >= FD_SETSIZE.");
157          close(fd);          close(fd);
# Line 264  void get_request(server_params* params, Line 299  void get_request(server_params* params,
299      }      }
300  #endif /* TCP_CORK */  #endif /* TCP_CORK */
301    
 #ifndef NO_RATE_LIMIT  
     /* We use the fact the file descriptors are  
      * assigned sequentialy.  
      */  
 #define MAX(x,y) (x>y?x:y)  
     if (conn->fd > (MAX(max_connections - 10, 0))) {  
         send_r_service_unavailable(conn);  
         conn->status = DONE;  
         server_s->pending_requests = 0;  
     }  
 #endif                          /* NO_RATE_LIMIT */  
   
302      params->total_connections++;      params->total_connections++;
303            
304      enqueue(&params->request_ready, conn);      enqueue(&params->request_ready, conn);
305    
306        return;
307        
308    unlock:
309    #ifdef ENABLE_SMP
310        pthread_mutex_unlock( &accept_mutex);
311    #endif
312       return;
313  }  }
314    
315    
# Line 350  static void free_request( server_params Line 381  static void free_request( server_params
381              enqueue(&params->request_free, req);              enqueue(&params->request_free, req);
382              close(req->fd);              close(req->fd);
383              params->total_connections--;              params->total_connections--;
384                decrease_global_total_connections();
385              return;              return;
386          }          }
387          conn->fd = req->fd;          conn->fd = req->fd;
# Line 363  static void free_request( server_params Line 395  static void free_request( server_params
395                          enqueue(&params->request_free, req);                          enqueue(&params->request_free, req);
396                          close(req->fd);                          close(req->fd);
397                          params->total_connections--;                          params->total_connections--;
398                            decrease_global_total_connections();
399                          return;                          return;
400                  }                  }
401    
# Line 459  static void free_request( server_params Line 492  static void free_request( server_params
492      close(req->fd);      close(req->fd);
493    
494      params->total_connections--;      params->total_connections--;
495        decrease_global_total_connections();
496    
497      enqueue(&params->request_free, req);      enqueue(&params->request_free, req);
498    

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26