Я использую libcurl для библиотеки RESTful. У меня две проблемы с сообщением PUT, я просто пытаюсь отправить небольшой контент, например «привет», через put.
Моя READFUNCTION для PUT блокируется в течение очень большого количества времени (минут), когда я следую руководству на curl.haxx.se и возвращаю 0, указывающее, что я закончил контент. (на os X) Когда я возвращаю что-то> 0, это происходит намного быстрее (‹ 1 сек)
Когда я запускаю это на своей Linux-машине (ubuntu 10.4), это блокирующее событие НИКОГДА не возвращается, когда я возвращаю 0, если я изменю поведение, чтобы вернуть размер, написанный libcurl, добавляет все данные в тело http, отправляя больше данных, и это не удается с сообщением "слишком много данных" с сервера. моя функция чтения ниже, любая помощь будет принята с благодарностью. Я использую 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;
}
}