mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-27 11:40:52 +00:00
Resize response body buffer as needed
This commit is contained in:
parent
430fb27ec8
commit
85fef2655c
1 changed files with 19 additions and 8 deletions
|
@ -25,6 +25,9 @@ Documentation available here.
|
|||
#include "i_tcp.h"/* for current_port */
|
||||
#include "i_threads.h"
|
||||
|
||||
/* reasonable default I guess?? */
|
||||
#define DEFAULT_BUFFER_SIZE (4096)
|
||||
|
||||
/* I just stop myself from making macros anymore. */
|
||||
#define Blame( ... ) \
|
||||
CONS_Printf("\x85" __VA_ARGS__)
|
||||
|
@ -65,16 +68,25 @@ static size_t
|
|||
HMS_on_read (char *s, size_t _1, size_t n, void *userdata)
|
||||
{
|
||||
struct HMS_buffer *buffer;
|
||||
size_t blocks;
|
||||
|
||||
(void)_1;
|
||||
|
||||
buffer = userdata;
|
||||
if (n < (size_t)( buffer->end - buffer->needle ))
|
||||
|
||||
if (n >= (size_t)( buffer->end - buffer->needle ))
|
||||
{
|
||||
memcpy(&buffer->buffer[buffer->needle], s, n);
|
||||
buffer->needle += n;
|
||||
return n;
|
||||
/* resize to next multiple of buffer size */
|
||||
blocks = ( n / DEFAULT_BUFFER_SIZE + 1 );
|
||||
buffer->end = ( blocks * DEFAULT_BUFFER_SIZE );
|
||||
|
||||
buffer->buffer = realloc(buffer->buffer, buffer->end);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
memcpy(&buffer->buffer[buffer->needle], s, n);
|
||||
buffer->needle += n;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static struct HMS_buffer *
|
||||
|
@ -134,8 +146,7 @@ HMS_connect (const char *format, ...)
|
|||
|
||||
buffer = malloc(sizeof *buffer);
|
||||
buffer->curl = curl;
|
||||
/* I just allocated 4k and fuck it! */
|
||||
buffer->end = 4096;
|
||||
buffer->end = DEFAULT_BUFFER_SIZE;
|
||||
buffer->buffer = malloc(buffer->end);
|
||||
buffer->needle = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue