curl-library
libcurl PUT retry and READFUNCTION
Date: Mon, 23 Jan 2012 17:42:35 +0000
Hi all,
I use libcurl to put a file to a HTTP server. When HTTP server FIN TCP connection, the curl retried and resend the http header. However, the data in retry packet has 0 length.
The sequence of the packet is as follows. The 1.1.1.1 is client IP address, the 2.2.2.2 is server IP address
1 0.000000 1.1.1.1 -> 2.2.2.2 HTTP PUT /webdav/arxce/1327331782-01XFR48JF-17.metadata HTTP/1.1 #### Initial PUT request, send HTTP header
2 0.000105 2.2.2.2 -> 1.1.1.1 TCP www > 55199 [FIN, ACK] Seq=0 Ack=0 Win=27 Len=0 #### Server FIN the connection
3 0.000124 1.1.1.1 -> 2.2.2.2 HTTP Continuation or non-HTTP traffic #### client send DATA 373 bytes. (Probably send before process the TCP FIN packet).
4 0.000177 1.1.1.1 -> 2.2.2.2 TCP 55199 > www [FIN, ACK] Seq=533 Ack=1 Win=254 [TCP CHECKSUM INCORRECT] Len=0 ### Client FIN above TCP connection
5 0.000294 1.1.1.1 -> 2.2.2.2 TCP 55200 > www [SYN] Seq=0 [TCP CHECKSUM INCORRECT] Len=0 MSS=1460 WS=8 #### Client started a new TCP connection
6 0.000496 2.2.2.2 -> 1.1.1.1 TCP www > 55199 [ACK] Seq=1 Ack=534 Win=36 Len=0
7 0.000498 2.2.2.2 -> 1.1.1.1 TCP www > 55200 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460 WS=8
8 0.000532 1.1.1.1 -> 2.2.2.2 TCP 55200 > www [ACK] Seq=1 Ack=1 Win=65536 [TCP CHECKSUM INCORRECT] Len=0
9 0.000600 1.1.1.1 -> 2.2.2.2 HTTP PUT /webdav/arxce/1327331782-01XFR48JF-17.metadata HTTP/1.1 ### Retry PUT request, send HTTP header
10 0.000785 2.2.2.2 -> 1.1.1.1 TCP www > 55200 [ACK] Seq=1 Ack=161 Win=6912 Len=0 #### Server ACK
11 0.000802 1.1.1.1 -> 2.2.2.2 HTTP Continuation or non-HTTP traffic #### client resend the data (only 5 bytes 300d0a0d0a), it should send 373 bytes as initial data send.
12 0.000933 2.2.2.2 -> 1.1.1.1 TCP www > 55200 [ACK] Seq=1 Ack=166 Win=6912 Len=0 #### Server ACK
13 0.001284 2.2.2.2 -> 1.1.1.1 HTTP HTTP/1.1 201 Created (text/html)I saw a similar issue reported here ### Server response with created (but only the file is only 0 byte).
I read the e-mail trace and look like this is the similar problem and SEEKFUNCTION is suggested here.
http://curl.haxx.se/mail/lib-2009-08/0401.html
What is the final solution to the issue described above? If SEEKFUNCTION is used, does anyone have an example of how to use it.
Thank you very much for your help in advance.
Wenjun Chen
PS.
I use READFUNCTION call back to put data to the libcurl buff.
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// set the put_data_callback function
curl_easy_setopt(curl, CURLOPT_PUT, true);
curl_easy_setopt(curl, CURLOPT_READDATA, &m_data);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, put_data_callback);
curl_easy_perform(curl);
Here is my callback function.
struct put_data_t {
const char * data_start;
unsigned read_pos;
unsigned data_len;
};
size_t put_data_callback(void *buff, size_t size, size_t nmem, void* userp)
{
if (!userp)
return 0;
put_data_t *userdata = (put_data_t *)userp;
if (userdata->data_len <= 0)
return 0;
size_t curl_size = nmem*size;
std::ostringstream ss;
ss << "put_data_callback get " << curl_size << " data passed in " << userdata->data_len;
DCAL_logCritical(ss.str().c_str());
size_t to_copy = (userdata->data_len < curl_size) ? userdata->data_len : curl_size;
memcpy(buff, userdata->data_start + userdata->read_pos, to_copy);
userdata->data_len -= to_copy;
userdata->read_pos += to_copy;
return to_copy;
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-23