diff --git a/include/maxscale/listener.hh b/include/maxscale/listener.hh index fec07cfb0..283c3658b 100644 --- a/include/maxscale/listener.hh +++ b/include/maxscale/listener.hh @@ -173,12 +173,6 @@ public: */ void print_users(DCB* dcb); - // TODO: Move dcb_accept code into listener.cc and remove this - int fd() const - { - return m_fd; - } - // Functions that are temporarily public bool create_listener_config(const char* filename); struct users* users() const; @@ -241,9 +235,34 @@ private: const std::string& protocol, const std::string& authenticator, const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl); - // Listen on a file descriptor shared between all workers + /** + * Listen on a file descriptor shared between all workers + * + * @param config_bind The bind configuration consisting of an address and a port separated by the pipe + * character. For UNIX domain sockets, the address is the socket path and the port + * is always zero. + * + * @return True if the listening was started successfully + */ bool listen_shared(std::string config_bind); + /** + * Accept a single client connection + * + * @return The new DCB or nullptr on error + */ + DCB* accept_one_dcb(); + + /** + * The file descriptor for accepting new connections + * + * When SO_REUSEPORT is in use, each worker has a separate file descriptor that they accept on. + */ + int fd() const + { + return m_fd; + } + // Handler for EPOLL_IN events static uint32_t poll_handler(MXB_POLL_DATA* data, MXB_WORKER* worker, uint32_t events); }; diff --git a/server/core/listener.cc b/server/core/listener.cc index ea1e082a5..d3c4e9b20 100644 --- a/server/core/listener.cc +++ b/server/core/listener.cc @@ -852,24 +852,19 @@ static int accept_one_connection(int fd, struct sockaddr* client_conn) return client_fd; } -/** - * @brief Accept a new client connection - * - * @param listener Listener that has a new connection request - * - * @return DCB - The new client DCB for the new connection, or NULL if failed - */ -DCB* accept_one_dcb(const SListener& listener) +} + +DCB* Listener::accept_one_dcb() { DCB* client_dcb = NULL; int c_sock; struct sockaddr_storage client_conn; - if ((c_sock = accept_one_connection(listener->fd(), (struct sockaddr*)&client_conn)) >= 0) + if ((c_sock = accept_one_connection(fd(), (struct sockaddr*)&client_conn)) >= 0) { configure_network_socket(c_sock, client_conn.ss_family); - client_dcb = dcb_alloc(DCB_ROLE_CLIENT_HANDLER, listener, listener->service()); + client_dcb = dcb_alloc(DCB_ROLE_CLIENT_HANDLER, m_self, m_service); if (client_dcb == NULL) { @@ -938,12 +933,11 @@ DCB* accept_one_dcb(const SListener& listener) if (client_dcb) { - mxb::atomic::add(&client_dcb->service->client_count, 1); + mxb::atomic::add(&m_service->client_count, 1); } return client_dcb; } -} bool Listener::listen_shared(std::string config_bind) { @@ -1015,7 +1009,7 @@ uint32_t Listener::poll_handler(MXB_POLL_DATA* data, MXB_WORKER* worker, uint32_ Listener* listener = static_cast(data); DCB* client_dcb; - while ((client_dcb = accept_one_dcb(listener->m_self))) + while ((client_dcb = listener->accept_one_dcb())) { listener->m_proto_func.accept(client_dcb); }