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:
Markus Mäkelä
2018-12-01 21:29:30 +02:00
parent 6cf672195a
commit 8046a314e5
4 changed files with 17 additions and 36 deletions

View File

@ -191,7 +191,7 @@ struct DCB : public MXB_POLL_DATA
void* protocol = nullptr; /**< The protocol specific state */
size_t protocol_packet_length = 0; /**< protocol packet length */
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 */
MXS_PROTOCOL func = {}; /**< Protocol 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 */
} thread;
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. */
};
/**

View File

@ -168,6 +168,15 @@ DCB::DCB(dcb_role_t role, const SListener& listener, SERVICE* service)
, service(service)
, 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)
{
dcb_add_callback(this, DCB_REASON_HIGH_WATER, downstream_throttle_callback, NULL);
@ -201,7 +210,6 @@ DCB::~DCB()
MXS_FREE(remote);
MXS_FREE(user);
MXS_FREE(path);
MXS_FREE(protocol);
gwbuf_free(delayq);
gwbuf_free(writeq);
@ -1215,14 +1223,6 @@ void dcb_final_close(DCB* 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
{

View File

@ -942,7 +942,6 @@ DCB* dcb_accept(const SListener& listener)
}
else
{
client_dcb->session = session_set_dummy(client_dcb);
client_dcb->fd = c_sock;
// get client address
@ -951,7 +950,6 @@ DCB* dcb_accept(const SListener& listener)
// client address
client_dcb->ip.ss_family = AF_UNIX;
client_dcb->remote = MXS_STRDUP_A("localhost");
client_dcb->path = MXS_STRDUP_A(listener->address());
}
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 */
if (client_dcb->authfunc.create
&& (client_dcb->authenticator_data =

View File

@ -332,18 +332,6 @@ static int mysql_auth_authenticate(DCB* dcb)
strcpy(extra, "Wrong password.");
}
if (dcb->path)
{
MXS_LOG_EVENT(maxscale::event::AUTHENTICATION_FAILURE,
"%s: login attempt for user '%s'@[%s]:%s, authentication failed. %s",
dcb->service->name,
client_data->user,
dcb->remote,
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,
@ -351,7 +339,6 @@ static int mysql_auth_authenticate(DCB* dcb)
dcb->remote,
dcb_get_port(dcb),
extra);
}
if (is_localhost_address(&dcb->ip)
&& !dcb->service->localhost_match_wildcard_host)