From 4597cdf7b93a420b618de0589470f95ebae789cf Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 8 Sep 2016 09:47:34 +0300 Subject: [PATCH] Use gwbuf_split in modutil_get_next_MySQL_packet Earlier, a copy was made. --- server/core/modutil.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/server/core/modutil.c b/server/core/modutil.c index 0cbae7f2e..62e6af6d7 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -501,12 +501,9 @@ GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf) { GWBUF* packetbuf; GWBUF* readbuf; - size_t buflen; size_t packetlen; size_t totalbuflen; uint8_t* data; - size_t nbytes_copied = 0; - uint8_t* target; readbuf = *p_readbuf; @@ -549,27 +546,7 @@ GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf) goto return_packetbuf; } - packetbuf = gwbuf_alloc(packetlen); - target = GWBUF_DATA(packetbuf); - packetbuf->gwbuf_type = readbuf->gwbuf_type; /*< Copy the type too */ - /** - * Copy first MySQL packet to packetbuf and leave posible other - * packets to read buffer. - */ - while (nbytes_copied < packetlen && totalbuflen > 0) - { - uint8_t* src = GWBUF_DATA((*p_readbuf)); - size_t bytestocopy; - - buflen = GWBUF_LENGTH((*p_readbuf)); - bytestocopy = MIN(buflen, packetlen - nbytes_copied); - - memcpy(target + nbytes_copied, src, bytestocopy); - *p_readbuf = gwbuf_consume((*p_readbuf), bytestocopy); - totalbuflen = gwbuf_length((*p_readbuf)); - nbytes_copied += bytestocopy; - } - ss_dassert(buflen == 0 || nbytes_copied == packetlen); + packetbuf = gwbuf_split(p_readbuf, packetlen); return_packetbuf: return packetbuf;