diff --git a/server/core/modutil.c b/server/core/modutil.c index d6dbfa7b1..e5528d73a 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -31,7 +31,7 @@ #include #include #include - +#include /** * Check if a GWBUF structure is a MySQL COM_QUERY packet * @@ -493,3 +493,29 @@ GWBUF* modutil_get_next_MySQL_packet( return_packetbuf: return packetbuf; } + + +/** + * Count the number of EOF packets in the buffer. + * @param reply Buffer to use + * @return Number of EOF packets + */ +int +modutil_count_EOF(GWBUF *reply) +{ + unsigned char* ptr = (unsigned char*) reply->start; + unsigned char* end = (unsigned char*) reply->end; + int pktlen,eof = 0; + + while(ptr < end) + { + pktlen = gw_mysql_get_byte3(ptr) + 4; + if(PTR_IS_EOF(ptr)) + { + eof++; + } + + ptr += pktlen; + } + return eof; +} diff --git a/server/include/modutil.h b/server/include/modutil.h index fac39cbcc..a94fe2f60 100644 --- a/server/include/modutil.h +++ b/server/include/modutil.h @@ -34,6 +34,12 @@ #include #include +#define PTR_IS_RESULTSET(b) (b[0] == 0x01 && b[1] == 0x0 && b[2] == 0x0 && b[3] == 0x01) +#define PTR_IS_EOF(b) (b[4] == 0xfe) +#define PTR_IS_OK(b) (b[4] == 0x00) +#define PTR_IS_ERR(b) (b[4] == 0xff) +#define PTR_IS_LOCAL_INFILE(b) (b[4] == 0xfb) + extern int modutil_is_SQL(GWBUF *); extern int modutil_extract_SQL(GWBUF *, char **, int *); extern int modutil_MySQL_Query(GWBUF *, char **, int *, int *); @@ -52,4 +58,5 @@ GWBUF *modutil_create_mysql_err_msg( const char *statemsg, const char *msg); +int modutil_count_EOF(GWBUF*); #endif diff --git a/server/modules/filter/tee.c b/server/modules/filter/tee.c index af56660db..1e2e18213 100644 --- a/server/modules/filter/tee.c +++ b/server/modules/filter/tee.c @@ -78,9 +78,6 @@ #define PARENT 0 #define CHILD 1 -#define PTR_IS_RESULTSET(b) (b[0] == 0x01 && b[1] == 0x0 && b[2] == 0x0 && b[3] == 0x01) -#define PTR_IS_EOF(b) (b[4] == 0xfe) - static unsigned char required_packets[] = { MYSQL_COM_QUIT, MYSQL_COM_INITDB, @@ -827,39 +824,6 @@ GWBUF *clone = NULL; return rval; } -/** - * Scans the GWBUF for EOF packets. If two packets for this session have been found - * from either the parent or the child branch, mark the response set from that branch as over. - * @param session The Tee filter session - * @param branch Parent or child branch - * @param reply Buffer to scan - */ -void -scan_resultset(TEE_SESSION *session, int branch, GWBUF *reply) -{ - unsigned char* ptr = (unsigned char*) reply->start; - unsigned char* end = (unsigned char*) reply->end; - int pktlen = 0; - - while(ptr < end) - { - pktlen = gw_mysql_get_byte3(ptr) + 4; - if(PTR_IS_EOF(ptr)) - { - session->eof[branch]++; - - if(session->eof[branch] == 2) - { - session->waiting[branch] = false; - session->eof[branch] = 0; - return; - } - } - - ptr += pktlen; - } -} - /** * The clientReply entry point. This is passed the response buffer * to which the filter should be applied. Once processed the @@ -894,7 +858,13 @@ clientReply (FILTER* instance, void *session, GWBUF *reply) if(my_session->waiting[branch]) { - scan_resultset(my_session,branch,reply); + int eof = modutil_count_EOF(reply); + + if((my_session->eof[branch] += eof) >= 2) + { + my_session->eof[branch] = 0; + my_session->waiting[branch] = false; + } } if(branch == PARENT)