tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/ajp/proxy proxy_util.c mod_proxy.h
Date Thu, 05 Aug 2004 19:09:13 GMT
mturk       2004/08/05 12:09:13

  Modified:    ajp/proxy proxy_util.c mod_proxy.h
  Log:
  Added acquire and release connection functions.
  The acquire pulls the connection from the pool.
  The release returns the connection to the pool.
  
  Revision  Changes    Path
  1.17      +66 -54    jakarta-tomcat-connectors/ajp/proxy/proxy_util.c
  
  Index: proxy_util.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/proxy/proxy_util.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- proxy_util.c	5 Aug 2004 18:32:57 -0000	1.16
  +++ proxy_util.c	5 Aug 2004 19:09:13 -0000	1.17
  @@ -1366,83 +1366,102 @@
       return APR_SUCCESS;
   }
   
  -/* Destroy the connection */
  -PROXY_DECLARE(apr_status_t) ap_proxy_destroy_connection(proxy_conn_rec *conn)
  -{
  -    return connection_destructor(conn, NULL, NULL);
  -}
  -
  -/* Destroy the connection */
  +/* Close the connection 
  + * The proxy_conn_rec from now on can not be used
  + */
   PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn)
   {
  -    apr_status_t rv = APR_EOF;
  -    /* Close the socket */
  -    if (conn->sock)
  -        rv = apr_socket_close(conn->sock);
  -    conn->sock = NULL;
  -    return rv;
  +    if (conn->worker && conn->worker->cp)
  +        conn->worker->cp->conn = NULL;
  +    return connection_destructor(conn, NULL, NULL);
   }
   
  -/* low level connection acquire/release functions
  - * they are hiding apr_reslist for nothreaded or prefork servers.
  - */
  -static apr_status_t acquire_connection_low(proxy_conn_rec **conn, proxy_worker *worker)
  +static apr_status_t init_conn_worker(proxy_worker *worker, server_rec *s)
   {
       apr_status_t rv;
   #if APR_HAS_THREADS
       if (worker->hmax) {
  -        rv = apr_reslist_acquire(worker->cp->res, (void **)conn);
  +        rv = apr_reslist_create(&(worker->cp->res),
  +                                worker->min, worker->smax,
  +                                worker->hmax, worker->ttl,
  +                                connection_constructor, connection_destructor,
  +                                s, worker->cp->pool);
  +#if (APR_MAJOR_VERSION > 0)
  +        /* Set the acquire timeout */
  +        if (rv == APR_SUCCESS && worker->acquire_set)
  +            apr_reslist_timeout_set(worker->cp->res, worker->acquire);
  +#endif
       }
       else
   #endif
       {
  -        *conn = worker->cp->conn;
  -        worker->cp->conn = NULL;
  +        
  +        connection_constructor((void **)&(worker->cp->conn), s, worker->cp->pool);
           rv = APR_SUCCESS;
       }
       return rv;
   }
   
  -static apr_status_t release_connection_low(proxy_conn_rec *conn, proxy_worker *worker)
  +PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
  +                                               proxy_conn_rec **conn,
  +                                               proxy_worker *worker,
  +                                               server_rec *s)
   {
  -    apr_status_t rv = APR_SUCCESS;
  +    apr_status_t rv;
   #if APR_HAS_THREADS
       if (worker->hmax) {
  -        rv = apr_reslist_release(worker->cp->res, (void *)conn);
  +        rv = apr_reslist_acquire(worker->cp->res, (void **)conn);
       }
       else
   #endif
       {
  -        worker->cp->conn = conn;
  +        /* create the new connection if the previous was destroyed */
  +        if (!worker->cp->conn)
  +            connection_constructor((void **)conn, s, worker->cp->pool);
  +        else {
  +            *conn = worker->cp->conn;
  +            worker->cp->conn = NULL;
  +        }
  +        rv = APR_SUCCESS;
       }
  -    return rv;
  -}
   
  +    if (rv != APR_SUCCESS) {
  +        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
  +                     "proxy: %s: failed to acquire connection for (%s)",
  +                     proxy_function, worker->hostname);
  +        return DECLINED;
  +    }
  +    return OK;
  +}
   
  -static apr_status_t init_conn_worker(proxy_worker *worker, server_rec *s)
  +PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
  +                                               proxy_conn_rec *conn,
  +                                               server_rec *s)
   {
  -    apr_status_t rv;
  +    apr_status_t rv = APR_SUCCESS;
  +    proxy_worker *worker = conn->worker;
  +
  +    if (!worker) {
  +        /* something bad happened. Obviously bug.
  +         * for now make a core dump.
  +         */
  +    }
   #if APR_HAS_THREADS
       if (worker->hmax) {
  -        rv = apr_reslist_create(&(worker->cp->res),
  -                                worker->min, worker->smax,
  -                                worker->hmax, worker->ttl,
  -                                connection_constructor, connection_destructor,
  -                                s, worker->cp->pool);
  -#if (APR_MAJOR_VERSION > 0)
  -        /* Set the acquire timeout */
  -        if (rv == APR_SUCCESS && worker->acquire_set)
  -            apr_reslist_timeout_set(worker->cp->res, worker->acquire);
  -#endif
  +        rv = apr_reslist_release(worker->cp->res, (void *)conn);
       }
       else
   #endif
       {
  -        
  -        connection_constructor((void **)&(worker->cp->conn), s, worker->cp->pool);
  -        rv = APR_SUCCESS;
  +        worker->cp->conn = conn;
       }
  -    return rv;
  +    if (rv != APR_SUCCESS) {
  +        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
  +                     "proxy: %s: failed to acquire connection for (%s)",
  +                     proxy_function, conn->hostname);
  +        return DECLINED;
  +    }
  +    return OK;
   }
   
   PROXY_DECLARE(apr_status_t)
  @@ -1554,7 +1573,6 @@
   PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
                                               proxy_conn_rec *conn,
                                               proxy_worker *worker,
  -                                            proxy_server_conf *conf,
                                               server_rec *s)
   {
       apr_status_t rv;
  @@ -1592,9 +1610,9 @@
           }
   
   #if !defined(TPF) && !defined(BEOS)
  -        if (conf->recv_buffer_size > 0 &&
  +        if (worker->recv_buffer_size > 0 &&
               (rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF,
  -                                     conf->recv_buffer_size))) {
  +                                     worker->recv_buffer_size))) {
               ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                            "apr_socket_opt_set(SO_RCVBUF): Failed to set "
                            "ProxyReceiveBufferSize, using default");
  @@ -1637,21 +1655,15 @@
               continue;
           }
           
  -        conn->sock     = newsock;
  -        conn->worker   = worker;
  -        /* XXX: the hostname will go from proxy_conn_rec
  -         * keep for now.
  -         * We will 'optimize' later, both code and unneeded data
  -         */
  -        conn->hostname = worker->hostname;
  -        connected      = 1;
  +        conn->sock   = newsock;
  +        conn->worker = worker;
  +        connected    = 1;
       }
       return connected ? OK : DECLINED;
   }
   
   PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
                                                 proxy_conn_rec *conn,
  -                                              proxy_server_conf *conf,
                                                 conn_rec *c,
                                                 server_rec *s)
   {
  
  
  
  1.23      +5 -5      jakarta-tomcat-connectors/ajp/proxy/mod_proxy.h
  
  Index: mod_proxy.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/proxy/mod_proxy.h,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- mod_proxy.h	5 Aug 2004 18:32:57 -0000	1.22
  +++ mod_proxy.h	5 Aug 2004 19:09:13 -0000	1.23
  @@ -360,12 +360,12 @@
   PROXY_DECLARE(apr_status_t) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
proxy_server_conf *conf, proxy_worker *worker, proxy_conn_rec *conn,
                                                             apr_pool_t *ppool, apr_uri_t
*uri, char **url, const char *proxyname, apr_port_t proxyport,
                                                             char *server_portstr, int server_portstr_size);
  -PROXY_DECLARE(apr_status_t) ap_proxy_destroy_connection(proxy_conn_rec *conn);
  +PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function, proxy_conn_rec
**conn, proxy_worker *worker, server_rec *s);
  +PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function, proxy_conn_rec
*conn, server_rec *s);
   PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn);
  -PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, proxy_conn_rec
*conn, proxy_worker *worker,
  -                                            proxy_server_conf *conf, server_rec *s);
  -PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec
*conn,
  -                                              proxy_server_conf *conf, conn_rec *c, server_rec
*s);
  +PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, proxy_conn_rec
*conn, proxy_worker *worker, server_rec *s);
  +PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec
*conn, conn_rec *c, server_rec *s);
  +
   /* For proxy_util */
   extern module PROXY_DECLARE_DATA proxy_module;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message