MXS-2196: Store listeners in a global list
The listeners are now stored in their own list which allows them to be a component separate from the service. The next step is to remove the listener iterator functionality and replace it with its STL counterpart.
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <maxbase/jansson.h>
|
#include <maxbase/jansson.h>
|
||||||
#include <maxscale/protocol.h>
|
#include <maxscale/protocol.h>
|
||||||
@ -33,26 +34,28 @@ class SERV_LISTENER
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SERV_LISTENER(SERVICE* service, const std::string& name, const std::string& address, uint16_t port,
|
SERV_LISTENER(SERVICE* service, const std::string& name, const std::string& address, uint16_t port,
|
||||||
const std::string& protocol, const std::string& authenticator,
|
const std::string& protocol, const std::string& authenticator,
|
||||||
const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl);
|
const std::string& auth_opts, void* auth_instance, SSL_LISTENER* ssl);
|
||||||
~SERV_LISTENER();
|
~SERV_LISTENER();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string name; /**< Name of the listener */
|
std::string name; /**< Name of the listener */
|
||||||
std::string protocol; /**< Protocol module to load */
|
std::string protocol; /**< Protocol module to load */
|
||||||
uint16_t port; /**< Port to listen on */
|
uint16_t port; /**< Port to listen on */
|
||||||
std::string address; /**< Address to listen with */
|
std::string address; /**< Address to listen with */
|
||||||
std::string authenticator;/**< Name of authenticator */
|
std::string authenticator; /**< Name of authenticator */
|
||||||
std::string auth_options; /**< Authenticator options */
|
std::string auth_options; /**< Authenticator options */
|
||||||
void* auth_instance;/**< Authenticator instance */
|
void* auth_instance; /**< Authenticator instance */
|
||||||
SSL_LISTENER* ssl; /**< Structure of SSL data or NULL */
|
SSL_LISTENER* ssl; /**< Structure of SSL data or NULL */
|
||||||
struct dcb* listener; /**< The DCB for the listener */
|
struct dcb* listener; /**< The DCB for the listener */
|
||||||
struct users* users; /**< The user data for this listener */
|
struct users* users; /**< The user data for this listener */
|
||||||
SERVICE* service; /**< The service which used by this listener */
|
SERVICE* service; /**< The service which used by this listener */
|
||||||
int active; /**< True if the port has not been deleted */
|
int active; /**< True if the port has not been deleted */
|
||||||
SERV_LISTENER* next; /**< Next service protocol */
|
SERV_LISTENER* next; /**< Next service protocol */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using SListener = std::shared_ptr<SERV_LISTENER>;
|
||||||
|
|
||||||
typedef struct listener_iterator
|
typedef struct listener_iterator
|
||||||
{
|
{
|
||||||
SERV_LISTENER* current;
|
SERV_LISTENER* current;
|
||||||
@ -94,13 +97,13 @@ json_t* listener_to_json(const SERV_LISTENER* listener);
|
|||||||
* @return New listener or nullptr on error
|
* @return New listener or nullptr on error
|
||||||
*/
|
*/
|
||||||
SERV_LISTENER* listener_alloc(SERVICE* service,
|
SERV_LISTENER* listener_alloc(SERVICE* service,
|
||||||
const char* name,
|
const char* name,
|
||||||
const char* protocol,
|
const char* protocol,
|
||||||
const char* address,
|
const char* address,
|
||||||
unsigned short port,
|
unsigned short port,
|
||||||
const char* authenticator,
|
const char* authenticator,
|
||||||
const char* auth_options,
|
const char* auth_options,
|
||||||
SSL_LISTENER* ssl);
|
SSL_LISTENER* ssl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Free a listener
|
* @brief Free a listener
|
||||||
|
@ -11,29 +11,20 @@
|
|||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
#include <maxscale/listener.hh>
|
||||||
* @file listener.c - Listener generic functions
|
|
||||||
*
|
|
||||||
* Listeners wait for new client connections and, if the connection is successful
|
|
||||||
* a new session is created. A listener typically knows about a port or a socket,
|
|
||||||
* and a few other things. It may know about SSL if it is expecting an SSL
|
|
||||||
* connection.
|
|
||||||
*
|
|
||||||
* @verbatim
|
|
||||||
* Revision History
|
|
||||||
*
|
|
||||||
* Date Who Description
|
|
||||||
* 26/01/16 Martin Brampton Initial implementation
|
|
||||||
*
|
|
||||||
* @endverbatim
|
|
||||||
*/
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <maxscale/listener.hh>
|
#include <algorithm>
|
||||||
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <maxscale/paths.h>
|
#include <maxscale/paths.h>
|
||||||
#include <maxscale/ssl.h>
|
#include <maxscale/ssl.h>
|
||||||
#include <maxscale/protocol.h>
|
#include <maxscale/protocol.h>
|
||||||
@ -43,9 +34,11 @@
|
|||||||
#include <maxscale/service.hh>
|
#include <maxscale/service.hh>
|
||||||
#include <maxscale/poll.h>
|
#include <maxscale/poll.h>
|
||||||
|
|
||||||
|
static std::list<SListener> all_listeners;
|
||||||
|
static std::mutex listener_lock;
|
||||||
|
|
||||||
static RSA* rsa_512 = NULL;
|
static RSA* rsa_512 = NULL;
|
||||||
static RSA* rsa_1024 = NULL;
|
static RSA* rsa_1024 = NULL;
|
||||||
|
|
||||||
static RSA* tmp_rsa_callback(SSL* s, int is_export, int keylength);
|
static RSA* tmp_rsa_callback(SSL* s, int is_export, int keylength);
|
||||||
|
|
||||||
SERV_LISTENER::SERV_LISTENER(SERVICE* service, const std::string& name, const std::string& address,
|
SERV_LISTENER::SERV_LISTENER(SERVICE* service, const std::string& name, const std::string& address,
|
||||||
@ -110,13 +103,24 @@ SERV_LISTENER* listener_alloc(SERVICE* service,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new(std::nothrow) SERV_LISTENER(service, name, address, port, protocol, authenticator,
|
auto listener = new(std::nothrow) SERV_LISTENER(service, name, address, port, protocol, authenticator,
|
||||||
auth_options, auth_instance, ssl);
|
auth_options, auth_instance, ssl);
|
||||||
|
|
||||||
|
if (listener)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(listener_lock);
|
||||||
|
all_listeners.emplace_back(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
void listener_free(SERV_LISTENER* listener)
|
void listener_free(SERV_LISTENER* listener)
|
||||||
{
|
{
|
||||||
delete listener;
|
std::lock_guard<std::mutex> guard(listener_lock);
|
||||||
|
all_listeners.remove_if([&](const SListener& l) {
|
||||||
|
return l.get() == listener;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void listener_destroy(SERV_LISTENER* listener)
|
void listener_destroy(SERV_LISTENER* listener)
|
||||||
|
Reference in New Issue
Block a user