Mysql_backend now only sends complete packets from the backend servers.

This commit is contained in:
Markus Makela
2015-03-22 08:56:18 +02:00
parent 55513cc998
commit e0ce987d72
2 changed files with 21 additions and 5 deletions

View File

@ -336,6 +336,8 @@ gwbuf_append(GWBUF *head, GWBUF *tail)
{ {
if (!head) if (!head)
return tail; return tail;
if(!tail)
return head;
CHK_GWBUF(head); CHK_GWBUF(head);
head->tail->next = tail; head->tail->next = tail;
head->tail = tail->tail; head->tail = tail->tail;

View File

@ -539,19 +539,29 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf)
{ {
GWBUF *buff = NULL, *packet; GWBUF *buff = NULL, *packet;
uint8_t *ptr,*end; uint8_t *ptr,*end;
unsigned int len,total = 0; unsigned int len,blen,total = 0;
if(p_readbuf == NULL || (*p_readbuf) == NULL || if(p_readbuf == NULL || (*p_readbuf) == NULL ||
gwbuf_length(*p_readbuf) < 3) gwbuf_length(*p_readbuf) < 3)
return NULL; return NULL;
packet = *p_readbuf; packet = gwbuf_make_contiguous(*p_readbuf);
ptr = (uint8_t*)packet->start; ptr = (uint8_t*)packet->start;
end = (uint8_t*)packet->end; end = (uint8_t*)packet->end;
len = gw_mysql_get_byte3(ptr) + 4; len = gw_mysql_get_byte3(ptr) + 4;
if(ptr + len >= end) if(ptr + len >= end)
return NULL; {
if(len == gwbuf_length(*p_readbuf))
{
*p_readbuf = NULL;
return packet;
}
else
{
return NULL;
}
}
while(ptr + len < end) while(ptr + len < end)
{ {
@ -561,13 +571,17 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf)
} }
/** Full packets only, return original */ /** Full packets only, return original */
if(total == gwbuf_length(packet))
if(total + len == (blen = gwbuf_length(packet)))
{
*p_readbuf = NULL;
return packet; return packet;
}
/** The next packet is a partial, split into complete and partial packets */ /** The next packet is a partial, split into complete and partial packets */
total -= len; total -= len;
if(buff = gwbuf_alloc(total)) if((buff = gwbuf_alloc(total)) == NULL)
{ {
skygw_log_write(LOGFILE_ERROR, skygw_log_write(LOGFILE_ERROR,
"Error: Failed to allocate new buffer " "Error: Failed to allocate new buffer "