/**
* @package Apache connection library
*/
-
#ifdef CORE_PRIVATE
-/**
- * Create a new connection.
- * @param p Pool to allocate data structures out of
- * @param server The server to create the connection for
- * @param csd The socket to use for all communication with the client
- * @param id ID of this connection; unique at any point in time.
- * @param sbh Scoreboard handle
- * @return new conn_rec, or NULL if the connection has already been reset
- */
-AP_CORE_DECLARE(conn_rec *)ap_new_connection(apr_pool_t *ptrans, server_rec *server,
- apr_socket_t *csd, long id, void *sbh);
-
/**
* This is the protocol module driver. This calls all of the
* pre-connection and connection hooks for all protocol modules.
/* Hooks */
/**
- * This hook is used to install the bottom most input and output
- * filters (e.g., CORE_IN and CORE_OUT) used to interface to the
- * network. This filter is a RUN_FIRST hook that runs right before
- * the pre_connection filter. This filter hook can use vhost
- * configuration to influence its operation.
+ * create_connection is a RUN_FIRST hook which allows modules to create
+ * connections. In general, you should not install filters with the
+ * create_connection hook. If you require vhost configuration information
+ * to make filter installation decisions, you must use the pre_connection
+ * or install_network_transport hook. This hook should close the connection
+ * if it encounters a fatal error condition.
+ *
+ * @param p The pool from which to allocate the connection record
+ * @param csd The socket that has been accepted
+ * @param conn_id A unique identifier for this connection. The ID only
+ * needs to be unique at that time, not forever.
+ * @param sbh A handle to scoreboard information for this connection.
+ * @return An allocated connection record or NULL.
+ */
+AP_DECLARE_HOOK(conn_rec *, create_connection,
+ (apr_pool_t *p, server_rec *server, apr_socket_t *csd, long conn_id, void *sbh))
+
+/**
+ * install_transport_filters is a RUN_FIRST hook used to install the bottom
+ * most input and output network transport filters (e.g., CORE_IN and CORE_OUT)
+ * used to interface to the network. This hook can access vhost configuration.
+ *
* @param c The socket to the client
* @param csd Pointer to the client apr_socket_t struct.
* @return OK or DECLINED
}
/* the socket is now open, create a new connection */
- origin = ap_new_connection(p, r->server, sock, r->connection->id, r->connection->sbh);
+ origin = ap_run_create_connection(p, r->server, sock, r->connection->id, r->connection->sbh);
if (!origin) {
/*
- * the peer reset the connection already; ap_new_connection() closed
+ * the peer reset the connection already; ap_run_create_connection() closed
* the socket
*/
ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
}
/* the transfer socket is now open, create a new connection */
- data = ap_new_connection(p, r->server, data_sock, r->connection->id, r->connection->sbh);
+ data = ap_run_create_connection(p, r->server, data_sock, r->connection->id, r->connection->sbh);
if (!data) {
/*
- * the peer reset the connection already; ap_new_connection() closed
+ * the peer reset the connection already; ap_run_create_connection() closed
* the socket
*/
ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
"proxy: socket is connected");
/* the socket is now open, create a new backend server connection */
- *origin = ap_new_connection(c->pool, r->server, p_conn->sock,
- r->connection->id, r->connection->sbh);
+ *origin = ap_run_create_connection(c->pool, r->server, p_conn->sock,
+ r->connection->id, r->connection->sbh);
if (!origin) {
- /* the peer reset the connection already; ap_new_connection()
+ /* the peer reset the connection already; ap_run_create_connection()
* closed the socket
*/
ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
#include "util_filter.h"
APR_HOOK_STRUCT(
- APR_HOOK_LINK(pre_connection)
+ APR_HOOK_LINK(create_connection)
APR_HOOK_LINK(process_connection)
APR_HOOK_LINK(install_transport_filters)
+ APR_HOOK_LINK(pre_connection)
)
-
-AP_IMPLEMENT_HOOK_RUN_ALL(int,pre_connection,(conn_rec *c),(c),OK,DECLINED)
+AP_IMPLEMENT_HOOK_RUN_FIRST(conn_rec *,create_connection,
+ (apr_pool_t *p, server_rec *server, apr_socket_t *csd, long conn_id, void *sbh),
+ (p, server, csd, conn_id, sbh), NULL)
AP_IMPLEMENT_HOOK_RUN_FIRST(int,process_connection,(conn_rec *c),(c),DECLINED)
AP_IMPLEMENT_HOOK_RUN_FIRST(int, install_transport_filters,
(conn_rec *c, apr_socket_t *csd),(c, csd), DECLINED)
-
+AP_IMPLEMENT_HOOK_RUN_ALL(int,pre_connection,(conn_rec *c),(c),OK,DECLINED)
/*
* More machine-dependent networking gooo... on some systems,
* you've got to be *really* sure that all the packets are acknowledged
ap_run_process_connection(c);
}
}
-AP_CORE_DECLARE(conn_rec *)ap_new_connection(apr_pool_t *ptrans, server_rec *server,
- apr_socket_t *csd, long id, void *sbh)
-{
- apr_status_t rv;
- conn_rec *c = (conn_rec *) apr_pcalloc(ptrans, sizeof(conn_rec));
- c->sbh = sbh;
- (void) ap_update_child_status(c->sbh, SERVER_BUSY_READ, (request_rec *) NULL);
-
- /* Got a connection structure, so initialize what fields we can
- * (the rest are zeroed out by pcalloc).
- */
- c->conn_config=ap_create_conn_config(ptrans);
- c->notes = apr_table_make(ptrans, 5);
-
- c->pool = ptrans;
- if ((rv = apr_socket_addr_get(&c->local_addr, APR_LOCAL, csd))
- != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_INFO, rv, server,
- "apr_socket_addr_get(APR_LOCAL)");
- apr_socket_close(csd);
- return NULL;
- }
- apr_sockaddr_ip_get(&c->local_ip, c->local_addr);
- if ((rv = apr_socket_addr_get(&c->remote_addr, APR_REMOTE, csd))
- != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_INFO, rv, server,
- "apr_socket_addr_get(APR_REMOTE)");
- apr_socket_close(csd);
- return NULL;
- }
- apr_sockaddr_ip_get(&c->remote_ip, c->remote_addr);
- c->base_server = server;
-
- c->id = id;
- return c;
-}
{
return core_create_req(pr);
}
+static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server,
+ apr_socket_t *csd, long id, void *sbh)
+{
+ apr_status_t rv;
+ conn_rec *c = (conn_rec *) apr_pcalloc(ptrans, sizeof(conn_rec));
+ c->sbh = sbh;
+ (void) ap_update_child_status(c->sbh, SERVER_BUSY_READ, (request_rec *) NULL);
+
+ /* Got a connection structure, so initialize what fields we can
+ * (the rest are zeroed out by pcalloc).
+ */
+ c->conn_config=ap_create_conn_config(ptrans);
+ c->notes = apr_table_make(ptrans, 5);
+
+ c->pool = ptrans;
+ if ((rv = apr_socket_addr_get(&c->local_addr, APR_LOCAL, csd))
+ != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_INFO, rv, server,
+ "apr_socket_addr_get(APR_LOCAL)");
+ apr_socket_close(csd);
+ return NULL;
+ }
+ apr_sockaddr_ip_get(&c->local_ip, c->local_addr);
+ if ((rv = apr_socket_addr_get(&c->remote_addr, APR_REMOTE, csd))
+ != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_INFO, rv, server,
+ "apr_socket_addr_get(APR_REMOTE)");
+ apr_socket_close(csd);
+ return NULL;
+ }
+ apr_sockaddr_ip_get(&c->remote_ip, c->remote_addr);
+ c->base_server = server;
+
+ c->id = id;
+ return c;
+}
static int core_install_transport_filters(conn_rec *c, apr_socket_t *csd)
{
core_net_rec *net = apr_palloc(c->pool, sizeof(*net));
static void register_hooks(apr_pool_t *p)
{
+ /* create_connection and install_transport_filters are RUN_FIRST
+ * hooks that should always be APR_HOOK_REALLY_LAST to give other
+ * modules the opportunity to install alternate network transports
+ */
+ ap_hook_create_connection(core_create_conn, NULL, NULL, APR_HOOK_REALLY_LAST);
ap_hook_install_transport_filters(core_install_transport_filters, NULL,
NULL, APR_HOOK_REALLY_LAST);
+
ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST);
ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST);
ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST);
core_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};
+
+
}
ap_create_sb_handle(&sbh, p, 0, my_child_num);
- current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh);
+ current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id, sbh);
if (current_conn) {
ap_process_connection(current_conn, sock);
}
ap_create_sb_handle(&sbh, p, conn_id / thread_limit, thread_num);
- current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh);
+ current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id, sbh);
if (current_conn) {
ap_process_connection(current_conn, sock);
ap_lingering_close(current_conn);
rc == 0 && rd.ulData != WORKTYPE_EXIT) {
pconn = worker_args->pconn;
ap_create_sb_handle(&sbh, pconn, child_slot, thread_slot);
- current_conn = ap_new_connection(pconn, ap_server_conf, worker_args->conn_sd, conn_id, sbh);
+ current_conn = ap_run_create_connection(pconn, ap_server_conf, worker_args->conn_sd, conn_id, sbh);
if (current_conn) {
ap_process_connection(current_conn, worker_args->conn_sd);
* We now have a connection, so set it up with the appropriate
* socket options, file descriptors, and read/write buffers.
*/
- current_conn = ap_new_connection(ptrans, ap_server_conf, csd,
- my_worker_num, sbh);
+ current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd,
+ my_worker_num, sbh);
if (current_conn) {
ap_process_connection(current_conn, csd);
ap_lingering_close(current_conn);
}
ap_create_sb_handle(&sbh, p, conn_id / thread_limit, thread_num);
- current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh);
+ current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id, sbh);
if (current_conn) {
ap_process_connection(current_conn, sock);
ap_lingering_close(current_conn);
* socket options, file descriptors, and read/write buffers.
*/
- current_conn = ap_new_connection(ptrans, ap_server_conf, csd, my_child_num, sbh);
+ current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num, sbh);
if (current_conn) {
ap_process_connection(current_conn, csd);
ap_lingering_close(current_conn);
* Main entry point for the worker threads. Worker threads block in
* win*_get_connection() awaiting a connection to service.
*/
-static void worker_main(int thread_num)
+static void worker_main(long thread_num)
{
static int requests_this_child = 0;
PCOMP_CONTEXT context = NULL;
apr_os_sock_make(&context->sock, &sockinfo, context->ptrans);
ap_create_sb_handle(&sbh, context->ptrans, 0, thread_num);
- c = ap_new_connection(context->ptrans, ap_server_conf, context->sock,
- thread_num, sbh);
+ c = ap_run_create_connection(context->ptrans, ap_server_conf, context->sock,
+ thread_num, sbh);
if (c) {
ap_process_connection(c, context->sock);
}
}
else {
- /* ap_new_connection closes the socket on failure */
+ /* ap_run_create_connection closes the socket on failure */
context->accept_socket = INVALID_SOCKET;
}
}
"Child %d: exit_event_name = %s", my_pid, exit_event_name);
/* Set up the scoreboard. */
ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
- ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
+ ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
"getting listeners child_main", my_pid);
get_listeners_from_parent(ap_server_conf);
}
return;
}
- current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id, sbh);
+ current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id, sbh);
if (current_conn) {
ap_process_connection(current_conn, sock);
ap_lingering_close(current_conn);