// Buffering hack! Throw what we've got in our "buffer" into the stream first, then get more.
if(control->gtls_buffer_hack_len>0){
if(length>control->gtls_buffer_hack_len){// If it's asking for more than we got
length-=control->gtls_buffer_hack_len;// Subtract what we have from their requested length
pos_start_fill=control->gtls_buffer_hack_len;// set the pos to start filling at
memcpy(buffer,control->gtls_buffer_hack,control->gtls_buffer_hack_len);// Fill their buffer partially
free(control->gtls_buffer_hack);// free our memory, it's not chained anymore
control->gtls_buffer_hack_len=0;// we don't have a hack buffer anymore
if(debug)printf("Did a partial fill to help quench thirst for data\n");
}elseif(length<control->gtls_buffer_hack_len){// If it's asking for less...
control->gtls_buffer_hack_len-=length;// subtract what they're asking for
memcpy(buffer,control->gtls_buffer_hack,length);// fill their buffer
hackhackhack=(char*)malloc(sizeof(char)*control->gtls_buffer_hack_len);// strndup is NOT a good solution -- concatenates \0!!!! Anyway, make a new "hack" buffer.
memcpy(hackhackhack,control->gtls_buffer_hack+length,control->gtls_buffer_hack_len);// Move what's left into the new one
free(control->gtls_buffer_hack);// Free the old one
control->gtls_buffer_hack=hackhackhack;// And make it the new one.
hackhackhack=NULL;
if(debug)printf("Quenched the thirst for data; new hack length is %i\n",control->gtls_buffer_hack_len);
returnlength;// hand it over.
}else{// length == hack length
memcpy(buffer,control->gtls_buffer_hack,length);// copy our buffer into theirs
if(debug)printf("Satiated the thirst for data; now we have to eventually receive again.\n");
returnlength;// hand it over
if(length>control->gtls_buffer_hack_len){// If it's asking for more than we got
length-=control->gtls_buffer_hack_len;// Subtract what we have from their requested length
pos_start_fill=control->gtls_buffer_hack_len;// set the pos to start filling at
memcpy(buffer,control->gtls_buffer_hack,control->gtls_buffer_hack_len);// Fill their buffer partially
free(control->gtls_buffer_hack);// free our memory, it's not chained anymore
control->gtls_buffer_hack_len=0;// we don't have a hack buffer anymore
if(debug)
printf("Did a partial fill to help quench thirst for data\n");
}elseif(length<control->gtls_buffer_hack_len){// If it's asking for less...
control->gtls_buffer_hack_len-=length;// subtract what they're asking for
memcpy(buffer,control->gtls_buffer_hack,length);// fill their buffer
hackhackhack=(char*)malloc(sizeof(char)*control->gtls_buffer_hack_len);// strndup is NOT a good solution -- concatenates \0!!!! Anyway, make a new "hack" buffer.
memcpy(hackhackhack,control->gtls_buffer_hack+length,control->gtls_buffer_hack_len);// Move what's left into the new one
free(control->gtls_buffer_hack);// Free the old one
control->gtls_buffer_hack=hackhackhack;// And make it the new one.
hackhackhack=NULL;
if(debug)
printf("Quenched the thirst for data; new hack length is %i\n",control->gtls_buffer_hack_len);
returnlength;// hand it over.
}else{// length == hack length
memcpy(buffer,control->gtls_buffer_hack,length);// copy our buffer into theirs