You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@serf.apache.org by br...@apache.org on 2016/11/15 14:29:28 UTC

svn commit: r1769841 - in /serf/trunk: serf_private.h src/config_store.c src/outgoing.c test/test_internal.c

Author: brane
Date: Tue Nov 15 14:29:27 2016
New Revision: 1769841

URL: http://svn.apache.org/viewvc?rev=1769841&view=rev
Log:
Revert r1769799 due to a chicken-and-egg problem.

Modified:
    serf/trunk/serf_private.h
    serf/trunk/src/config_store.c
    serf/trunk/src/outgoing.c
    serf/trunk/test/test_internal.c

Modified: serf/trunk/serf_private.h
URL: http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1769841&r1=1769840&r2=1769841&view=diff
==============================================================================
--- serf/trunk/serf_private.h (original)
+++ serf/trunk/serf_private.h Tue Nov 15 14:29:27 2016
@@ -334,15 +334,11 @@ apr_status_t serf__config_store_init(ser
    The host and connection entries will be created in the configuration store
    when not existing already.
 
-   The config object will be allocated in CONN's pool. The config object's
+   The config object will be allocated in OUT_POOL. The config object's
    lifecycle cannot extend beyond that of the serf context!
-
-   If OPT_POOL is is not NULL, it will be used for temporary
-   allocations and the function will always return APR_SUCCESS.
  */
 apr_status_t serf__config_store_create_conn_config(serf_connection_t *conn,
-                                                   serf_config_t **config,
-                                                   apr_pool_t *opt_pool);
+                                                   serf_config_t **config);
 
 /* Same thing, but for incoming connections */
 apr_status_t serf__config_store_create_client_config(serf_incoming_t *client,

Modified: serf/trunk/src/config_store.c
URL: http://svn.apache.org/viewvc/serf/trunk/src/config_store.c?rev=1769841&r1=1769840&r2=1769841&view=diff
==============================================================================
--- serf/trunk/src/config_store.c (original)
+++ serf/trunk/src/config_store.c Tue Nov 15 14:29:27 2016
@@ -236,27 +236,21 @@ apr_status_t serf__config_store_create_c
 }
 
 apr_status_t serf__config_store_create_conn_config(serf_connection_t *conn,
-                                                   serf_config_t **config,
-                                                   apr_pool_t *opt_pool)
+                                                   serf_config_t **config)
 {
     serf__config_store_t *config_store = &conn->ctx->config_store;
     const char *host_key, *conn_key;
     serf__config_hdr_t *per_conn, *per_host;
     apr_pool_t *tmp_pool;
+    apr_status_t status;
 
     serf_config_t *cfg = apr_pcalloc(conn->pool, sizeof(serf_config_t));
     cfg->ctx_pool = config_store->pool;
     cfg->allocator = config_store->allocator;
     cfg->per_context = config_store->global_per_context;
 
-    if (!opt_pool) {
-        apr_status_t status = apr_pool_create(&tmp_pool, cfg->ctx_pool);
-        if (status != APR_SUCCESS)
-            return status;
-    }
-    else {
-        tmp_pool = opt_pool;
-    }
+    if ((status = apr_pool_create(&tmp_pool, cfg->ctx_pool)) != APR_SUCCESS)
+        return status;
 
     /* Find the config values for this connection, create empty structure
         if needed */
@@ -285,8 +279,7 @@ apr_status_t serf__config_store_create_c
     }
     cfg->per_host = per_host;
 
-    if (tmp_pool != opt_pool)
-        apr_pool_destroy(tmp_pool);
+    apr_pool_destroy(tmp_pool);
 
     *config = cfg;
 

Modified: serf/trunk/src/outgoing.c
URL: http://svn.apache.org/viewvc/serf/trunk/src/outgoing.c?rev=1769841&r1=1769840&r2=1769841&view=diff
==============================================================================
--- serf/trunk/src/outgoing.c (original)
+++ serf/trunk/src/outgoing.c Tue Nov 15 14:29:27 2016
@@ -1216,7 +1216,7 @@ apr_status_t serf__process_connection(se
     return APR_SUCCESS;
 }
 
