From 8d30d34e0cc45376bb95de46d42a786c2c362e8a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 6 Jun 2003 14:58:26 +0000 Subject: When doing very big GET requests over HTTPS, we need to add some extra funky logic in order to make re-tries work fine with OpenSSL. This corrects the problem David Orrell noticed. --- lib/http.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/http.c b/lib/http.c index 408cbafc5..16a87d937 100644 --- a/lib/http.c +++ b/lib/http.c @@ -191,6 +191,7 @@ CURLcode add_buffer_send(send_buffer *in, char *ptr; int size; struct HTTP *http = conn->proto.http; + int sendsize; /* The looping below is required since we use non-blocking sockets, but due to the circumstances we will just loop and try again and again etc */ @@ -198,7 +199,28 @@ CURLcode add_buffer_send(send_buffer *in, ptr = in->buffer; size = in->size_used; - res = Curl_write(conn, sockfd, ptr, size, &amount); + if(conn->protocol & PROT_HTTPS) { + /* We never send more than CURL_MAX_WRITE_SIZE bytes in one single chunk + when we speak HTTPS, as if only a fraction of it is sent now, this data + needs to fit into the normal read-callback buffer later on and that + buffer is using this size. + */ + + sendsize= (size > CURL_MAX_WRITE_SIZE)?CURL_MAX_WRITE_SIZE:size; + + /* OpenSSL is very picky and we must send the SAME buffer pointer to the + library when we attempt to re-send this buffer. Sending the same data + is not enough, we must use the exact same address. For this reason, we + must copy the data to the uploadbuffer first, since that is the buffer + we will be using if this send is retried later. + */ + memcpy(conn->data->state.uploadbuffer, ptr, sendsize); + ptr = conn->data->state.uploadbuffer; + } + else + sendsize = size; + + res = Curl_write(conn, sockfd, ptr, sendsize, &amount); if(CURLE_OK == res) { -- cgit v1.2.3