MXS-2196: Use Listener in MXS_PROTOCOL::accept

This commit is contained in:
Markus Mäkelä 2018-11-30 18:08:55 +02:00
parent 45827dd433
commit e46104c32a
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
7 changed files with 27 additions and 21 deletions

View File

@ -18,10 +18,16 @@
* The protocol module interface definition.
*/
#include <maxscale/ccdefs.hh>
#include <maxbase/jansson.h>
#include <maxscale/cdefs.h>
#include <maxscale/buffer.h>
#include <memory>
class Listener;
using SListener = std::shared_ptr<Listener>;
MXS_BEGIN_DECLS
struct DCB;
@ -94,7 +100,7 @@ typedef struct mxs_protocol
*
* @note Currently the return value is ignored
*/
int32_t (* accept)(DCB* dcb);
int32_t (* accept)(const SListener& listener);
/**
* Connect to a server, only for backend side protocol modules

View File

@ -3000,7 +3000,7 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events)
if (dcb_session_check(dcb, "accept"))
{
DCB_EH_NOTICE("Calling dcb->func.accept(%p)", dcb);
dcb->func.accept(dcb);
dcb->func.accept(dcb->listener);
}
}
else

View File

@ -48,7 +48,7 @@ static int cdc_write_event(DCB* dcb);
static int cdc_write(DCB* dcb, GWBUF* queue);
static int cdc_error(DCB* dcb);
static int cdc_hangup(DCB* dcb);
static int cdc_accept(DCB* dcb);
static int cdc_accept(const SListener& listener);
static int cdc_close(DCB* dcb);
static CDC_protocol* cdc_protocol_init(DCB* dcb);
static void cdc_protocol_done(DCB* dcb);
@ -280,12 +280,12 @@ static int cdc_hangup(DCB* dcb)
*
* @param dcb The descriptor control block
*/
static int cdc_accept(DCB* listener)
static int cdc_accept(const SListener& listener)
{
int n_connect = 0;
DCB* client_dcb;
while ((client_dcb = dcb_accept(listener->listener)) != NULL)
while ((client_dcb = dcb_accept(listener)) != NULL)
{
CDC_session* client_data = NULL;
CDC_protocol* protocol = NULL;

View File

@ -50,7 +50,7 @@ static int httpd_write_event(DCB* dcb);
static int httpd_write(DCB* dcb, GWBUF* queue);
static int httpd_error(DCB* dcb);
static int httpd_hangup(DCB* dcb);
static int httpd_accept(DCB* dcb);
static int httpd_accept(const SListener& listener);
static int httpd_close(DCB* dcb);
static int httpd_get_line(int sock, char* buf, int size);
static void httpd_send_headers(DCB* dcb, int final, bool auth_ok);
@ -358,12 +358,12 @@ static int httpd_hangup(DCB* dcb)
*
* @param listener The descriptor control block
*/
static int httpd_accept(DCB* listener)
static int httpd_accept(const SListener& listener)
{
int n_connect = 0;
DCB* client_dcb;
while ((client_dcb = dcb_accept(listener->listener)) != NULL)
while ((client_dcb = dcb_accept(listener)) != NULL)
{
HTTPD_session* client_data = NULL;
@ -375,7 +375,7 @@ static int httpd_accept(DCB* listener)
}
client_dcb->data = client_data;
client_dcb->session = session_alloc(listener->session->service, client_dcb);
client_dcb->session = session_alloc(listener->service(), client_dcb);
if (NULL == client_dcb->session || poll_add_dcb(client_dcb) == -1)
{
dcb_close(client_dcb);

View File

@ -58,7 +58,7 @@ static void process_finish(void);
static int thread_init(void);
static void thread_finish(void);
static int gw_MySQLAccept(DCB* listener);
static int gw_MySQLAccept(const SListener& listener);
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);
@ -1390,11 +1390,11 @@ return_1:
* @return 0 in success, 1 in failure
*
*/
int gw_MySQLAccept(DCB* listener)
int gw_MySQLAccept(const SListener& listener)
{
DCB* client_dcb;
while ((client_dcb = dcb_accept(listener->listener)) != NULL)
while ((client_dcb = dcb_accept(listener)) != NULL)
{
gw_process_one_new_client(client_dcb);
} /**< while client_dcb != NULL */

View File

@ -61,7 +61,7 @@ static int maxscaled_write_event(DCB* dcb);
static int maxscaled_write(DCB* dcb, GWBUF* queue);
static int maxscaled_error(DCB* dcb);
static int maxscaled_hangup(DCB* dcb);
static int maxscaled_accept(DCB* dcb);
static int maxscaled_accept(const SListener& listener);
static int maxscaled_close(DCB* dcb);
static char* mxsd_default_auth();
@ -345,14 +345,14 @@ static int maxscaled_hangup(DCB* dcb)
* @param dcb The descriptor control block
* @return The number of new connections created
*/
static int maxscaled_accept(DCB* listener)
static int maxscaled_accept(const SListener& listener)
{
int n_connect = 0;
DCB* client_dcb;
socklen_t len = sizeof(struct ucred);
struct ucred ucred;
while ((client_dcb = dcb_accept(listener->listener)) != NULL)
while ((client_dcb = dcb_accept(listener)) != NULL)
{
MAXSCALED* maxscaled_protocol = (MAXSCALED*)calloc(1, sizeof(MAXSCALED));
@ -377,7 +377,7 @@ static int maxscaled_accept(DCB* listener)
pthread_mutex_init(&maxscaled_protocol->lock, NULL);
client_dcb->protocol = (void*)maxscaled_protocol;
client_dcb->session = session_alloc(listener->session->service, client_dcb);
client_dcb->session = session_alloc(listener->service(), client_dcb);
if (NULL == client_dcb->session || poll_add_dcb(client_dcb))
{

View File

@ -63,7 +63,7 @@ static int telnetd_write_event(DCB* dcb);
static int telnetd_write(DCB* dcb, GWBUF* queue);
static int telnetd_error(DCB* dcb);
static int telnetd_hangup(DCB* dcb);
static int telnetd_accept(DCB* dcb);
static int telnetd_accept(const SListener& listener);
static int telnetd_close(DCB* dcb);
static char* telnetd_default_auth();
@ -276,12 +276,12 @@ static int telnetd_hangup(DCB* dcb)
* @param listener The descriptor control block
* @return The number of new connections created
*/
static int telnetd_accept(DCB* listener)
static int telnetd_accept(const SListener& listener)
{
int n_connect = 0;
DCB* client_dcb;
while ((client_dcb = dcb_accept(listener->listener)) != NULL)
while ((client_dcb = dcb_accept(listener)) != NULL)
{
TELNETD* telnetd_protocol = NULL;
@ -294,7 +294,7 @@ static int telnetd_accept(DCB* listener)
telnetd_protocol->username = NULL;
client_dcb->protocol = (void*)telnetd_protocol;
client_dcb->session = session_alloc(listener->session->service, client_dcb);
client_dcb->session = session_alloc(listener->service(), client_dcb);
if (NULL == client_dcb->session || poll_add_dcb(client_dcb))
{
dcb_close(client_dcb);