Moved result set processing functions to modutil.c from tee.c.
This commit is contained in:
@ -31,7 +31,7 @@
|
|||||||
#include <buffer.h>
|
#include <buffer.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <mysql_client_server_protocol.h>
|
#include <mysql_client_server_protocol.h>
|
||||||
|
#include <modutil.h>
|
||||||
/**
|
/**
|
||||||
* Check if a GWBUF structure is a MySQL COM_QUERY packet
|
* 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:
|
||||||
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;
|
||||||
|
}
|
||||||
|
@ -34,6 +34,12 @@
|
|||||||
#include <buffer.h>
|
#include <buffer.h>
|
||||||
#include <dcb.h>
|
#include <dcb.h>
|
||||||
|
|
||||||
|
#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_is_SQL(GWBUF *);
|
||||||
extern int modutil_extract_SQL(GWBUF *, char **, int *);
|
extern int modutil_extract_SQL(GWBUF *, char **, int *);
|
||||||
extern int modutil_MySQL_Query(GWBUF *, char **, int *, 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 *statemsg,
|
||||||
const char *msg);
|
const char *msg);
|
||||||
|
|
||||||
|
int modutil_count_EOF(GWBUF*);
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,9 +78,6 @@
|
|||||||
#define PARENT 0
|
#define PARENT 0
|
||||||
#define CHILD 1
|
#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[] = {
|
static unsigned char required_packets[] = {
|
||||||
MYSQL_COM_QUIT,
|
MYSQL_COM_QUIT,
|
||||||
MYSQL_COM_INITDB,
|
MYSQL_COM_INITDB,
|
||||||
@ -827,39 +824,6 @@ GWBUF *clone = NULL;
|
|||||||
return rval;
|
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
|
* The clientReply entry point. This is passed the response buffer
|
||||||
* to which the filter should be applied. Once processed the
|
* 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])
|
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)
|
if(branch == PARENT)
|
||||||
|
Reference in New Issue
Block a user