From e0ce987d72e68f08a47db8d84e23a6d91fc4162a Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 22 Mar 2015 08:56:18 +0200 Subject: [PATCH] Mysql_backend now only sends complete packets from the backend servers. --- server/core/buffer.c | 2 ++ server/core/modutil.c | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/server/core/buffer.c b/server/core/buffer.c index fa2fa8d13..4c788cdd2 100644 --- a/server/core/buffer.c +++ b/server/core/buffer.c @@ -336,6 +336,8 @@ gwbuf_append(GWBUF *head, GWBUF *tail) { if (!head) return tail; + if(!tail) + return head; CHK_GWBUF(head); head->tail->next = tail; head->tail = tail->tail; diff --git a/server/core/modutil.c b/server/core/modutil.c index f4a0a4e4e..20e57a9e6 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -539,19 +539,29 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf) { GWBUF *buff = NULL, *packet; uint8_t *ptr,*end; - unsigned int len,total = 0; + unsigned int len,blen,total = 0; if(p_readbuf == NULL || (*p_readbuf) == NULL || gwbuf_length(*p_readbuf) < 3) return NULL; - packet = *p_readbuf; + packet = gwbuf_make_contiguous(*p_readbuf); ptr = (uint8_t*)packet->start; end = (uint8_t*)packet->end; len = gw_mysql_get_byte3(ptr) + 4; if(ptr + len >= end) - return NULL; + { + if(len == gwbuf_length(*p_readbuf)) + { + *p_readbuf = NULL; + return packet; + } + else + { + return NULL; + } + } while(ptr + len < end) { @@ -561,13 +571,17 @@ GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf) } /** Full packets only, return original */ - if(total == gwbuf_length(packet)) + + if(total + len == (blen = gwbuf_length(packet))) + { + *p_readbuf = NULL; return packet; + } /** The next packet is a partial, split into complete and partial packets */ total -= len; - if(buff = gwbuf_alloc(total)) + if((buff = gwbuf_alloc(total)) == NULL) { skygw_log_write(LOGFILE_ERROR, "Error: Failed to allocate new buffer "