|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tool_setup.h" |
|
|
|
|
|
#ifdef HAVE_SYS_SELECT_H |
|
|
#include <sys/select.h> |
|
|
#endif |
|
|
|
|
|
#include "curlx.h" |
|
|
|
|
|
#include "tool_cfgable.h" |
|
|
#include "tool_cb_rea.h" |
|
|
#include "tool_operate.h" |
|
|
#include "tool_util.h" |
|
|
#include "tool_msgs.h" |
|
|
#include "tool_sleep.h" |
|
|
|
|
|
#include "memdebug.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata) |
|
|
{ |
|
|
ssize_t rc = 0; |
|
|
struct per_transfer *per = userdata; |
|
|
struct OperationConfig *config = per->config; |
|
|
|
|
|
if((per->uploadfilesize != -1) && |
|
|
(per->uploadedsofar == per->uploadfilesize)) { |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
if(config->timeout_ms) { |
|
|
struct timeval now = tvnow(); |
|
|
long msdelta = tvdiff(now, per->start); |
|
|
|
|
|
if(msdelta > config->timeout_ms) |
|
|
|
|
|
return 0; |
|
|
#ifndef _WIN32 |
|
|
|
|
|
|
|
|
else { |
|
|
fd_set bits; |
|
|
struct timeval timeout; |
|
|
long wait = config->timeout_ms - msdelta; |
|
|
|
|
|
|
|
|
timeout.tv_sec = wait/1000; |
|
|
timeout.tv_usec = (int)((wait%1000)*1000); |
|
|
|
|
|
FD_ZERO(&bits); |
|
|
FD_SET(per->infd, &bits); |
|
|
if(!select(per->infd + 1, &bits, NULL, NULL, &timeout)) |
|
|
return 0; |
|
|
} |
|
|
#endif |
|
|
} |
|
|
|
|
|
rc = read(per->infd, buffer, sz*nmemb); |
|
|
if(rc < 0) { |
|
|
if(errno == EAGAIN) { |
|
|
errno = 0; |
|
|
config->readbusy = TRUE; |
|
|
return CURL_READFUNC_PAUSE; |
|
|
} |
|
|
|
|
|
rc = 0; |
|
|
} |
|
|
if((per->uploadfilesize != -1) && |
|
|
(per->uploadedsofar + rc > per->uploadfilesize)) { |
|
|
|
|
|
curl_off_t delta = per->uploadedsofar + rc - per->uploadfilesize; |
|
|
warnf(per->config->global, "File size larger in the end than when " |
|
|
"started. Dropping at least %" CURL_FORMAT_CURL_OFF_T " bytes", |
|
|
delta); |
|
|
rc = (ssize_t)(per->uploadfilesize - per->uploadedsofar); |
|
|
} |
|
|
config->readbusy = FALSE; |
|
|
|
|
|
|
|
|
return (size_t)rc; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tool_readbusy_cb(void *clientp, |
|
|
curl_off_t dltotal, curl_off_t dlnow, |
|
|
curl_off_t ultotal, curl_off_t ulnow) |
|
|
{ |
|
|
struct per_transfer *per = clientp; |
|
|
struct OperationConfig *config = per->config; |
|
|
|
|
|
(void)dltotal; |
|
|
(void)dlnow; |
|
|
(void)ultotal; |
|
|
(void)ulnow; |
|
|
|
|
|
if(config->readbusy) { |
|
|
|
|
|
|
|
|
static long rate = 500; |
|
|
static struct timeval prev; |
|
|
static curl_off_t ulprev; |
|
|
|
|
|
if(ulprev == ulnow) { |
|
|
|
|
|
struct timeval now = tvnow(); |
|
|
if(prev.tv_sec) |
|
|
|
|
|
|
|
|
rate -= rate/4 - tvdiff(now, prev)/4; |
|
|
prev = now; |
|
|
} |
|
|
else { |
|
|
rate = 50; |
|
|
ulprev = ulnow; |
|
|
} |
|
|
if(rate >= 50) { |
|
|
|
|
|
config->readbusy = FALSE; |
|
|
curl_easy_pause(per->curl, CURLPAUSE_CONT); |
|
|
} |
|
|
else |
|
|
|
|
|
tool_go_sleep(25); |
|
|
} |
|
|
|
|
|
return per->noprogress ? 0 : CURL_PROGRESSFUNC_CONTINUE; |
|
|
} |
|
|
|