Author: rhuijben Date: Sun Oct 18 12:40:25 2015 New Revision: 1709274 URL: http://svn.apache.org/viewvc?rev=1709274&view=rev Log: Following up on r1709265, add a protocol baton and a teardown function to the connection to allow hooking up the http2 protocol handlers.
* serf-dev/dev/outgoing.c (reset_connection): Teardown protocol state. (serf_connection_create): Init protocol state vars. (serf_connection_close): Teardown protocol state. (serf_connection_set_framing_type): Tear down existing protocol. Setup http2. Remove unneeded call to serf__conn_update_pollset() which is already handled by the dirty flags. * serf-dev/dev/protocols/http2_protocol.c (*): New file in new directory. * serf-dev/dev/SConstruct (SOURCES): Build files in protocols subdirectory. * serf-dev/dev/serf_private.h (serf_connection_t): Add missing whitespace. Add baton and teardown. (serf__http2_protocol_init): New function. Added: serf/trunk/protocols/ serf/trunk/protocols/http2_protocol.c (with props) Modified: serf/trunk/SConstruct serf/trunk/outgoing.c serf/trunk/serf_private.h Modified: serf/trunk/SConstruct URL: http://svn.apache.org/viewvc/serf/trunk/SConstruct?rev=1709274&r1=1709273&r2=1709274&view=diff ============================================================================== --- serf/trunk/SConstruct (original) +++ serf/trunk/SConstruct Sun Oct 18 12:40:25 2015 @@ -295,7 +295,8 @@ if sys.platform == 'win32': dll_res = env.RES(['serf.rc']) SHARED_SOURCES.append(dll_res) -SOURCES = Glob('*.c') + Glob('buckets/*.c') + Glob('auth/*.c') +SOURCES = Glob('*.c') + Glob('buckets/*.c') + Glob('auth/*.c') + \ + Glob('protocols/*.c') lib_static = env.StaticLibrary(LIBNAMESTATIC, SOURCES) lib_shared = env.SharedLibrary(LIBNAME, SOURCES + SHARED_SOURCES) Modified: serf/trunk/outgoing.c URL: http://svn.apache.org/viewvc/serf/trunk/outgoing.c?rev=1709274&r1=1709273&r2=1709274&view=diff ============================================================================== --- serf/trunk/outgoing.c (original) +++ serf/trunk/outgoing.c Sun Oct 18 12:40:25 2015 @@ -731,9 +731,16 @@ static apr_status_t reset_connection(ser /* conn->pipelining */ conn->framing_type = SERF_CONNECTION_FRAMING_TYPE_HTTP1; + + if (conn->protocol_baton) { + conn->perform_teardown(conn); + conn->protocol_baton = NULL; + } + conn->perform_read = read_from_connection; conn->perform_write = write_to_connection; conn->perform_hangup = hangup_connection; + conn->perform_teardown = NULL; conn->status = APR_SUCCESS; @@ -1589,6 +1596,8 @@ serf_connection_t *serf_connection_creat conn->perform_read = read_from_connection; conn->perform_write = write_to_connection; conn->perform_hangup = hangup_connection; + conn->perform_teardown = NULL; + conn->protocol_baton = NULL; /* Create a subpool for our connection. */ apr_pool_create(&conn->skt_pool, conn->pool); @@ -1706,6 +1715,11 @@ apr_status_t serf_connection_close( destroy_ostream(conn); + if (conn->protocol_baton) { + conn->perform_teardown(conn); + conn->protocol_baton = NULL; + } + /* Remove the connection from the context. We don't want to * deal with it any more. */ @@ -1783,7 +1797,26 @@ void serf_connection_set_framing_type( conn->ctx->dirty_pollset = 1; conn->stop_writing = 0; conn->write_now = 1; - serf__conn_update_pollset(conn); + + /* Close down existing protocol */ + if (conn->protocol_baton) { + conn->perform_teardown(conn); + conn->protocol_baton = NULL; + } + + /* Reset to default */ + conn->perform_read = read_from_connection; + conn->perform_write = write_to_connection; + conn->perform_hangup = hangup_connection; + conn->perform_teardown = NULL; + + switch (framing_type) { + case SERF_CONNECTION_FRAMING_TYPE_HTTP2: + serf__http2_protocol_init(conn); + break; + default: + break; + } } } Added: serf/trunk/protocols/http2_protocol.c URL: http://svn.apache.org/viewvc/serf/trunk/protocols/http2_protocol.c?rev=1709274&view=auto ============================================================================== --- serf/trunk/protocols/http2_protocol.c (added) +++ serf/trunk/protocols/http2_protocol.c Sun Oct 18 12:40:25 2015 @@ -0,0 +1,111 @@ +/* ==================================================================== +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* ==================================================================== +*/ + +#include <apr_pools.h> +#include <apr_poll.h> +#include <apr_version.h> +#include <apr_portable.h> +#include <apr_strings.h> + +#include "serf.h" +#include "serf_bucket_util.h" + +#include "serf_private.h" + +static apr_status_t +http2_protocol_read(serf_connection_t *conn); + +static apr_status_t +http2_protocol_write(serf_connection_t *conn); + +static apr_status_t +http2_protocol_hangup(serf_connection_t *conn); + +static void +http2_protocol_teardown(serf_connection_t *conn); + +typedef struct serf_http2_procotol_state_t +{ + apr_pool_t *pool; + +} serf_http2_procotol_state_t; + +static apr_status_t +http2_protocol_cleanup(void *state) +{ + serf_connection_t *conn = state; + /* serf_http2_procotol_state_t *ctx = conn->protocol_baton; */ + + conn->protocol_baton = NULL; + return APR_SUCCESS; +} + +void serf__http2_protocol_init(serf_connection_t *conn) +{ + serf_http2_procotol_state_t *ctx; + apr_pool_t *protocol_pool; + + apr_pool_create(&protocol_pool, conn->pool); + + ctx = apr_pcalloc(protocol_pool, sizeof(*ctx)); + ctx->pool = protocol_pool; + + apr_pool_cleanup_register(protocol_pool, conn, http2_protocol_cleanup, + apr_pool_cleanup_null); + + conn->perform_read = http2_protocol_read; + conn->perform_write = http2_protocol_write; + conn->perform_hangup = http2_protocol_hangup; + conn->perform_teardown = http2_protocol_teardown; + conn->protocol_baton = ctx; +} + +static apr_status_t +http2_protocol_read(serf_connection_t *conn) +{ + /* serf_http2_procotol_state_t *ctx = conn->protocol_baton; */ + + return APR_EGENERAL; +} + +static apr_status_t +http2_protocol_write(serf_connection_t *conn) +{ + /* serf_http2_procotol_state_t *ctx = conn->protocol_baton; */ + + return APR_EGENERAL; +} + +static apr_status_t +http2_protocol_hangup(serf_connection_t *conn) +{ + /* serf_http2_procotol_state_t *ctx = conn->protocol_baton; */ + + return APR_EGENERAL; +} + +static void +http2_protocol_teardown(serf_connection_t *conn) +{ + serf_http2_procotol_state_t *ctx = conn->protocol_baton; + + apr_pool_destroy(ctx->pool); + conn->protocol_baton = NULL; +} Propchange: serf/trunk/protocols/http2_protocol.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: serf/trunk/serf_private.h URL: http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1709274&r1=1709273&r2=1709274&view=diff ============================================================================== --- serf/trunk/serf_private.h (original) +++ serf/trunk/serf_private.h Sun Oct 18 12:40:25 2015 @@ -410,9 +410,13 @@ struct serf_connection_t { /* Event callbacks, called from serf__process_connection() to do the actual processing. */ - apr_status_t(*perform_read)(serf_connection_t *conn); - apr_status_t(*perform_write)(serf_connection_t *conn); - apr_status_t(*perform_hangup)(serf_connection_t *conn); + apr_status_t (*perform_read)(serf_connection_t *conn); + apr_status_t (*perform_write)(serf_connection_t *conn); + apr_status_t (*perform_hangup)(serf_connection_t *conn); + + /* Cleanup of protocol handling */ + void (*perform_teardown)(serf_connection_t *conn); + void *protocol_baton; /* Configuration shared with buckets and authn plugins */ serf_config_t *config; @@ -515,6 +519,9 @@ serf_bucket_t *serf__bucket_log_wrapper_ const char *prefix, serf_bucket_alloc_t *allocator); +/* From http2_protocol.c: Initializes http2 state on connection */ +void serf__http2_protocol_init(serf_connection_t *conn); + /** Logging functions. **/ /* Initialize the logging subsystem. This will store a log baton in the