Author: rhuijben Date: Mon Nov 23 14:00:01 2015 New Revision: 1715823 URL: http://svn.apache.org/viewvc?rev=1715823&view=rev Log: Explicitly setup the connection buckets, instead of relying on the read or write code to do it in time. Resolve an error code leak.
* outgoing.c (do_conn_setup): Rename to... (serf_connection__perform_setup): ... this. (prepare_conn_streams): Remove. Folded into only remaining caller. (connect_connection): Call serf_connection__perform_setup directly. (write_to_connection, read_from_connection): Just assume connection streams exist when connected. * serf_private.h (serf_connection__perform_setup): New function. * ssltunnel.c (handle_response): Explicitly setup connection over tunnel. Modified: serf/trunk/outgoing.c serf/trunk/serf_private.h serf/trunk/ssltunnel.c Modified: serf/trunk/outgoing.c URL: http://svn.apache.org/viewvc/serf/trunk/outgoing.c?rev=1715823&r1=1715822&r2=1715823&view=diff ============================================================================== --- serf/trunk/outgoing.c (original) +++ serf/trunk/outgoing.c Mon Nov 23 14:00:01 2015 @@ -250,7 +250,7 @@ void serf__connection_pre_cleanup(serf_c conn->done_reqs = conn->done_reqs_tail = NULL; } -static apr_status_t do_conn_setup(serf_connection_t *conn) +apr_status_t serf_connection__perform_setup(serf_connection_t *conn) { apr_status_t status; serf_bucket_t *ostream, *stream; @@ -298,36 +298,6 @@ static apr_status_t do_conn_setup(serf_c return status; } -/* Set up the input and output stream buckets. - When a tunnel over an http proxy is needed, create a socket bucket and - empty aggregate bucket for sending and receiving unencrypted requests - over the socket. - - After the tunnel is there, or no tunnel was needed, ask the application - to create the input and output buckets, which should take care of the - [en/de]cryption. - */ - -static apr_status_t prepare_conn_streams(serf_connection_t *conn) -{ - apr_status_t status; - - /* Do we need a SSL tunnel first? */ - if (conn->state == SERF_CONN_CONNECTED) { - /* If the connection does not have an associated bucket, then - * call the setup callback to get one. - */ - if (conn->pump.stream == NULL) { - status = do_conn_setup(conn); - if (status) { - return status; - } - } - } - - return APR_SUCCESS; -} - static apr_status_t connect_connection(serf_connection_t *conn) { serf_context_t *ctx = conn->ctx; @@ -357,7 +327,11 @@ static apr_status_t connect_connection(s serf__ssltunnel_connect(conn); else { conn->state = SERF_CONN_CONNECTED; - status = do_conn_setup(conn); + + status = serf_connection__perform_setup(conn); + + if (status) + return status; } return APR_SUCCESS; @@ -751,11 +725,6 @@ static apr_status_t write_to_connection( return APR_SUCCESS; } - status = prepare_conn_streams(conn); - if (status) { - return status; - } - if (request && request->writing == SERF_WRITING_NONE) { serf_bucket_t *event_bucket; @@ -850,12 +819,6 @@ static apr_status_t read_from_connection while (1) { apr_pool_clear(tmppool); - /* Only interested in the input stream here. */ - status = prepare_conn_streams(conn); - if (status) { - goto error; - } - /* We have a different codepath when we can have async responses. */ if (conn->async_responses) { /* TODO What about socket errors? */ Modified: serf/trunk/serf_private.h URL: http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1715823&r1=1715822&r2=1715823&view=diff ============================================================================== --- serf/trunk/serf_private.h (original) +++ serf/trunk/serf_private.h Mon Nov 23 14:00:01 2015 @@ -693,10 +693,13 @@ apr_status_t serf__provide_credentials(s /* Requeue a request (at the front). */ serf_request_t *serf__request_requeue(const serf_request_t *request); +apr_status_t serf_connection__perform_setup(serf_connection_t *conn); + /* from ssltunnel.c */ apr_status_t serf__ssltunnel_connect(serf_connection_t *conn); + /* Creates a bucket that logs all data returned by one of the read functions of the wrapped bucket. The new bucket will replace the wrapped bucket, so the wrapped ptr will be invalid when this function returns. */ Modified: serf/trunk/ssltunnel.c URL: http://svn.apache.org/viewvc/serf/trunk/ssltunnel.c?rev=1715823&r1=1715822&r2=1715823&view=diff ============================================================================== --- serf/trunk/ssltunnel.c (original) +++ serf/trunk/ssltunnel.c Mon Nov 23 14:00:01 2015 @@ -144,6 +144,11 @@ static apr_status_t handle_response(serf serf__bucket_headers_remove(hdrs, "Connection"); } + status = serf_connection__perform_setup(conn); + + if (status) + return SERF_BUCKET_READ_ERROR(status) ? status : APR_EGENERAL; + return APR_EOF; }