Skip to content

Commit

Permalink
Combine multiple packets in larger buffers for resultsets from QC #1482
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Apr 30, 2018
1 parent 0029f84 commit a92159a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/mysql_data_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,18 +1120,52 @@ unsigned char * MySQL_Data_Stream::resultset2buffer(bool del) {
return mybuff;
};

#define RESULTSET_BUFLEN_DS_16K 16000
#define RESULTSET_BUFLEN_DS_1M 1000*1024
void MySQL_Data_Stream::buffer2resultset(unsigned char *ptr, unsigned int size) {
unsigned char *__ptr=ptr;
mysql_hdr hdr;
unsigned int l;
void *pkt;
void *buff = NULL;
unsigned int bl;
unsigned int bf;
while (__ptr<ptr+size) {
memcpy(&hdr,__ptr,sizeof(mysql_hdr));
l=hdr.pkt_length+sizeof(mysql_hdr); // amount of space we need
if (buff) {
if ( bf < l ) {
// we ran out of space
resultset->add(buff,bl-bf);
buff=NULL;
}
}
if (buff == NULL) {
if (__ptr+RESULTSET_BUFLEN_DS_1M <= ptr+size) {
bl = RESULTSET_BUFLEN_DS_1M;
} else {
bl = RESULTSET_BUFLEN_DS_16K;
}
if (l > bl) {
bl = l; // make sure there is the space to copy a packet
}
buff = malloc(bl);
bf = bl;
}
memcpy(buff + (bl-bf), __ptr, l);
bf -= l;
__ptr+=l;
/*
l=hdr.pkt_length+sizeof(mysql_hdr);
pkt=l_alloc(l);
memcpy(pkt,__ptr,l);
resultset->add(pkt,l);
__ptr+=l;
*/
}
if (buff) {
// last buffer to add
resultset->add(buff,bl-bf);
}
};

Expand Down

0 comments on commit a92159a

Please sign in to comment.