-static serf_connection_t *create_connection(
+serf_connection_t *serf_connection_create(
     serf_context_t *ctx,
     apr_sockaddr_t *address,
     serf_connection_setup_t setup,
@@ -1265,8 +1265,6 @@ static serf_connection_t *create_connect
 
     conn->done_reqs = conn->done_reqs_tail = 0;
 
-    conn->config = NULL;
-
     /* Create a subpool for our connection. */
     apr_pool_create(&conn->skt_pool, conn->pool);
 
@@ -1280,23 +1278,6 @@ static serf_connection_t *create_connect
     return conn;
 }
 
-serf_connection_t *serf_connection_create(
-    serf_context_t *ctx,
-    apr_sockaddr_t *address,
-    serf_connection_setup_t setup,
-    void *setup_baton,
-    serf_connection_closed_t closed,
-    void *closed_baton,
-    apr_pool_t *pool)
-{
-    serf_connection_t *conn = create_connection(ctx, address,
-                                                setup, setup_baton,
-                                                closed, closed_baton,
-                                                pool);
-    serf__config_store_create_conn_config(conn, &conn->config, pool);
-    return conn;
-}
-
 apr_status_t serf_connection_create2(
     serf_connection_t **conn,
     serf_context_t *ctx,
@@ -1327,8 +1308,8 @@ apr_status_t serf_connection_create2(
             return status;
     }
 
-    c = create_connection(ctx, host_address, setup, setup_baton,
-                          closed, closed_baton, pool);
+    c = serf_connection_create(ctx, host_address, setup, setup_baton,
+                               closed, closed_baton, pool);
 
     /* We're not interested in the path following the hostname. */
     c->host_url = apr_uri_unparse(c->pool,
@@ -1343,7 +1324,7 @@ apr_status_t serf_connection_create2(
     }
 
     /* Store the connection specific info in the configuration store */
-    status = serf__config_store_create_conn_config(c, &config, NULL);
+    status = serf__config_store_create_conn_config(c, &config);
     if (status)
         return status;
     c->config = config;

Modified: serf/trunk/test/test_internal.c
URL: http://svn.apache.org/viewvc/serf/trunk/test/test_internal.c?rev=1769841&r1=1769840&r2=1769841&view=diff
==============================================================================
--- serf/trunk/test/test_internal.c (original)
+++ serf/trunk/test/test_internal.c Tue Nov 15 14:29:27 2016
@@ -119,13 +119,13 @@ static void test_config_store_per_connec
     /* Test 1: This should return a config object with per_context, per_host and
        per_connection hash_table's initialized. */
     CuAssertIntEquals(tc, APR_SUCCESS,
-                      serf__config_store_create_conn_config(conn1, &cfg1, NULL));
+                      serf__config_store_create_conn_config(conn1, &cfg1));
     CuAssertPtrNotNull(tc, cfg1->per_context);
     CuAssertPtrNotNull(tc, cfg1->per_host);
     CuAssertPtrNotNull(tc, cfg1->per_conn);
     /* Get a config object for the other connection also. */
     CuAssertIntEquals(tc, APR_SUCCESS,
-                      serf__config_store_create_conn_config(conn2, &cfg2, NULL));
+                      serf__config_store_create_conn_config(conn2, &cfg2));
 
     /* Test 2: Get a non-existing per connection key, value should be NULL */
     CuAssertIntEquals(tc, APR_SUCCESS,
@@ -180,13 +180,13 @@ static void test_config_store_per_connec
     /* Test 1: This should return a config object with per_context, per_host and
      per_connection hash_table's initialized. */
     CuAssertIntEquals(tc, APR_SUCCESS,
-                      serf__config_store_create_conn_config(conn1, &cfg1, NULL));
+                      serf__config_store_create_conn_config(conn1, &cfg1));
     CuAssertPtrNotNull(tc, cfg1->per_context);
     CuAssertPtrNotNull(tc, cfg1->per_host);
     CuAssertPtrNotNull(tc, cfg1->per_conn);
     /* Get a config object for the other connection also. */
     CuAssertIntEquals(tc, APR_SUCCESS,
-                      serf__config_store_create_conn_config(conn2, &cfg2, NULL));
+                      serf__config_store_create_conn_config(conn2, &cfg2));
 
     /* Test 2: Get a non-existing per connection key, value should be NULL */
     CuAssertIntEquals(tc, APR_SUCCESS,
@@ -277,7 +277,7 @@ static void test_config_store_remove_obj
                             conn_closed, NULL, tb->pool);
 
     CuAssertIntEquals(tc, APR_SUCCESS,
-                      serf__config_store_create_conn_config(conn, &cfg, NULL));
+                      serf__config_store_create_conn_config(conn, &cfg));
 
     /* Add and remove a key per-context */
     CuAssertIntEquals(tc, APR_SUCCESS,



Re: svn commit: r1769841 - in /serf/trunk: serf_private.h src/config_store.c src/outgoing.c test/test_internal.c

Posted by Branko Čibej <br...@apache.org>.
On 15.11.2016 15:48, Branko \u010cibej wrote:
> On 15.11.2016 15:41, Branko \u010cibej wrote:
>> On 15.11.2016 15:29, brane@apache.org wrote:
>>> Author: brane
>>> Date: Tue Nov 15 14:29:27 2016
>>> New Revision: 1769841
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1769841&view=rev
>>> Log:
>>> Revert r1769799 due to a chicken-and-egg problem.
>> So this was fun.
>>
>> What I didn't realize is that, in order to create the
>> connection-specific config store, one must first know the connection
>> URL. But serf_connection_create() does not know the connection URL ...
>>
>> ... and the tests didn't break on my dev box, for some reason. Sorry for
>> the noise.
>>
>>
>> Here's what I propose to do:
>>
>>   * Completely deprecate serf_connection_create().
>>     It's useless as it stands now, because it does not set the host_url
>>     and host_info members of the connection struct (hence breaking when
>>     the request attempts to set the Host: header, among other places)
>>     and it does not initialize the config store.
>>
>>   * Create a new function, e.g., serf_connection_create_from_address()
>>     which would be like serf_connection_create() but would also take a
>>     'const char* host_url' parameter with which to initialize the
>>     missing members.
>>
>>
>> The reason why I'd like to have another function besides
>> serf_connectIon_create2() is that the latter blocks on DNS lookup, which
>> is quite unacceptable for my purposes.
>>
>>
>> If anyone has a better idea, I'd love to hear it.
> Another solution would be to create serf_connection_create3 which would
> be like serf_connection_create2 but would take an optional
> apr_sockaddr_t* parameter and only perform the DNS lookup if the address
> wasn't provided.

I went with this solution in rr1769851.

-- Brane


Re: svn commit: r1769841 - in /serf/trunk: serf_private.h src/config_store.c src/outgoing.c test/test_internal.c

Posted by Branko Čibej <br...@apache.org>.
On 15.11.2016 15:41, Branko \u010cibej wrote:
> On 15.11.2016 15:29, brane@apache.org wrote:
>> Author: brane
>> Date: Tue Nov 15 14:29:27 2016
>> New Revision: 1769841
>>
>> URL: http://svn.apache.org/viewvc?rev=1769841&view=rev
>> Log:
>> Revert r1769799 due to a chicken-and-egg problem.
>
> So this was fun.
>
> What I didn't realize is that, in order to create the
> connection-specific config store, one must first know the connection
> URL. But serf_connection_create() does not know the connection URL ...
>
> ... and the tests didn't break on my dev box, for some reason. Sorry for
> the noise.
>
>
> Here's what I propose to do:
>
>   * Completely deprecate serf_connection_create().
>     It's useless as it stands now, because it does not set the host_url
>     and host_info members of the connection struct (hence breaking when
>     the request attempts to set the Host: header, among other places)
>     and it does not initialize the config store.
>
>   * Create a new function, e.g., serf_connection_create_from_address()
>     which would be like serf_connection_create() but would also take a
>     'const char* host_url' parameter with which to initialize the
>     missing members.
>
>
> The reason why I'd like to have another function besides
> serf_connectIon_create2() is that the latter blocks on DNS lookup, which
> is quite unacceptable for my purposes.
>
>
> If anyone has a better idea, I'd love to hear it.

Another solution would be to create serf_connection_create3 which would
be like serf_connection_create2 but would take an optional
apr_sockaddr_t* parameter and only perform the DNS lookup if the address
wasn't provided.

I still think serf_connection_create() should be deprecated and declared
permanently broken.

-- Brane

Re: svn commit: r1769841 - in /serf/trunk: serf_private.h src/config_store.c src/outgoing.c test/test_internal.c

Posted by Branko Čibej <br...@apache.org>.
On 15.11.2016 15:29, brane@apache.org wrote:
> Author: brane
> Date: Tue Nov 15 14:29:27 2016
> New Revision: 1769841
>
> URL: http://svn.apache.org/viewvc?rev=1769841&view=rev
> Log:
> Revert r1769799 due to a chicken-and-egg problem.


So this was fun.

What I didn't realize is that, in order to create the
connection-specific config store, one must first know the connection
URL. But serf_connection_create() does not know the connection URL ...

... and the tests didn't break on my dev box, for some reason. Sorry for
the noise.


Here's what I propose to do:

  * Completely deprecate serf_connection_create().
    It's useless as it stands now, because it does not set the host_url
    and host_info members of the connection struct (hence breaking when
    the request attempts to set the Host: header, among other places)
    and it does not initialize the config store.

  * Create a new function, e.g., serf_connection_create_from_address()
    which would be like serf_connection_create() but would also take a
    'const char* host_url' parameter with which to initialize the
    missing members.


The reason why I'd like to have another function besides
serf_connectIon_create2() is that the latter blocks on DNS lookup, which
is quite unacceptable for my purposes.


If anyone has a better idea, I'd love to hear it.

-- Brane