Author: brane Date: Tue Nov 15 16:04:24 2016 New Revision: 1769851 URL: http://svn.apache.org/viewvc?rev=1769851&view=rev Log: Introduce serf_connection_create3, which improves on serf_connection_create2 by optionally avoiding blocking hostname lookups.
* serf.h (serf_connection_create2): Reduce docstring to a reference to the documentation for serf_connection_create3. (serf_connection_create3): New. Like serf_connection_create2 but accepts an optional pre-cooked apr_sockaddr_t*. (serf_request_bucket_request_create): Update docstring. * src/outgoing.c (serf_connection_create3): Rename from serf_connection_create2 and update implementation to match new prototype and semantics. (serf_connection_create2): Reimplement in terms of serf_connection_create3. Modified: serf/trunk/serf.h serf/trunk/src/outgoing.c Modified: serf/trunk/serf.h URL: http://svn.apache.org/viewvc/serf/trunk/serf.h?rev=1769851&r1=1769850&r2=1769851&view=diff ============================================================================== --- serf/trunk/serf.h (original) +++ serf/trunk/serf.h Tue Nov 15 16:04:24 2016 @@ -472,11 +472,30 @@ serf_connection_t *serf_connection_creat /** * Create a new connection associated with the @a ctx serf context. * + * Like @see serf_connection_create3 but with @a host_address set to @c NULL. + */ +apr_status_t serf_connection_create2( + serf_connection_t **conn, + serf_context_t *ctx, + apr_uri_t host_info, + serf_connection_setup_t setup, + void *setup_baton, + serf_connection_closed_t closed, + void *closed_baton, + apr_pool_t *pool); + + +/** + * Create a new connection associated with the @a ctx serf context. + * * A connection will be created to (eventually) connect to the address * specified by @a address. The address must live at least as long as * @a pool (thus, as long as the connection object). * - * The host address will be looked up based on the hostname in @a host_info. + * If @a host_address is @c NULL, the host address will be looked up + * based on the hostname in @a host_info; otherwise @a host_address + * will be used to connect and @a host_info will only be used for + * setting request headers. * * The connection object will be allocated within @a pool. Clearing or * destroying this pool will close the connection, and terminate any @@ -489,13 +508,14 @@ serf_connection_t *serf_connection_creat * NULL may be passed for @a acceptor and @a closed; default implementations * will be used. * - * Note: the connection is not made immediately. It will be opened on + * @note the connection is not made immediately. It will be opened on * the next call to @see serf_context_run. */ -apr_status_t serf_connection_create2( +apr_status_t serf_connection_create3( serf_connection_t **conn, serf_context_t *ctx, apr_uri_t host_info, + apr_sockaddr_t *host_address, serf_connection_setup_t setup, void *setup_baton, serf_connection_closed_t closed, @@ -886,7 +906,8 @@ serf_bucket_t *serf_context_bucket_socke * settings. * * This function will set following header(s): - * - Host: if the connection was created with @a serf_connection_create2. + * - Host: if the connection was created with @see serf_connection_create2 + * or @see serf_connection_create3 */ serf_bucket_t *serf_request_bucket_request_create( serf_request_t *request, Modified: serf/trunk/src/outgoing.c URL: http://svn.apache.org/viewvc/serf/trunk/src/outgoing.c?rev=1769851&r1=1769850&r2=1769851&view=diff ============================================================================== --- serf/trunk/src/outgoing.c (original) +++ serf/trunk/src/outgoing.c Tue Nov 15 16:04:24 2016 @@ -1288,10 +1288,27 @@ apr_status_t serf_connection_create2( void *closed_baton, apr_pool_t *pool) { + return serf_connection_create3(conn, ctx, host_info, NULL, + setup, setup_baton, + closed, closed_baton, + pool); +} + + +apr_status_t serf_connection_create3( + serf_connection_t **conn, + serf_context_t *ctx, + apr_uri_t host_info, + apr_sockaddr_t *host_address, + serf_connection_setup_t setup, + void *setup_baton, + serf_connection_closed_t closed, + void *closed_baton, + apr_pool_t *pool) +{ apr_status_t status = APR_SUCCESS; serf_config_t *config; serf_connection_t *c; - apr_sockaddr_t *host_address = NULL; /* Set the port number explicitly, needed to create the socket later. */ if (!host_info.port) { @@ -1301,11 +1318,15 @@ apr_status_t serf_connection_create2( /* Only lookup the address of the server if no proxy server was configured. */ if (!ctx->proxy_address) { - status = apr_sockaddr_info_get(&host_address, - host_info.hostname, - APR_UNSPEC, host_info.port, 0, pool); - if (status) - return status; + if (!host_address) { + status = apr_sockaddr_info_get(&host_address, + host_info.hostname, + APR_UNSPEC, host_info.port, 0, pool); + if (status) + return status; + } + } else { + host_address = NULL; } c = serf_connection_create(ctx, host_address, setup, setup_baton,