Small fix to modutil_get_complete_packets.

This commit is contained in:
Markus Makela
2015-03-22 10:09:58 +02:00
parent e0ce987d72
commit 6cfc2338c1
2 changed files with 16 additions and 17 deletions

View File

@ -539,31 +539,30 @@ 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,blen,total = 0; 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 = gwbuf_make_contiguous(*p_readbuf); packet = gwbuf_make_contiguous(*p_readbuf);
*p_readbuf = packet;
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;
blen = gwbuf_length(packet);
if(ptr + len >= end) if(ptr + len == end)
{
if(len == gwbuf_length(*p_readbuf))
{ {
*p_readbuf = NULL; *p_readbuf = NULL;
return packet; return packet;
} }
else else if(ptr + len > end)
{ {
return NULL; return NULL;
} }
}
while(ptr + len < end) while(total + len < blen)
{ {
ptr += len; ptr += len;
total += len; total += len;
@ -572,14 +571,13 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf)
/** Full packets only, return original */ /** Full packets only, return original */
if(total + len == (blen = gwbuf_length(packet))) if(total + len == blen)
{ {
*p_readbuf = NULL; *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;
if((buff = gwbuf_alloc(total)) == NULL) if((buff = gwbuf_alloc(total)) == NULL)
{ {
@ -592,15 +590,14 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf)
} }
memcpy(buff->start,packet->start,total); memcpy(buff->start,packet->start,total);
gwbuf_consume(*p_readbuf,total); gwbuf_consume(packet,total);
return buff; return buff;
} }
/** /**
* Count the number of EOF, OK or ERR packets in the buffer. Only complete * Count the number of EOF, OK or ERR packets in the buffer. Only complete
* packets are inspected and the buffer is assumed to only contain whole packets. * packets are inspected and the buffer is assumed to only contain whole packets.
* If partial packets are in the buffer, they are ingnored. The caller must handle the * If partial packets are in the buffer, they are ignored. The caller must handle the
* detection of partial packets in buffers. * detection of partial packets in buffers.
* @param reply Buffer to use * @param reply Buffer to use
* @param use_ok Whether the DEPRECATE_EOF flag is set * @param use_ok Whether the DEPRECATE_EOF flag is set

View File

@ -492,8 +492,10 @@ static int gw_read_backend_event(DCB *dcb) {
{ {
ss_dassert(read_buffer != NULL || dcb->dcb_readqueue != NULL); ss_dassert(read_buffer != NULL || dcb->dcb_readqueue != NULL);
} }
if(dcb->dcb_readqueue)
read_buffer = gwbuf_append(read_buffer,dcb->dcb_readqueue); {
read_buffer = gwbuf_append(dcb->dcb_readqueue,read_buffer);
}
nbytes_read = gwbuf_length(read_buffer); nbytes_read = gwbuf_length(read_buffer);
if (nbytes_read < 3) if (nbytes_read < 3)