From 99465dd6b7bfcef2abfe73a9bbc5ee0563fd6990 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Thu, 27 Jun 2013 09:28:34 +0200 Subject: [PATCH] Move sending of the OK on client side authentication to the EPOLLIN event processing routine Addition of a compile switch to make epoll block rather than timeout, useful only for debugging --- core/poll.c | 9 +++++++ modules/protocol/mysql_client.c | 47 +++++++++++++++------------------ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/core/poll.c b/core/poll.c index 0909a8788..6bc93fcbf 100644 --- a/core/poll.c +++ b/core/poll.c @@ -104,6 +104,9 @@ struct epoll_event ev; return epoll_ctl(epoll_fd, EPOLL_CTL_DEL, dcb->fd, &ev); } +#define BLOCKINGPOLL 1 /* Set BLOCKING POLL to 1 if using a single thread and to make + * debugging easier. + */ /** * The main polling loop * @@ -118,6 +121,11 @@ int i, nfds; while (1) { +#if BLOCKINGPOLL + if ((nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, -1)) == -1) + { + } +#else if ((nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, 0)) == -1) { } @@ -127,6 +135,7 @@ int i, nfds; { } } +#endif if (nfds > 0) { atomic_add(&pollStats.n_polls, 1); diff --git a/modules/protocol/mysql_client.c b/modules/protocol/mysql_client.c index 6de84b617..505d32930 100644 --- a/modules/protocol/mysql_client.c +++ b/modules/protocol/mysql_client.c @@ -823,11 +823,33 @@ int gw_read_client_event(DCB* dcb) { queue = gwbuf_consume(queue, len); if (auth_val == 0) + { + SESSION *session = NULL; + protocol->state = MYSQL_AUTH_RECV; + + //write to client mysql AUTH_OK packet, packet n. is 2 + mysql_send_ok(dcb, 2, 0, NULL); + + // start a new session, and connect to backends + session = session_alloc(dcb->service, dcb); + + protocol->state = MYSQL_IDLE; + + session->data = (MYSQL_session *)dcb->data; + } else + { protocol->state = MYSQL_AUTH_FAILED; + + // still to implement + mysql_send_auth_error(dcb, 2, 0, "Authorization failed"); + + dcb->func.close(dcb); + } } + break; case MYSQL_IDLE: @@ -952,31 +974,6 @@ int gw_write_client_event(DCB *dcb) { return 1; } - if(protocol->state == MYSQL_AUTH_RECV) { - SESSION *session = NULL; - - //write to client mysql AUTH_OK packet, packet n. is 2 - mysql_send_ok(dcb, 2, 0, NULL); - - // start a new session, and connect to backends - session = session_alloc(dcb->service, dcb); - - protocol->state = MYSQL_IDLE; - - session->data = (MYSQL_session *)dcb->data; - - return 0; - } - - if (protocol->state == MYSQL_AUTH_FAILED) { - // still to implement - mysql_send_auth_error(dcb, 2, 0, "Authorization failed"); - - dcb->func.close(dcb); - - return 0; - } - if ((protocol->state == MYSQL_IDLE) || (protocol->state == MYSQL_WAITING_RESULT)) { int w;