From 0c8fdaed01bae805dc7f9316d3ed574e844e9d14 Mon Sep 17 00:00:00 2001 From: Massimiliano Pinto Date: Tue, 11 Jun 2013 12:28:37 +0200 Subject: [PATCH] New versions --- gateway.c | 46 +++++++++++++++++++++++++--------------------- gw.h | 4 ++-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/gateway.c b/gateway.c index 87cb57d9d..23f674c5e 100644 --- a/gateway.c +++ b/gateway.c @@ -31,6 +31,8 @@ Massimiliano Pinto // epoll fd, global! static int epollfd; +void myfree(void** pp) { free(*pp); *pp = NULL; } + /* basic signal handling */ static void sighup_handler (int i) { fprintf(stderr, "Signal SIGHUP %i received ...\n", i); @@ -49,7 +51,7 @@ static void signal_set (int sig, void (*handler)(int)) { memset(&sigact, 0, sizeof(struct sigaction)); sigact.sa_handler = handler; - GW_LOOPED_CALL(err = sigaction(sig, &sigact, NULL)); + GW_NOINTR_CALL(err = sigaction(sig, &sigact, NULL)); if (err < 0) { fprintf(stderr,"sigaction() error %s\n", strerror(errno)); exit(1); @@ -60,12 +62,11 @@ int handle_event_errors(DCB *dcb, int event) { struct epoll_event ed; MySQLProtocol *protocol = DCB_PROTOCOL(dcb, MySQLProtocol); - fprintf(stderr, "#### Handle error function for %i\n", dcb->fd); + fprintf(stderr, "#### Handle error function for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state)); - if (dcb) { - if (dcb->state == DCB_STATE_DISCONNECTED) { - return 1; - } + if (dcb->state == DCB_STATE_DISCONNECTED) { + fprintf(stderr, "#### Handle error function, session is %p\n", dcb->session); + return 1; } #ifdef GW_EVENT_DEBUG @@ -95,18 +96,26 @@ int handle_event_errors(DCB *dcb, int event) { gw_mysql_close((MySQLProtocol **)&dcb->protocol); fprintf(stderr, "Client protocol dcb->protocol %p\n", dcb->protocol); + dcb->state = DCB_STATE_DISCONNECTED; - +/* if (dcb->session->backends->protocol != NULL) { - fprintf(stderr, "!!!!!! BAckend still open! dcb %p\n", dcb->session->backends->protocol); + fprintf(stderr, "!!!!!! Backend still open! dcb %p\n", dcb->session->backends->protocol); gw_mysql_close((MySQLProtocol **)&dcb->session->backends->protocol); } - close(dcb->fd); +*/ } - free(dcb->session); - free(dcb); } + + fprintf(stderr, "Return from error handling, dcb is %p\n", dcb); + free(dcb->session); + dcb->state = DCB_STATE_FREED; + + fprintf(stderr, "#### Handle error function RETURN for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state)); + //myfree((void **)&dcb); + + return 1; } int handle_event_errors_backend(DCB *dcb, int event) { @@ -142,9 +151,7 @@ int handle_event_errors_backend(DCB *dcb, int event) { fprintf(stderr, "Freeing backend MySQL conn %p, %p\n", dcb->protocol, &dcb->protocol); gw_mysql_close((MySQLProtocol **)&dcb->protocol); fprintf(stderr, "Freeing backend MySQL conn %p, %p\n", dcb->protocol, &dcb->protocol); - close(dcb->fd); } - free(dcb); } } @@ -234,32 +241,29 @@ int main(int argc, char **argv) { fprintf(stderr, "New event %i for socket %i is EPOLLPRI\n", n, dcb->fd); //#endif - if ((events[n].events & EPOLLIN) || (events[n].events & EPOLLPRI)) { + if (events[n].events & EPOLLIN) { // now checking the listening socket if (dcb->state == DCB_STATE_LISTENING) { (dcb->func).accept(dcb, epollfd); } else { - // all the other filedesc here: clients and backends too! - //protcocol based read operations + fprintf(stderr, "CALL the READ pointer\n"); (dcb->func).read(dcb, epollfd); } - } if (events[n].events & EPOLLOUT) { if (dcb->state != DCB_STATE_LISTENING) { - //protcocol based write operations + fprintf(stderr, "CALL the WRITE pointer\n"); (dcb->func).write(dcb, epollfd); + fprintf(stderr, ">>> CALLED the WRITE pointer\n"); } } if (events[n].events & (EPOLLERR | EPOLLHUP)) { - - // error handling + fprintf(stderr, "CALL the ERROR pointer\n"); (dcb->func).error(dcb, events[n].events); - if (dcb) free(dcb); } } // filedesc loop diff --git a/gw.h b/gw.h index d7ffe84af..6a5f1355a 100644 --- a/gw.h +++ b/gw.h @@ -25,9 +25,9 @@ // network buffer is 32K #define MAX_BUFFER_SIZE 32768 // socket send buffer for backend -#define GW_BACKEND_SO_SNDBUF 16384 +#define GW_BACKEND_SO_SNDBUF 16 -#define GW_LOOPED_CALL(A) do { errno = 0; A; } while (errno == EINTR) +#define GW_NOINTR_CALL(A) do { errno = 0; A; } while (errno == EINTR) #define GW_VERSION "0.1.0" #define GW_MYSQL_VERSION "5.5.22-SKYSQL-" GW_VERSION #define GW_MYSQL_LOOP_TIMEOUT 300000000