aboutsummaryrefslogtreecommitdiff
path: root/lib/sendf.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-05-02 17:04:08 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-05-04 10:40:39 +0200
commited35d6590e72c23c568af1e3b8ac6e4e2d883888 (patch)
tree57555732f4f452bf84c3c7296581485be064a853 /lib/sendf.c
parent00c2e8da9a9555ce6171e3f7ddc5e43fc6f9bb4b (diff)
dynbuf: introduce internal generic dynamic buffer functions
A common set of functions instead of many separate implementations for creating buffers that can grow when appending data to them. Existing functionality has been ported over. In my early basic testing, the total number of allocations seem at roughly the same amount as before, possibly a few less. See docs/DYNBUF.md for a description of the API. Closes #5300
Diffstat (limited to 'lib/sendf.c')
-rw-r--r--lib/sendf.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/lib/sendf.c b/lib/sendf.c
index 6ef47aa80..6ad32e1b3 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -498,7 +498,6 @@ static CURLcode pausewrite(struct Curl_easy *data,
is again enabled */
struct SingleRequest *k = &data->req;
struct UrlState *s = &data->state;
- char *dupl;
unsigned int i;
bool newtype = TRUE;
@@ -518,44 +517,21 @@ static CURLcode pausewrite(struct Curl_easy *data,
else
i = 0;
- if(!newtype) {
- /* append new data to old data */
-
- /* figure out the new size of the data to save */
- size_t newlen = len + s->tempwrite[i].len;
- /* allocate the new memory area */
- char *newptr = realloc(s->tempwrite[i].buf, newlen);
- if(!newptr)
- return CURLE_OUT_OF_MEMORY;
- /* copy the new data to the end of the new area */
- memcpy(newptr + s->tempwrite[i].len, ptr, len);
-
- /* update the pointer and the size */
- s->tempwrite[i].buf = newptr;
- s->tempwrite[i].len = newlen;
-
- len = newlen; /* for the debug output below */
- }
- else {
- dupl = Curl_memdup(ptr, len);
- if(!dupl)
- return CURLE_OUT_OF_MEMORY;
-
+ if(newtype) {
/* store this information in the state struct for later use */
- s->tempwrite[i].buf = dupl;
- s->tempwrite[i].len = len;
+ Curl_dyn_init(&s->tempwrite[i].b, DYN_PAUSE_BUFFER);
s->tempwrite[i].type = type;
if(newtype)
s->tempcount++;
}
+ if(Curl_dyn_addn(&s->tempwrite[i].b, (unsigned char *)ptr, len))
+ return CURLE_OUT_OF_MEMORY;
+
/* mark the connection as RECV paused */
k->keepon |= KEEP_RECV_PAUSE;
- DEBUGF(infof(data, "Paused %zu bytes in buffer for type %02x\n",
- len, type));
-
return CURLE_OK;
}