DISPATCH-390: Cleanup unused code in server.c Removed unused code, mark file-local functions static with no qd_ prefix.
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/1ea0219b Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/1ea0219b Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/1ea0219b Branch: refs/heads/master Commit: 1ea0219bcbc5c2761c60fc94e7e387927cfb0418 Parents: 960053d Author: Alan Conway <[email protected]> Authored: Thu Jan 19 12:48:42 2017 -0500 Committer: Alan Conway <[email protected]> Committed: Thu Jan 19 15:32:58 2017 -0500 ---------------------------------------------------------------------- include/qpid/dispatch.h | 1 - include/qpid/dispatch/user_fd.h | 128 ------------------------------ src/server.c | 104 +++---------------------- src/server_private.h | 13 ---- tests/CMakeLists.txt | 1 - tests/run_unit_tests.c | 2 - tests/server_test.c | 146 ----------------------------------- 7 files changed, 10 insertions(+), 385 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/include/qpid/dispatch.h ---------------------------------------------------------------------- diff --git a/include/qpid/dispatch.h b/include/qpid/dispatch.h index 156f831..cab1bea 100644 --- a/include/qpid/dispatch.h +++ b/include/qpid/dispatch.h @@ -53,7 +53,6 @@ #include <qpid/dispatch/compose.h> #include <qpid/dispatch/threading.h> #include <qpid/dispatch/timer.h> -#include <qpid/dispatch/user_fd.h> #include <qpid/dispatch/server.h> #include <qpid/dispatch/message.h> #include <qpid/dispatch/container.h> http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/include/qpid/dispatch/user_fd.h ---------------------------------------------------------------------- diff --git a/include/qpid/dispatch/user_fd.h b/include/qpid/dispatch/user_fd.h deleted file mode 100644 index 56d9124..0000000 --- a/include/qpid/dispatch/user_fd.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef __dispatch_user_fd_h__ -#define __dispatch_user_fd_h__ 1 -/* - * 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 <qpid/dispatch/dispatch.h> -#include <qpid/dispatch/server.h> - -/**@file - * Server User-File-Descriptor functions. - * - * @defgroup user_fd user_fd - * - * Server User-File-Descriptor Functions - * @{ - */ - -typedef struct qd_user_fd_t qd_user_fd_t; - - -/** - * User_fd Handler - * - * Callback invoked when a user-managed file descriptor is available for reading or writing or there - * was an error on the file descriptor. - * - * @param context The handler context supplied in the qd_user_fd call. - * @param ufd The user_fd handle for the processable fd. - */ -typedef void (*qd_user_fd_handler_cb_t)(void* context, qd_user_fd_t *ufd); - - -/** - * Set the user-fd handler callback for the server. This handler is optional, but must be supplied - * if the qd_server is used to manage the activation of user file descriptors. - */ -void qd_server_set_user_fd_handler(qd_dispatch_t *qd, qd_user_fd_handler_cb_t ufd_handler); - - -/** - * Create a tracker for a user-managed file descriptor. - * - * A user-fd is appropriate for use when the application opens and manages file descriptors - * for purposes other than AMQP communication. Registering a user fd with the dispatch server - * controls processing of the FD alongside the FDs used for messaging. - * - * @param qd Pointer to the dispatch instance. - * @param fd The open file descriptor being managed by the application. - * @param context User context passed back in the connection handler. - * @return A pointer to the new user_fd. - */ -qd_user_fd_t *qd_user_fd(qd_dispatch_t *qd, int fd, void *context); - - -/** - * Free the resources for a user-managed FD tracker. - * - * @param ufd Structure pointer returned by qd_user_fd. - */ -void qd_user_fd_free(qd_user_fd_t *ufd); - - -/** - * Activate a user-fd for read. - * - * Use this activation when the application has capacity to receive data from the user-fd. This will - * cause the callback set in qd_server_set_user_fd_handler to later be invoked when the - * file descriptor has data to read. - * - * @param ufd Structure pointer returned by qd_user_fd. - */ -void qd_user_fd_activate_read(qd_user_fd_t *ufd); - - -/** - * Activate a user-fd for write. - * - * Use this activation when the application has data to write via the user-fd. This will - * cause the callback set in qd_server_set_user_fd_handler to later be invoked when the - * file descriptor is writable. - * - * @param ufd Structure pointer returned by qd_user_fd. - */ -void qd_user_fd_activate_write(qd_user_fd_t *ufd); - - -/** - * Check readable status of a user-fd - * - * Note: It is possible that readable status is spurious (i.e. this function returns true - * but the file-descriptor is not readable and will block if not set to O_NONBLOCK). - * Code accordingly. - * - * @param ufd Structure pointer returned by qd_user_fd. - * @return true iff the user file descriptor is readable. - */ -bool qd_user_fd_is_readable(qd_user_fd_t *ufd); - - -/** - * Check writable status of a user-fd - * - * @param ufd Structure pointer returned by qd_user_fd. - * @return true iff the user file descriptor is writable. - */ -bool qd_user_fd_is_writeable(qd_user_fd_t *ufd); - -/** - * @} - */ - -#endif http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/src/server.c ---------------------------------------------------------------------- diff --git a/src/server.c b/src/server.c index 4a937cd..a86500a 100644 --- a/src/server.c +++ b/src/server.c @@ -47,7 +47,6 @@ ALLOC_DEFINE(qd_listener_t); ALLOC_DEFINE(qd_connector_t); ALLOC_DEFINE(qd_deferred_call_t); ALLOC_DEFINE(qd_connection_t); -ALLOC_DEFINE(qd_user_fd_t); const char *QD_CONNECTION_TYPE = "connection"; const char *MECH_EXTERNAL = "EXTERNAL"; @@ -109,12 +108,10 @@ static void free_qd_connection(qd_connection_t *ctx) free_qd_connection_t(ctx); } -qd_error_t qd_entity_update_connection(qd_entity_t* entity, void *impl); - /** * This function is set as the pn_transport->tracer and is invoked when proton tries to write the log message to pn_transport->tracer */ -static void qd_transport_tracer(pn_transport_t *transport, const char *message) +static void transport_tracer(pn_transport_t *transport, const char *message) { qd_connection_t *ctx = (qd_connection_t*) pn_transport_get_context(transport); if (ctx) @@ -143,7 +140,7 @@ qd_error_t qd_register_display_name_service(qd_dispatch_t *qd, void *displayname * Returns a char pointer to a user id which is constructed from components specified in the config->ssl_uid_format. * Parses through each component and builds a semi-colon delimited string which is returned as the user id. */ -static const char *qd_transport_get_user(qd_connection_t *conn, pn_transport_t *tport) +static const char *transport_get_user(qd_connection_t *conn, pn_transport_t *tport) { const qd_server_config_t *config = conn->connector ? conn->connector->config : conn->listener->config; @@ -346,7 +343,7 @@ static const char *qd_transport_get_user(qd_connection_t *conn, pn_transport_t * * Allocate a new qd_connection * with DEQ items initialized, call lock allocated, and all other fields cleared. */ -qd_connection_t *qd_connection_allocate() +static qd_connection_t *connection_allocate() { qd_connection_t *ctx = new_qd_connection_t(); ZERO(ctx); @@ -367,7 +364,7 @@ void qd_connection_set_user(qd_connection_t *conn) conn->user_id = pn_transport_get_user(tport); // We want to set the user name only if it is not already set and the selected sasl mechanism is EXTERNAL if (mech && strcmp(mech, MECH_EXTERNAL) == 0) { - const char *user_id = qd_transport_get_user(conn, tport); + const char *user_id = transport_get_user(conn, tport); if (user_id) conn->user_id = user_id; } @@ -504,7 +501,7 @@ static void thread_process_listeners_LH(qd_server_t *qd_server) char logbuf[qd_log_max_len()]; - ctx = qd_connection_allocate(); + ctx = connection_allocate(); ctx->server = qd_server; ctx->owner_thread = CONTEXT_UNSPECIFIED_OWNER; ctx->pn_cxtr = cxtr; @@ -549,13 +546,13 @@ static void thread_process_listeners_LH(qd_server_t *qd_server) pn_transport_set_idle_timeout(tport, config->idle_timeout_seconds * 1000); // - // Proton pushes out its trace to qd_transport_tracer() which in turn writes a trace message to the qdrouter log + // Proton pushes out its trace to transport_tracer() which in turn writes a trace message to the qdrouter log // If trace level logging is enabled on the router set PN_TRACE_DRV | PN_TRACE_FRM | PN_TRACE_RAW on the proton transport // pn_transport_set_context(tport, ctx); if (qd_log_enabled(qd_server->log_source, QD_LOG_TRACE)) { pn_transport_trace(tport, PN_TRACE_FRM); - pn_transport_set_tracer(tport, qd_transport_tracer); + pn_transport_set_tracer(tport, transport_tracer); } if (li->http) { @@ -661,15 +658,6 @@ static int process_connector(qd_server_t *qd_server, qdpn_connector_t *cxtr) if (ctx->closed) return 0; - // - // If this is a user connection, bypass the AMQP processing and invoke the - // UserFD handler instead. - // - if (ctx->ufd) { - qd_server->ufd_handler(ctx->ufd->context, ctx->ufd); - return 1; - } - do { passes++; @@ -1054,7 +1042,7 @@ static void cxtr_try_open(void *context) if (ct->state != CXTR_STATE_CONNECTING) return; - qd_connection_t *ctx = qd_connection_allocate(); + qd_connection_t *ctx = connection_allocate(); ctx->server = ct->server; ctx->owner_thread = CONTEXT_UNSPECIFIED_OWNER; ctx->pn_conn = pn_connection(); @@ -1127,13 +1115,13 @@ static void cxtr_try_open(void *context) pn_transport_set_idle_timeout(tport, config->idle_timeout_seconds * 1000); // - // Proton pushes out its trace to qd_transport_tracer() which in turn writes a trace message to the qdrouter log + // Proton pushes out its trace to transport_tracer() which in turn writes a trace message to the qdrouter log // // If trace level logging is enabled on the router set PN_TRACE_DRV | PN_TRACE_FRM | PN_TRACE_RAW on the proton transport pn_transport_set_context(tport, ctx); if (qd_log_enabled(ct->server->log_source, QD_LOG_TRACE)) { pn_transport_trace(tport, PN_TRACE_FRM); - pn_transport_set_tracer(tport, qd_transport_tracer); + pn_transport_set_tracer(tport, transport_tracer); } // @@ -1244,7 +1232,6 @@ qd_server_t *qd_server(qd_dispatch_t *qd, int thread_count, const char *containe qd_server->conn_handler = 0; qd_server->pn_event_handler = 0; qd_server->signal_handler = 0; - qd_server->ufd_handler = 0; qd_server->start_context = 0; qd_server->signal_context = 0; qd_server->lock = sys_mutex(); @@ -1319,12 +1306,6 @@ void qd_server_set_start_handler(qd_dispatch_t *qd, qd_thread_start_cb_t handler } -void qd_server_set_user_fd_handler(qd_dispatch_t *qd, qd_user_fd_handler_cb_t ufd_handler) -{ - qd->server->ufd_handler = ufd_handler; -} - - static void qd_server_announce(qd_server_t* qd_server) { qd_log(qd_server->log_source, QD_LOG_INFO, "Operational, %d Threads Running", qd_server->thread_count); @@ -1653,71 +1634,6 @@ void qd_server_connector_free(qd_connector_t* ct) free_qd_connector_t(ct); } - -qd_user_fd_t *qd_user_fd(qd_dispatch_t *qd, int fd, void *context) -{ - qd_server_t *qd_server = qd->server; - qd_user_fd_t *ufd = new_qd_user_fd_t(); - - if (!ufd) - return 0; - - qd_connection_t *ctx = qd_connection_allocate(); - ctx->server = qd_server; - ctx->owner_thread = CONTEXT_NO_OWNER; - ctx->ufd = ufd; - - // Copy the role from the connector config - if (ctx->connector && ctx->connector->config) { - int role_length = strlen(ctx->connector->config->role) + 1; - ctx->role = (char*) malloc(role_length); - strcpy(ctx->role, ctx->connector->config->role); - } - - ufd->context = context; - ufd->server = qd_server; - ufd->fd = fd; - ufd->pn_conn = qdpn_connector_fd(qd_server->driver, fd, (void*) ctx); - qdpn_driver_wakeup(qd_server->driver); - - return ufd; -} - - -void qd_user_fd_free(qd_user_fd_t *ufd) -{ - if (!ufd) return; - qdpn_connector_close(ufd->pn_conn); - free_qd_user_fd_t(ufd); -} - - -void qd_user_fd_activate_read(qd_user_fd_t *ufd) -{ - qdpn_connector_activate(ufd->pn_conn, QDPN_CONNECTOR_READABLE); - qdpn_driver_wakeup(ufd->server->driver); -} - - -void qd_user_fd_activate_write(qd_user_fd_t *ufd) -{ - qdpn_connector_activate(ufd->pn_conn, QDPN_CONNECTOR_WRITABLE); - qdpn_driver_wakeup(ufd->server->driver); -} - - -bool qd_user_fd_is_readable(qd_user_fd_t *ufd) -{ - return qdpn_connector_activated(ufd->pn_conn, QDPN_CONNECTOR_READABLE); -} - - -bool qd_user_fd_is_writeable(qd_user_fd_t *ufd) -{ - return qdpn_connector_activated(ufd->pn_conn, QDPN_CONNECTOR_WRITABLE); -} - - void qd_server_timer_pending_LH(qd_timer_t *timer) { DEQ_INSERT_TAIL(timer->server->pending_timers, timer); http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/src/server_private.h ---------------------------------------------------------------------- diff --git a/src/server_private.h b/src/server_private.h index 28ce2ba..3bec063 100644 --- a/src/server_private.h +++ b/src/server_private.h @@ -21,7 +21,6 @@ #include <qpid/dispatch/enum.h> #include <qpid/dispatch/server.h> -#include <qpid/dispatch/user_fd.h> #include "alloc.h" #include <qpid/dispatch/ctools.h> #include <qpid/dispatch/log.h> @@ -113,7 +112,6 @@ struct qd_connection_t { void *context; // Copy of context from listener or connector void *user_context; void *link_context; // Context shared by this connection's links - qd_user_fd_t *ufd; uint64_t connection_id; // A unique identifier for the qd_connection_t. The underlying pn_connection already has one but it is long and clunky. const char *user_id; // A unique identifier for the user on the connection. This is currently populated from the client ssl cert. See ssl_uid_format in server.h for more info bool free_user_id; @@ -140,15 +138,6 @@ static inline const char* qd_connection_hostip(const qd_connection_t *c) { DEQ_DECLARE(qd_connection_t, qd_connection_list_t); - -struct qd_user_fd_t { - qd_server_t *server; - void *context; - int fd; - qdpn_connector_t *pn_conn; -}; - - typedef struct qd_thread_t { qd_server_t *qd_server; int thread_id; @@ -179,7 +168,6 @@ struct qd_server_t { qd_conn_handler_cb_t conn_handler; qd_pn_event_handler_cb_t pn_event_handler; qd_pn_event_complete_cb_t pn_event_complete_handler; - qd_user_fd_handler_cb_t ufd_handler; void *start_context; void *conn_handler_context; sys_cond_t *cond; @@ -209,7 +197,6 @@ ALLOC_DECLARE(qd_listener_t); ALLOC_DECLARE(qd_deferred_call_t); ALLOC_DECLARE(qd_connector_t); ALLOC_DECLARE(qd_connection_t); -ALLOC_DECLARE(qd_user_fd_t); ALLOC_DECLARE(qd_pn_free_link_session_t); http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/tests/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a1d2520..dc72e85 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,6 @@ set(unit_test_SOURCES compose_test.c policy_test.c run_unit_tests.c - server_test.c timer_test.c tool_test.c ) http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/tests/run_unit_tests.c ---------------------------------------------------------------------- diff --git a/tests/run_unit_tests.c b/tests/run_unit_tests.c index 173fc38..203ee47 100644 --- a/tests/run_unit_tests.c +++ b/tests/run_unit_tests.c @@ -26,7 +26,6 @@ int tool_tests(void); int timer_tests(void); int alloc_tests(void); -int server_tests(qd_dispatch_t *qd); int compose_tests(void); int policy_tests(void); @@ -53,7 +52,6 @@ int main(int argc, char** argv) return 1; } result += timer_tests(); - result += server_tests(qd); result += tool_tests(); result += compose_tests(); #if USE_MEMORY_POOL http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/1ea0219b/tests/server_test.c ---------------------------------------------------------------------- diff --git a/tests/server_test.c b/tests/server_test.c deleted file mode 100755 index 621f039..0000000 --- a/tests/server_test.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -#define _GNU_SOURCE -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <assert.h> -#include "test_case.h" -#include <qpid/dispatch.h> - -#define THREAD_COUNT 4 -#define OCTET_COUNT 100 - -static qd_dispatch_t *qd; -static sys_mutex_t *test_lock; - -static int call_count; -static char stored_error[512]; - -static int write_count; -static int read_count; -static int fd[2]; -static qd_user_fd_t *ufd_write; -static qd_user_fd_t *ufd_read; - - -static void ufd_handler(void *context, qd_user_fd_t *ufd) -{ - long dir = (long) context; - char buffer; - ssize_t len; - static int in_read = 0; - static int in_write = 0; - - if (dir == 0) { // READ - in_read++; - assert(in_read == 1); - len = read(fd[0], &buffer, 1); - if (len < 0) { - sprintf(stored_error, "Error while reading"); - qd_server_stop(qd); - } else if (len == 1) { - read_count++; - if (read_count == OCTET_COUNT) - qd_server_stop(qd); - } - qd_user_fd_activate_read(ufd_read); - in_read--; - } else { // WRITE - in_write++; - assert(in_write == 1); - if (!qd_user_fd_is_writeable(ufd_write)) { - sprintf(stored_error, "Expected Writable"); - qd_server_stop(qd); - } else { - if (write(fd[1], "X", 1) < 0) abort(); - - write_count++; - if (write_count < OCTET_COUNT) - qd_user_fd_activate_write(ufd_write); - } - in_write--; - } -} - - -static void fd_test_start(void *context, int unused) -{ - if (++call_count == THREAD_COUNT) { - qd_user_fd_activate_read(ufd_read); - } -} - - -static char* test_user_fd(void *context) -{ - int res; - - call_count = 0; - qd_server_set_start_handler(qd, fd_test_start, 0); - qd_server_set_user_fd_handler(qd, ufd_handler); - - stored_error[0] = 0x0; - - res = pipe(fd); // Don't use pipe2 because it's not available on RHEL5 - if (res != 0) return "Error creating pipe2"; - - for (int i = 0; i < 2; i++) { - int flags = fcntl(fd[i], F_GETFL); - flags |= O_NONBLOCK; - if (fcntl(fd[i], F_SETFL, flags) < 0) { - perror("fcntl"); - return "Failed to set socket to non-blocking"; - } - } - - ufd_write = qd_user_fd(qd, fd[1], (void*) 1); - ufd_read = qd_user_fd(qd, fd[0], (void*) 0); - - qd_server_run(qd); - close(fd[0]); - close(fd[1]); - - qd_user_fd_free(ufd_read); - qd_user_fd_free(ufd_write); - - if (stored_error[0]) return stored_error; - if (write_count - OCTET_COUNT > 2) sprintf(stored_error, "Excessively high Write Count: %d", write_count); - if (read_count != OCTET_COUNT) sprintf(stored_error, "Incorrect Read Count: %d", read_count);; - - if (stored_error[0]) return stored_error; - return 0; -} - - -int server_tests(qd_dispatch_t *_qd) -{ - int result = 0; - test_lock = sys_mutex(); - - qd = _qd; - - TEST_CASE(test_user_fd, 0); - - sys_mutex_free(test_lock); - return result; -} - --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
