libcurl (c api) READFUNCTION for http PUT blocking forever
Posted
by Duane
on Stack Overflow
See other posts from Stack Overflow
or by Duane
Published on 2010-06-09T21:18:03Z
Indexed on
2010/06/09
21:22 UTC
Read the original article
Hit count: 233
I am using libcurl for a RESTful library. I am having two problems with a PUT message, I am just trying to send a small content like "hello" via put.
My READFUNCTION for PUT's blocks for a very large amount of time (minutes) when I follow the manual at curl.haxx.se and return a 0 indicating I have finished the content. (on os X) When I return something > 0 this succeeds much faster (< 1 sec)
When I run this on my linux machine (ubuntu 10.4) this blocking event appears to NEVER return when I return 0, if I change the behavior to return the size written libcurl appends all the data in the http body sending way more data and it fails with a "too much data" message from the server. my readfunction is below, any help would be greatly appreciated.
I am using libcurl 7.20.1
typedef struct{ void *data; int body_size; int bytes_remaining; int bytes_written;
} postdata;
size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream) {
if(stream) {
postdata ud = (postdata)stream;
if(ud->bytes_remaining) {
if(ud->body_size > size*nmemb) {
memcpy(ptr, ud->data+ud->bytes_written, size*nmemb);
ud->bytes_written+=size+nmemb;
ud->bytes_remaining = ud->body_size-size*nmemb;
return size*nmemb;
} else {
memcpy(ptr, ud->data+ud->bytes_written, ud->bytes_remaining);
ud->bytes_remaining=0;
return 0; } }
© Stack Overflow or respective owner