From a6063b5e858b18f9c7bbcb89ad919a323951a9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 30 Nov 2018 11:32:05 +0200 Subject: [PATCH] MXS-2196: Remove listen entry point from protocol The entry point was useless as all of the modules called the same function. --- include/maxscale/dcb.h | 2 +- include/maxscale/protocol.h | 10 ------- server/core/config.cc | 13 ++++++++-- server/core/dcb.cc | 9 +++---- server/core/listener.cc | 7 +++-- server/modules/protocol/CDC/cdc.cc | 13 ---------- server/modules/protocol/HTTPD/httpd.cc | 13 ---------- .../MySQL/mariadbbackend/mysql_backend.cc | 1 - .../MySQL/mariadbclient/mysql_client.cc | 21 --------------- .../modules/protocol/maxscaled/maxscaled.cc | 26 ------------------- server/modules/protocol/telnetd/telnetd.cc | 13 ---------- 11 files changed, 21 insertions(+), 107 deletions(-) diff --git a/include/maxscale/dcb.h b/include/maxscale/dcb.h index f007d9f91..6518b793f 100644 --- a/include/maxscale/dcb.h +++ b/include/maxscale/dcb.h @@ -301,7 +301,7 @@ uint64_t dcb_get_session_id(DCB* dcb); char* dcb_role_name(DCB*); /* Return the name of a role */ int dcb_accept_SSL(DCB* dcb); int dcb_connect_SSL(DCB* dcb); -int dcb_listen(DCB* listener, const char* config, const char* protocol_name); +int dcb_listen(DCB* listener, const char* config); void dcb_enable_session_timeouts(); void dcb_process_idle_sessions(int thr); diff --git a/include/maxscale/protocol.h b/include/maxscale/protocol.h index d3ad62b60..98f4c98aa 100644 --- a/include/maxscale/protocol.h +++ b/include/maxscale/protocol.h @@ -118,16 +118,6 @@ typedef struct mxs_protocol */ int32_t (* close)(struct dcb* dcb); - /** - * Listen on a network socket, only for client side protocol modules - * - * @param dcb DCB to listen with - * @param address Address to listen on in `address|port` format - * - * @return 1 on success, 0 on error - */ - int32_t (* listen)(struct dcb* dcb, char* address); - /** * Perform user re-authentication * diff --git a/server/core/config.cc b/server/core/config.cc index d92f9ea37..5cbae0922 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -3831,8 +3832,8 @@ int create_new_listener(CONFIG_CONTEXT* obj) int error_count = 0; - char* port = config_get_value(obj->parameters, CN_PORT); - char* socket = config_get_value(obj->parameters, CN_SOCKET); + const char* port = config_get_value(obj->parameters, CN_PORT); + const char* socket = config_get_value(obj->parameters, CN_SOCKET); if (socket && port) { @@ -3854,6 +3855,14 @@ int create_new_listener(CONFIG_CONTEXT* obj) Service* service = static_cast(config_get_service(obj->parameters, CN_SERVICE)); mxb_assert(service); + // Remove this once maxadmin is removed + if (strcasecmp(protocol, "maxscaled") == 0 && socket + && strcmp(socket, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG) == 0) + { + socket = MAXADMIN_DEFAULT_SOCKET; + address = ""; + } + if (auto l = service_find_listener(service, socket, address, socket ? 0 : atoi(port))) { MXS_ERROR("Creation of listener '%s' for service '%s' failed, because " diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 2c270b1ff..fe6dfc539 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -2606,10 +2606,10 @@ static int dcb_accept_one_connection(DCB* dcb, struct sockaddr* client_conn) * * @param dcb Listener DCB that is being created * @param config Configuration for port to listen on - * @param protocol_name Name of protocol that is listening + * * @return 0 if new listener created successfully, otherwise -1 */ -int dcb_listen(DCB* dcb, const char* config, const char* protocol_name) +int dcb_listen(DCB* dcb, const char* config) { char host[strlen(config) + 1]; strcpy(host, config); @@ -2667,17 +2667,16 @@ int dcb_listen(DCB* dcb, const char* config, const char* protocol_name) */ if (listen(listener_socket, INT_MAX) != 0) { - MXS_ERROR("Failed to start listening on [%s]:%u with protocol '%s': %d, %s", + MXS_ERROR("Failed to start listening on [%s]:%u: %d, %s", host, port, - protocol_name, errno, mxs_strerror(errno)); close(listener_socket); return -1; } - MXS_NOTICE("Listening for connections at [%s]:%u with protocol %s", host, port, protocol_name); + MXS_NOTICE("Listening for connections at [%s]:%u", host, port); // assign listener_socket to dcb dcb->fd = listener_socket; diff --git a/server/core/listener.cc b/server/core/listener.cc index 440237718..80c7c3185 100644 --- a/server/core/listener.cc +++ b/server/core/listener.cc @@ -796,13 +796,16 @@ bool Listener::listen() } } - if (m_listener->func.listen(m_listener, &config_bind[0])) + bool rval = false; + + if (dcb_listen(m_listener, config_bind.data()) == 0) { m_listener->session = session_alloc(m_service, m_listener); if (m_listener->session != NULL) { m_listener->session->state = SESSION_STATE_LISTENER; + rval = true; } else { @@ -814,5 +817,5 @@ bool Listener::listen() MXS_ERROR("[%s] Failed to listen on %s", m_service->name, config_bind.c_str()); } - return true; + return rval; } diff --git a/server/modules/protocol/CDC/cdc.cc b/server/modules/protocol/CDC/cdc.cc index c1f47e13b..fe03336b1 100644 --- a/server/modules/protocol/CDC/cdc.cc +++ b/server/modules/protocol/CDC/cdc.cc @@ -50,7 +50,6 @@ static int cdc_error(DCB* dcb); static int cdc_hangup(DCB* dcb); static int cdc_accept(DCB* dcb); static int cdc_close(DCB* dcb); -static int cdc_listen(DCB* dcb, char* config); static CDC_protocol* cdc_protocol_init(DCB* dcb); static void cdc_protocol_done(DCB* dcb); static int do_auth(DCB* dcb, GWBUF* buffer, void* data); @@ -84,7 +83,6 @@ extern "C" cdc_accept, /* Accept */ NULL, /* Connect */ cdc_close, /* Close */ - cdc_listen, /* Create a listener */ NULL, /* Authentication */ cdc_default_auth, /* default authentication */ NULL, @@ -359,17 +357,6 @@ static int cdc_close(DCB* dcb) return 1; } -/** - * CDC protocol listener entry point - * - * @param listener The Listener DCB - * @param config Configuration (ip:port) - */ -static int cdc_listen(DCB* listener, char* config) -{ - return (dcb_listen(listener, config, "CDC") < 0) ? 0 : 1; -} - /** * Allocate a new CDC protocol structure * diff --git a/server/modules/protocol/HTTPD/httpd.cc b/server/modules/protocol/HTTPD/httpd.cc index 0e2b1a1bc..4778c1b74 100644 --- a/server/modules/protocol/HTTPD/httpd.cc +++ b/server/modules/protocol/HTTPD/httpd.cc @@ -52,7 +52,6 @@ static int httpd_error(DCB* dcb); static int httpd_hangup(DCB* dcb); static int httpd_accept(DCB* dcb); static int httpd_close(DCB* dcb); -static int httpd_listen(DCB* dcb, char* config); static int httpd_get_line(int sock, char* buf, int size); static void httpd_send_headers(DCB* dcb, int final, bool auth_ok); static char* httpd_default_auth(); @@ -79,7 +78,6 @@ extern "C" httpd_accept, /**< Accept */ NULL, /**< Connect */ httpd_close, /**< Close */ - httpd_listen, /**< Create a listener */ NULL, /**< Authentication */ httpd_default_auth, /**< Default authenticator */ NULL, /**< Connection limit reached */ @@ -401,17 +399,6 @@ static int httpd_close(DCB* dcb) return 0; } -/** - * HTTTP daemon listener entry point - * - * @param listener The Listener DCB - * @param config Configuration (ip:port) - */ -static int httpd_listen(DCB* listener, char* config) -{ - return (dcb_listen(listener, config, "HTTPD") < 0) ? 0 : 1; -} - /** * HTTPD get line from client */ diff --git a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc index cccb1e376..e65475fd7 100644 --- a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc +++ b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc @@ -84,7 +84,6 @@ extern "C" NULL, /* Accept */ gw_create_backend_connection, /* Connect */ gw_backend_close, /* Close */ - NULL, /* Listen */ gw_change_user, /* Authentication */ gw_backend_default_auth, /* Default authenticator */ NULL, /* Connection limit reached */ diff --git a/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc b/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc index 746396e49..90d2a6c92 100644 --- a/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc +++ b/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc @@ -59,7 +59,6 @@ static int thread_init(void); static void thread_finish(void); static int gw_MySQLAccept(DCB* listener); -static int gw_MySQLListener(DCB* listener, char* config_bind); static int gw_read_client_event(DCB* dcb); static int gw_write_client_event(DCB* dcb); static int gw_MySQLWrite_client(DCB* dcb, GWBUF* queue); @@ -107,7 +106,6 @@ extern "C" gw_MySQLAccept, /* Accept */ NULL, /* Connect */ gw_client_close, /* Close */ - gw_MySQLListener, /* Listen */ NULL, /* Authentication */ gw_default_auth, /* Default authenticator */ gw_connection_limit, /* Send error connection limit */ @@ -1384,25 +1382,6 @@ return_1: return 1; } -/** - * Bind the DCB to a network port or a UNIX Domain Socket. - * @param listen_dcb Listener DCB - * @param config_bind Bind address in either IP:PORT format for network sockets or PATH - * for UNIX Domain Sockets - * @return 1 on success, 0 on error - */ -int gw_MySQLListener(DCB* listen_dcb, char* config_bind) -{ - if (dcb_listen(listen_dcb, config_bind, "MySQL") < 0) - { - return 0; - } - listen_dcb->func.accept = gw_MySQLAccept; - - return 1; -} - - /** * @node Accept a new connection, using the DCB code for the basic work * diff --git a/server/modules/protocol/maxscaled/maxscaled.cc b/server/modules/protocol/maxscaled/maxscaled.cc index 19bef8022..a2bf73d5e 100644 --- a/server/modules/protocol/maxscaled/maxscaled.cc +++ b/server/modules/protocol/maxscaled/maxscaled.cc @@ -63,7 +63,6 @@ static int maxscaled_error(DCB* dcb); static int maxscaled_hangup(DCB* dcb); static int maxscaled_accept(DCB* dcb); static int maxscaled_close(DCB* dcb); -static int maxscaled_listen(DCB* dcb, char* config); static char* mxsd_default_auth(); static bool authenticate_unix_socket(MAXSCALED* protocol, DCB* dcb) @@ -181,7 +180,6 @@ extern "C" maxscaled_accept, /**< Accept */ NULL, /**< Connect */ maxscaled_close, /**< Close */ - maxscaled_listen, /**< Create a listener */ NULL, /**< Authentication */ mxsd_default_auth, /**< Default authenticator */ NULL, /**< Connection limit reached */ @@ -417,27 +415,3 @@ static int maxscaled_close(DCB* dcb) return 0; } - -/** - * Maxscale daemon listener entry point - * - * @param listener The Listener DCB - * @param config Configuration (ip:port) - * @return 0 on failure, 1 on success - */ -static int maxscaled_listen(DCB* listener, char* config) -{ - const char* socket_path = NULL; - - /* check for default UNIX socket */ - if (strncmp(config, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG, MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG_LEN) == 0) - { - socket_path = MAXADMIN_DEFAULT_SOCKET; - } - else - { - socket_path = config; - } - - return (dcb_listen(listener, socket_path, "MaxScale Admin") < 0) ? 0 : 1; -} diff --git a/server/modules/protocol/telnetd/telnetd.cc b/server/modules/protocol/telnetd/telnetd.cc index dc41e5368..6b4f73a1f 100644 --- a/server/modules/protocol/telnetd/telnetd.cc +++ b/server/modules/protocol/telnetd/telnetd.cc @@ -65,7 +65,6 @@ static int telnetd_error(DCB* dcb); static int telnetd_hangup(DCB* dcb); static int telnetd_accept(DCB* dcb); static int telnetd_close(DCB* dcb); -static int telnetd_listen(DCB* dcb, char* config); static char* telnetd_default_auth(); /** @@ -100,7 +99,6 @@ extern "C" telnetd_accept, /**< Accept */ NULL, /**< Connect */ telnetd_close, /**< Close */ - telnetd_listen, /**< Create a listener */ NULL, /**< Authentication */ telnetd_default_auth, /**< Default authenticator */ NULL, /**< Connection limit reached */ @@ -330,17 +328,6 @@ static int telnetd_close(DCB* dcb) return 0; } -/** - * Telnet daemon listener entry point - * - * @param listener The Listener DCB - * @param config Configuration (ip:port) - */ -static int telnetd_listen(DCB* listener, char* config) -{ - return (dcb_listen(listener, config, "telnet") < 0) ? 0 : 1; -} - /** * Telnet command implementation *