You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@apache.org on 2001/11/21 04:46:22 UTC

cvs commit: httpd-2.0/server core.c protocol.c

rbb         01/11/20 19:46:22

  Modified:    include  httpd.h
               modules/http http_core.c
               server   core.c protocol.c
  Log:
  Fix the timeout logic that I broke last week.  This adds a request
  level filter that sets the timeout on the socket that is connected
  to the client.
  
  Thanks Greg Stein for seeing this bug.
  
  Revision  Changes    Path
  1.170     +0 -1      httpd-2.0/include/httpd.h
  
  Index: httpd.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/include/httpd.h,v
  retrieving revision 1.169
  retrieving revision 1.170
  diff -u -r1.169 -r1.170
  --- httpd.h	2001/11/12 23:49:06	1.169
  +++ httpd.h	2001/11/21 03:46:21	1.170
  @@ -1064,7 +1064,6 @@
    
   typedef struct core_filter_ctx {
       apr_bucket_brigade *b;
  -    int first_line;
   } core_ctx_t;
    
   typedef struct core_net_rec {
  
  
  
  1.287     +1 -0      httpd-2.0/modules/http/http_core.c
  
  Index: http_core.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/http/http_core.c,v
  retrieving revision 1.286
  retrieving revision 1.287
  diff -u -r1.286 -r1.287
  --- http_core.c	2001/11/12 23:49:06	1.286
  +++ http_core.c	2001/11/21 03:46:22	1.287
  @@ -275,6 +275,7 @@
       ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_BUSY_READ, NULL);
       while ((r = ap_read_request(c)) != NULL) {
    
  +        c->keepalive = 0;
           /* process the request if it was read without error */
    
           ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_BUSY_WRITE, r);
  
  
  
  1.101     +32 -16    httpd-2.0/server/core.c
  
  Index: core.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/core.c,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- core.c	2001/11/19 22:36:20	1.100
  +++ core.c	2001/11/21 03:46:22	1.101
  @@ -2780,6 +2780,35 @@
       return ap_pass_brigade(r->output_filters, bb);
   }
   
  +static int net_time_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes)
  +{
  +    int keptalive = f->c->keepalive == 1;
  +    apr_socket_t *csd = ap_get_module_config(f->c->conn_config, &core_module);
  +    int *first_line = f->ctx;
  +
  +    if (!f->ctx) {
  +        f->ctx = first_line = apr_palloc(f->r->pool, sizeof(*first_line));
  +        *first_line = 1;
  +    }
  +
  +    if (mode != AP_MODE_INIT && mode != AP_MODE_PEEK) {
  +        if (*first_line) {
  +            apr_setsocketopt(csd, APR_SO_TIMEOUT,
  +                             (int)(keptalive
  +                      ? f->c->base_server->keep_alive_timeout * APR_USEC_PER_SEC
  +                      : f->c->base_server->timeout * APR_USEC_PER_SEC));
  +            *first_line = 0;
  +        }
  +        else {
  +            if (keptalive) {
  +                apr_setsocketopt(csd, APR_SO_TIMEOUT,
  +                         (int)(f->c->base_server->timeout * APR_USEC_PER_SEC));
  +            }
  +        }
  +    }
  +    return ap_get_brigade(f->next, b, mode, readbytes);
  +}
  +
   static int core_input_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes)
   {
       apr_bucket *e;
  @@ -2788,7 +2817,6 @@
       core_ctx_t *ctx = net->in_ctx;
       const char *str;
       apr_size_t len;
  -    int keptalive = f->c->keepalive == 1;
   
       if (mode == AP_MODE_INIT) {
           /*
  @@ -2813,23 +2841,8 @@
           e = apr_bucket_socket_create(net->client_socket);
           APR_BRIGADE_INSERT_TAIL(ctx->b, e);
           net->in_ctx = ctx;
  -        ctx->first_line = 1;
       }
   
  -    if (ctx->first_line) {
  -        apr_setsocketopt(net->client_socket, APR_SO_TIMEOUT,
  -                         (int)(keptalive
  -                         ? f->c->base_server->keep_alive_timeout * APR_USEC_PER_SEC
  -                         : f->c->base_server->timeout * APR_USEC_PER_SEC));
  -        ctx->first_line = 0;
  -    }
  -    else {
  -        if (keptalive) {
  -            apr_setsocketopt(net->client_socket, APR_SO_TIMEOUT,
  -                             (int)(f->c->base_server->timeout * APR_USEC_PER_SEC));
  -        }
  -    }
  -
       /* ### This is bad. */
       APR_BRIGADE_NORMALIZE(ctx->b);
   
  @@ -3272,6 +3285,8 @@
           req_cfg->bb = apr_brigade_create(r->pool);
           ap_set_module_config(r->request_config, &core_module, req_cfg);
       }
  +
  +    ap_add_input_filter("NET_TIME", NULL, r, r->connection);
       return OK;
   }
   
  @@ -3355,6 +3370,7 @@
       ap_hook_insert_filter(core_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
   
       ap_register_input_filter("CORE_IN", core_input_filter, AP_FTYPE_NETWORK);
  +    ap_register_input_filter("NET_TIME", net_time_filter, AP_FTYPE_CONTENT);
       ap_register_output_filter("CONTENT_LENGTH", ap_content_length_filter, 
                                 AP_FTYPE_HTTP_HEADER);
       ap_register_output_filter("CORE", core_output_filter, AP_FTYPE_NETWORK);
  
  
  
  1.54      +0 -2      httpd-2.0/server/protocol.c
  
  Index: protocol.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/protocol.c,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- protocol.c	2001/11/21 03:19:13	1.53
  +++ protocol.c	2001/11/21 03:46:22	1.54
  @@ -553,8 +553,6 @@
       r->connection      = conn;
       r->server          = conn->base_server;
   
  -    conn->keepalive    = 0;
  -
       r->user            = NULL;
       r->ap_auth_type    = NULL;