diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sendf.c | 2 | ||||
-rw-r--r-- | lib/transfer.c | 9 | ||||
-rw-r--r-- | lib/url.c | 12 | ||||
-rw-r--r-- | lib/urldata.h | 3 |
4 files changed, 21 insertions, 5 deletions
diff --git a/lib/sendf.c b/lib/sendf.c index bf9ee490a..922550b00 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -495,7 +495,7 @@ int Curl_read(struct connectdata *conn, /* connection data */ } /* If we come here, it means that there is no data to read from the buffer, * so we read from the socket */ - bytesfromsocket = MIN(sizerequested, sizeof(conn->master_buffer)); + bytesfromsocket = MIN(sizerequested, BUFSIZE * sizeof (char)); buffertofill = conn->master_buffer; } else { diff --git a/lib/transfer.c b/lib/transfer.c index 52b4c8966..d007e8814 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -289,8 +289,13 @@ static void read_rewind(struct connectdata *conn, size_t show; show = MIN(conn->buf_len - conn->read_pos, sizeof(buf)-1); - memcpy(buf, conn->master_buffer + conn->read_pos, show); - buf[show] = '\0'; + if (conn->master_buffer) { + memcpy(buf, conn->master_buffer + conn->read_pos, show); + buf[show] = '\0'; + } + else { + buf[0] = '\0'; + } DEBUGF(infof(conn->data, "Buffer after stream rewind (read_pos = %d): [%s]", @@ -1789,6 +1789,7 @@ static void conn_free(struct connectdata *conn) Curl_safefree(conn->trailer); Curl_safefree(conn->host.rawalloc); /* host name buffer */ Curl_safefree(conn->proxy.rawalloc); /* proxy name buffer */ + Curl_safefree(conn->master_buffer); Curl_llist_destroy(conn->send_pipe, NULL); Curl_llist_destroy(conn->recv_pipe, NULL); @@ -2825,7 +2826,7 @@ static CURLcode CreateConnection(struct SessionHandle *data, to not have to modify everything at once, we allocate a temporary connection data struct and fill in for comparison purposes. */ - conn = (struct connectdata *)calloc(sizeof(struct connectdata), 1); + conn = (struct connectdata *)calloc(1, sizeof(struct connectdata)); if(!conn) { *in_connect = NULL; /* clear the pointer */ return CURLE_OUT_OF_MEMORY; @@ -2835,6 +2836,14 @@ static CURLcode CreateConnection(struct SessionHandle *data, any failure */ *in_connect = conn; + if (data->multi && Curl_multi_canPipeline(data->multi) && + !conn->master_buffer) { + /* Allocate master_buffer to be used for pipelining */ + conn->master_buffer = calloc(BUFSIZE, sizeof (char)); + if (!conn->master_buffer) + return CURLE_OUT_OF_MEMORY; + } + /* and we setup a few fields in case we end up actually using this struct */ conn->data = data; /* Setup the association between this connection @@ -3803,6 +3812,7 @@ else { Curl_safefree(old_conn->proxypasswd); Curl_llist_destroy(old_conn->send_pipe, NULL); Curl_llist_destroy(old_conn->recv_pipe, NULL); + Curl_safefree(old_conn->master_buffer); free(old_conn); /* we don't need this anymore */ diff --git a/lib/urldata.h b/lib/urldata.h index b129ca708..023bc3ca3 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -868,7 +868,8 @@ struct connectdata { struct curl_llist *recv_pipe; /* List of handles waiting to read their responses on this pipeline */ - char master_buffer[BUFSIZE]; /* The master buffer for this connection. */ + char* master_buffer; /* The master buffer allocated on-demand; + used for pipelining. */ size_t read_pos; /* Current read position in the master buffer */ size_t buf_len; /* Length of the buffer?? */ |