MXS-2196: Move DCB initialization into DCB constructor
More of the DCB initialization is now done in the DCB constructor. This makes the creation of new DCBs simpler but it can be even simpler. By passing the file descriptor that the DCB should use into the constructor almost all of the initialization would be done inside it. Also removed the unused path member variable.
This commit is contained in:
@ -191,7 +191,7 @@ struct DCB : public MXB_POLL_DATA
|
|||||||
void* protocol = nullptr; /**< The protocol specific state */
|
void* protocol = nullptr; /**< The protocol specific state */
|
||||||
size_t protocol_packet_length = 0; /**< protocol packet length */
|
size_t protocol_packet_length = 0; /**< protocol packet length */
|
||||||
size_t protocol_bytes_processed = 0; /**< How many bytes have been read */
|
size_t protocol_bytes_processed = 0; /**< How many bytes have been read */
|
||||||
struct session* session = nullptr; /**< The owning session */
|
struct session* session; /**< The owning session */
|
||||||
SListener listener; /**< The origin of the connection */
|
SListener listener; /**< The origin of the connection */
|
||||||
MXS_PROTOCOL func = {}; /**< Protocol functions for the DCB */
|
MXS_PROTOCOL func = {}; /**< Protocol functions for the DCB */
|
||||||
MXS_AUTHENTICATOR authfunc = {}; /**< Authenticator functions for the DCB */
|
MXS_AUTHENTICATOR authfunc = {}; /**< Authenticator functions for the DCB */
|
||||||
@ -231,7 +231,6 @@ struct DCB : public MXB_POLL_DATA
|
|||||||
DCB* tail = nullptr; /**< Last DCB in owning thread's list */
|
DCB* tail = nullptr; /**< Last DCB in owning thread's list */
|
||||||
} thread;
|
} thread;
|
||||||
uint32_t n_close = 0; /** How many times dcb_close has been called. */
|
uint32_t n_close = 0; /** How many times dcb_close has been called. */
|
||||||
char* path = nullptr; /** If a Unix socket, the path it was bound to. */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,6 +168,15 @@ DCB::DCB(dcb_role_t role, const SListener& listener, SERVICE* service)
|
|||||||
, service(service)
|
, service(service)
|
||||||
, last_read(mxs_clock())
|
, last_read(mxs_clock())
|
||||||
{
|
{
|
||||||
|
session_set_dummy(this);
|
||||||
|
|
||||||
|
// TODO: Remove DCB_ROLE_INTERNAL to always have a valid listener
|
||||||
|
if (listener)
|
||||||
|
{
|
||||||
|
func = listener->protocol_func();
|
||||||
|
authfunc = listener->auth_func();
|
||||||
|
}
|
||||||
|
|
||||||
if (high_water && low_water)
|
if (high_water && low_water)
|
||||||
{
|
{
|
||||||
dcb_add_callback(this, DCB_REASON_HIGH_WATER, downstream_throttle_callback, NULL);
|
dcb_add_callback(this, DCB_REASON_HIGH_WATER, downstream_throttle_callback, NULL);
|
||||||
@ -201,7 +210,6 @@ DCB::~DCB()
|
|||||||
|
|
||||||
MXS_FREE(remote);
|
MXS_FREE(remote);
|
||||||
MXS_FREE(user);
|
MXS_FREE(user);
|
||||||
MXS_FREE(path);
|
|
||||||
MXS_FREE(protocol);
|
MXS_FREE(protocol);
|
||||||
gwbuf_free(delayq);
|
gwbuf_free(delayq);
|
||||||
gwbuf_free(writeq);
|
gwbuf_free(writeq);
|
||||||
@ -1215,14 +1223,6 @@ void dcb_final_close(DCB* dcb)
|
|||||||
|
|
||||||
MXS_DEBUG("Closed socket %d on dcb %p.", dcb->fd, dcb);
|
MXS_DEBUG("Closed socket %d on dcb %p.", dcb->fd, dcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dcb->path && (dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER))
|
|
||||||
{
|
|
||||||
if (unlink(dcb->path) != 0)
|
|
||||||
{
|
|
||||||
MXS_ERROR("Could not unlink %s: %s", dcb->path, mxs_strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -942,7 +942,6 @@ DCB* dcb_accept(const SListener& listener)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
client_dcb->session = session_set_dummy(client_dcb);
|
|
||||||
client_dcb->fd = c_sock;
|
client_dcb->fd = c_sock;
|
||||||
|
|
||||||
// get client address
|
// get client address
|
||||||
@ -951,7 +950,6 @@ DCB* dcb_accept(const SListener& listener)
|
|||||||
// client address
|
// client address
|
||||||
client_dcb->ip.ss_family = AF_UNIX;
|
client_dcb->ip.ss_family = AF_UNIX;
|
||||||
client_dcb->remote = MXS_STRDUP_A("localhost");
|
client_dcb->remote = MXS_STRDUP_A("localhost");
|
||||||
client_dcb->path = MXS_STRDUP_A(listener->address());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -976,9 +974,6 @@ DCB* dcb_accept(const SListener& listener)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client_dcb->func = listener->protocol_func();
|
|
||||||
client_dcb->authfunc = listener->auth_func();
|
|
||||||
|
|
||||||
/** Allocate DCB specific authentication data */
|
/** Allocate DCB specific authentication data */
|
||||||
if (client_dcb->authfunc.create
|
if (client_dcb->authfunc.create
|
||||||
&& (client_dcb->authenticator_data =
|
&& (client_dcb->authenticator_data =
|
||||||
|
@ -332,26 +332,13 @@ static int mysql_auth_authenticate(DCB* dcb)
|
|||||||
strcpy(extra, "Wrong password.");
|
strcpy(extra, "Wrong password.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dcb->path)
|
MXS_LOG_EVENT(maxscale::event::AUTHENTICATION_FAILURE,
|
||||||
{
|
"%s: login attempt for user '%s'@[%s]:%d, authentication failed. %s",
|
||||||
MXS_LOG_EVENT(maxscale::event::AUTHENTICATION_FAILURE,
|
dcb->service->name,
|
||||||
"%s: login attempt for user '%s'@[%s]:%s, authentication failed. %s",
|
client_data->user,
|
||||||
dcb->service->name,
|
dcb->remote,
|
||||||
client_data->user,
|
dcb_get_port(dcb),
|
||||||
dcb->remote,
|
extra);
|
||||||
dcb->path,
|
|
||||||
extra);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MXS_LOG_EVENT(maxscale::event::AUTHENTICATION_FAILURE,
|
|
||||||
"%s: login attempt for user '%s'@[%s]:%d, authentication failed. %s",
|
|
||||||
dcb->service->name,
|
|
||||||
client_data->user,
|
|
||||||
dcb->remote,
|
|
||||||
dcb_get_port(dcb),
|
|
||||||
extra);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_localhost_address(&dcb->ip)
|
if (is_localhost_address(&dcb->ip)
|
||||||
&& !dcb->service->localhost_match_wildcard_host)
|
&& !dcb->service->localhost_match_wildcard_host)
|
||||||
|
Reference in New Issue
Block a user