Author: rhuijben
Date: Tue Nov 24 12:09:14 2015
New Revision: 1716115
URL: http://svn.apache.org/viewvc?rev=1716115&view=rev
Log:
Revert a behavior change of the incoming client pool handling applied
in r1714449. Add documentation for the function and its 'special' pool
assumptions.
* incoming.c
(read_from_client): Remove obsolete comment. This was already implemented.
(serf_incoming_create2): Don't create pool. Use passed pool. Don't
destroy pool on failures as caller already does that.
* serf.h
(serf_incoming_create2): Rename pool. Add documentation.
Modified:
serf/trunk/incoming.c
serf/trunk/serf.h
Modified: serf/trunk/incoming.c
URL:
http://svn.apache.org/viewvc/serf/trunk/incoming.c?rev=1716115&r1=1716114&r2=1716115&view=diff
==============================================================================
--- serf/trunk/incoming.c (original)
+++ serf/trunk/incoming.c Tue Nov 24 12:09:14 2015
@@ -349,8 +349,6 @@ static apr_status_t read_from_client(ser
status = client->closed(client, client->closed_baton, status,
client->pool);
- /* ### Somehow do a apr_pool_destroy(client->pool); */
-
return status;
}
@@ -542,20 +540,17 @@ apr_status_t serf_incoming_create2(
void *closed_baton,
serf_incoming_request_setup_t req_setup,
void *req_setup_baton,
- apr_pool_t *pool)
+ apr_pool_t *client_pool)
{
- apr_status_t rv;
- apr_pool_t *ic_pool;
+ apr_status_t status;
serf_incoming_t *ic;
serf_config_t *config;
- apr_pool_create(&ic_pool, pool);
-
- ic = apr_palloc(ic_pool, sizeof(*ic));
+ ic = apr_palloc(client_pool, sizeof(*ic));
ic->ctx = ctx;
- ic->pool = ic_pool;
- ic->allocator = serf_bucket_allocator_create(ic_pool, NULL, NULL);
+ ic->pool = client_pool;
+ ic->allocator = serf_bucket_allocator_create(client_pool, NULL, NULL);
ic->io.type = SERF_IO_CLIENT;
ic->io.u.client = ic;
ic->io.ctx = ctx;
@@ -575,11 +570,11 @@ apr_status_t serf_incoming_create2(
ic->closed_baton = closed_baton;
/* Store the connection specific info in the configuration store */
- rv = serf__config_store_get_client_config(ctx, ic, &config, pool);
- if (rv) {
- apr_pool_destroy(ic->pool);
- return rv;
- }
+ status = serf__config_store_get_client_config(ctx, ic, &config,
+ client_pool);
+ if (status)
+ return status;
+
ic->config = config;
/* Prepare wrapping the socket with buckets. */
@@ -597,22 +592,18 @@ apr_status_t serf_incoming_create2(
ic->desc.reqevents = APR_POLLIN | APR_POLLERR | APR_POLLHUP;
ic->seen_in_pollset = 0;
- rv = ctx->pollset_add(ctx->pollset_baton,
- &ic->desc, &ic->io);
+ status = ctx->pollset_add(ctx->pollset_baton, &ic->desc, &ic->io);
- if (!rv) {
- apr_pool_cleanup_register(ic->pool, ic, incoming_cleanup,
- apr_pool_cleanup_null);
- *client = ic;
- }
- else {
- apr_pool_destroy(ic_pool);
- /* Let caller handle the socket */
- }
+ if (status)
+ return status;
- *(serf_incoming_t **)apr_array_push(ctx->incomings) = *client;
+ apr_pool_cleanup_register(ic->pool, ic, incoming_cleanup,
+ apr_pool_cleanup_null);
- return rv;
+ APR_ARRAY_PUSH(ctx->incomings, serf_incoming_t *) = ic;
+ *client = ic;
+
+ return status;
}
apr_status_t serf_listener_create(
Modified: serf/trunk/serf.h
URL:
http://svn.apache.org/viewvc/serf/trunk/serf.h?rev=1716115&r1=1716114&r2=1716115&view=diff
==============================================================================
--- serf/trunk/serf.h (original)
+++ serf/trunk/serf.h Tue Nov 24 12:09:14 2015
@@ -558,6 +558,28 @@ apr_status_t serf_incoming_create(
serf_incoming_request_cb_t request,
apr_pool_t *pool);
+/**
+ * Creates a new client associated with @a ctx for socket @a insock. The client
+ * takes responsibility for @a client_pool and will destroy it after the
+ * connection is closed. Typically this would be the same pool as where the
+ * incomming socket @a insock is allocated in.
+ *
+ * This non-standard behavior is needed to support listeners inside the same
+ * @a ctx instance without leaking memory for each used connections. Callers
+ * might want to create a specific client pool if they use a non-standard
+ * listening pattern.
+ *
+ * Once the connection is setup @a setup will be called with @a setup_baton
+ * to setup the connection's bucket support.
+ *
+ * When the connection closed @a closed will be called with @a closed_baton to
+ * notify that the client and its pool are about to be destroyed.
+ *
+ * Once the connection is fully setup incoming requests will be routed to @a
+ * req_setup with @a req_setup_baton, to handle processing.
+ *
+ * @since New in 1.4.
+ */
apr_status_t serf_incoming_create2(
serf_incoming_t **client,
serf_context_t *ctx,
@@ -568,7 +590,7 @@ apr_status_t serf_incoming_create2(
void *closed_baton,
serf_incoming_request_setup_t req_setup,
void *req_setup_baton,
- apr_pool_t *pool);
+ apr_pool_t *client_pool);
/* Allows creating a response before the request is completely
read. Will call the response create function if it hasn't