mirror of
https://github.com/apache/httpd.git
synced 2025-08-07 04:02:58 +03:00
Added close_on_recycle flags for creatin connections.
This flag enables to distinguish between connection types. Also added a pool cleanup bound to connection pool that recycles the connection when client disconnects from server. Submitted by: mturk git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@104599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -192,6 +192,7 @@ typedef struct {
|
|||||||
apr_socket_t *sock; /* Connection socket */
|
apr_socket_t *sock; /* Connection socket */
|
||||||
apr_uint32_t flags; /* Conection flags */
|
apr_uint32_t flags; /* Conection flags */
|
||||||
int close; /* Close 'this' connection */
|
int close; /* Close 'this' connection */
|
||||||
|
int close_on_recycle; /* Close the connection when returning to pool */
|
||||||
proxy_worker *worker; /* Connection pool this connection belogns to */
|
proxy_worker *worker; /* Connection pool this connection belogns to */
|
||||||
void *data; /* per scheme connection data */
|
void *data; /* per scheme connection data */
|
||||||
} proxy_conn_rec;
|
} proxy_conn_rec;
|
||||||
@@ -364,7 +365,7 @@ PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function, proxy
|
|||||||
PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function, proxy_conn_rec *conn, 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(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, 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);
|
PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec *conn, int close_on_recycle, conn_rec *c, server_rec *s);
|
||||||
|
|
||||||
/* For proxy_util */
|
/* For proxy_util */
|
||||||
extern module PROXY_DECLARE_DATA proxy_module;
|
extern module PROXY_DECLARE_DATA proxy_module;
|
||||||
|
@@ -1324,6 +1324,22 @@ static apr_status_t proxy_conn_cleanup(void *theconn)
|
|||||||
return APR_SUCCESS;
|
return APR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static apr_status_t connection_cleanup(void *theconn)
|
||||||
|
{
|
||||||
|
proxy_conn_rec *conn = (proxy_conn_rec *)theconn;
|
||||||
|
/* deterimine if the connection need to be closed */
|
||||||
|
if (conn->close_on_recycle) {
|
||||||
|
if (conn->sock)
|
||||||
|
apr_socket_close(conn->sock);
|
||||||
|
conn->sock = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
conn->connection = NULL;
|
||||||
|
ap_proxy_release_connection(NULL, conn, NULL);
|
||||||
|
/* Allways return the SUCCESS */
|
||||||
|
return APR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* reslist constructor */
|
/* reslist constructor */
|
||||||
static apr_status_t connection_constructor(void **resource, void *params,
|
static apr_status_t connection_constructor(void **resource, void *params,
|
||||||
apr_pool_t *pool)
|
apr_pool_t *pool)
|
||||||
@@ -1446,6 +1462,17 @@ PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
|
|||||||
* for now make a core dump.
|
* for now make a core dump.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Need to close the connection */
|
||||||
|
if (conn->sock && conn->close) {
|
||||||
|
apr_socket_close(conn->sock);
|
||||||
|
conn->sock = NULL;
|
||||||
|
}
|
||||||
|
conn->close = 0;
|
||||||
|
/* If there is a connection kill it's cleanup */
|
||||||
|
if (conn->connection)
|
||||||
|
apr_pool_cleanup_kill(conn->connection->pool, conn, connection_cleanup);
|
||||||
|
|
||||||
#if APR_HAS_THREADS
|
#if APR_HAS_THREADS
|
||||||
if (worker->hmax) {
|
if (worker->hmax) {
|
||||||
rv = apr_reslist_release(worker->cp->res, (void *)conn);
|
rv = apr_reslist_release(worker->cp->res, (void *)conn);
|
||||||
@@ -1455,7 +1482,7 @@ PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
|
|||||||
{
|
{
|
||||||
worker->cp->conn = conn;
|
worker->cp->conn = conn;
|
||||||
}
|
}
|
||||||
if (rv != APR_SUCCESS) {
|
if (rv != APR_SUCCESS && proxy_function) {
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
|
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
|
||||||
"proxy: %s: failed to acquire connection for (%s)",
|
"proxy: %s: failed to acquire connection for (%s)",
|
||||||
proxy_function, conn->hostname);
|
proxy_function, conn->hostname);
|
||||||
@@ -1664,6 +1691,7 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
|
|||||||
|
|
||||||
PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
|
PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
|
||||||
proxy_conn_rec *conn,
|
proxy_conn_rec *conn,
|
||||||
|
int close_on_recycle,
|
||||||
conn_rec *c,
|
conn_rec *c,
|
||||||
server_rec *s)
|
server_rec *s)
|
||||||
{
|
{
|
||||||
@@ -1705,6 +1733,7 @@ PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
|
|||||||
/* TODO: See if this will break FTP */
|
/* TODO: See if this will break FTP */
|
||||||
ap_proxy_ssl_disable(conn->connection);
|
ap_proxy_ssl_disable(conn->connection);
|
||||||
}
|
}
|
||||||
|
conn->close_on_recycle = close_on_recycle;
|
||||||
|
|
||||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
||||||
"proxy: %s: connection complete to %pI (%s)",
|
"proxy: %s: connection complete to %pI (%s)",
|
||||||
@@ -1713,5 +1742,11 @@ PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
|
|||||||
/* set up the connection filters */
|
/* set up the connection filters */
|
||||||
ap_run_pre_connection(conn->connection, conn->sock);
|
ap_run_pre_connection(conn->connection, conn->sock);
|
||||||
|
|
||||||
|
/* register the connection cleanup to client connection
|
||||||
|
* so that the connection can be closed or reused
|
||||||
|
*/
|
||||||
|
apr_pool_cleanup_register(c->pool, (void *)conn, connection_cleanup,
|
||||||
|
apr_pool_cleanup_null);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user