MXS-2860: Extract socket error only when needed

As the process of extracting the socket error also resets it, it should be
done only when necessary.
This commit is contained in:
Markus Mäkelä 2020-03-06 13:56:42 +02:00
parent 318a81121b
commit eb0432b7b2
No known key found for this signature in database
GPG Key ID: 5CE746D557ACC499
2 changed files with 10 additions and 76 deletions

View File

@ -2657,30 +2657,12 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events)
if ((events & EPOLLOUT) && (dcb->n_close == 0))
{
int eno = 0;
eno = gw_getsockerrno(dcb->fd);
rc |= MXB_POLL_WRITE;
if (eno == 0)
if (dcb_session_check(dcb, "write_ready"))
{
rc |= MXB_POLL_WRITE;
if (dcb_session_check(dcb, "write_ready"))
{
DCB_EH_NOTICE("Calling dcb->func.write_ready(%p)", dcb);
dcb->func.write_ready(dcb);
}
}
else
{
char errbuf[MXS_STRERROR_BUFLEN];
MXS_DEBUG("%lu [poll_waitevents] "
"EPOLLOUT due %d, %s. "
"dcb %p, fd %i",
pthread_self(),
eno,
strerror_r(eno, errbuf, sizeof(errbuf)),
dcb,
dcb->fd);
DCB_EH_NOTICE("Calling dcb->func.write_ready(%p)", dcb);
dcb->func.write_ready(dcb);
}
}
if ((events & EPOLLIN) && (dcb->n_close == 0))
@ -2712,16 +2694,6 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events)
}
if ((events & EPOLLERR) && (dcb->n_close == 0))
{
int eno = gw_getsockerrno(dcb->fd);
if (eno != 0)
{
char errbuf[MXS_STRERROR_BUFLEN];
MXS_DEBUG("%lu [poll_waitevents] "
"EPOLLERR due %d, %s.",
pthread_self(),
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
}
rc |= MXB_POLL_ERROR;
if (dcb_session_check(dcb, "error"))
@ -2733,16 +2705,6 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events)
if ((events & EPOLLHUP) && (dcb->n_close == 0))
{
MXB_AT_DEBUG(int eno = gw_getsockerrno(dcb->fd));
MXB_AT_DEBUG(char errbuf[MXS_STRERROR_BUFLEN]);
MXS_DEBUG("%lu [poll_waitevents] "
"EPOLLHUP on dcb %p, fd %d. "
"Errno %d, %s.",
pthread_self(),
dcb,
dcb->fd,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
rc |= MXB_POLL_HUP;
if (!dcb->dcb_errhandle_called)
@ -2760,16 +2722,6 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events)
#ifdef EPOLLRDHUP
if ((events & EPOLLRDHUP) && (dcb->n_close == 0))
{
MXB_AT_DEBUG(int eno = gw_getsockerrno(dcb->fd));
MXB_AT_DEBUG(char errbuf[MXS_STRERROR_BUFLEN]);
MXS_DEBUG("%lu [poll_waitevents] "
"EPOLLRDHUP on dcb %p, fd %d. "
"Errno %d, %s.",
pthread_self(),
dcb,
dcb->fd,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
rc |= MXB_POLL_HUP;
if (!dcb->dcb_errhandle_called)

View File

@ -1329,29 +1329,15 @@ static int gw_error_backend_event(DCB* dcb)
if (dcb->persistentstart == 0)
{
/** Not a persistent connection, something is wrong. */
MXS_ERROR("EPOLLERR event on a non-persistent DCB with no session. "
"Closing connection.");
MXS_ERROR("EPOLLERR event on a non-persistent DCB with no session. Closing connection.");
}
dcb_close(dcb);
}
else if (dcb->state != DCB_STATE_POLLING || session->state != SESSION_STATE_STARTED)
{
int error;
int len = sizeof(error);
if (getsockopt(dcb->fd, SOL_SOCKET, SO_ERROR, &error, (socklen_t*) &len) == 0 && error != 0)
if (auto err = gw_getsockerrno(dcb->fd))
{
if (dcb->state != DCB_STATE_POLLING)
{
MXS_ERROR("DCB in state %s got error '%s'.",
STRDCBSTATE(dcb->state),
mxs_strerror(errno));
}
else
{
MXS_ERROR("Error '%s' in session that is not ready for routing.",
mxs_strerror(errno));
}
MXS_ERROR("DCB in state %s got error '%s'.", STRDCBSTATE(dcb->state), mxs_strerror(err));
}
}
else
@ -1381,15 +1367,11 @@ static int gw_backend_hangup(DCB* dcb)
{
if (session->state != SESSION_STATE_STARTED)
{
int error;
int len = sizeof(error);
if (getsockopt(dcb->fd, SOL_SOCKET, SO_ERROR, &error, (socklen_t*) &len) == 0)
if (session->state != SESSION_STATE_STOPPING)
{
if (error != 0 && session->state != SESSION_STATE_STOPPING)
if (auto err = gw_getsockerrno(dcb->fd))
{
MXS_ERROR("Hangup in session that is not ready for routing, "
"Error reported is '%s'.",
mxs_strerror(errno));
MXS_ERROR("Hangup in session that is not ready for routing: %s", mxs_strerror(err));
}
}
}