mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-28 20:20:43 +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_tcp.h"/* for current_port */
|
||||||
#include "i_threads.h"
|
#include "i_threads.h"
|
||||||
|
|
||||||
|
/* reasonable default I guess?? */
|
||||||
|
#define DEFAULT_BUFFER_SIZE (4096)
|
||||||
|
|
||||||
/* I just stop myself from making macros anymore. */
|
/* I just stop myself from making macros anymore. */
|
||||||
#define Blame( ... ) \
|
#define Blame( ... ) \
|
||||||
CONS_Printf("\x85" __VA_ARGS__)
|
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)
|
HMS_on_read (char *s, size_t _1, size_t n, void *userdata)
|
||||||
{
|
{
|
||||||
struct HMS_buffer *buffer;
|
struct HMS_buffer *buffer;
|
||||||
|
size_t blocks;
|
||||||
|
|
||||||
(void)_1;
|
(void)_1;
|
||||||
|
|
||||||
buffer = userdata;
|
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);
|
/* resize to next multiple of buffer size */
|
||||||
buffer->needle += n;
|
blocks = ( n / DEFAULT_BUFFER_SIZE + 1 );
|
||||||
return n;
|
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 *
|
static struct HMS_buffer *
|
||||||
|
@ -134,8 +146,7 @@ HMS_connect (const char *format, ...)
|
||||||
|
|
||||||
buffer = malloc(sizeof *buffer);
|
buffer = malloc(sizeof *buffer);
|
||||||
buffer->curl = curl;
|
buffer->curl = curl;
|
||||||
/* I just allocated 4k and fuck it! */
|
buffer->end = DEFAULT_BUFFER_SIZE;
|
||||||
buffer->end = 4096;
|
|
||||||
buffer->buffer = malloc(buffer->end);
|
buffer->buffer = malloc(buffer->end);
|
||||||
buffer->needle = 0;
|
buffer->needle = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue