diff options
author | Daniel Stenberg <daniel@haxx.se> | 2008-01-10 10:30:19 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2008-01-10 10:30:19 +0000 |
commit | 18faa509403c39b4914114cfe2966241b62b2959 (patch) | |
tree | bb5e0bf7ac66a313e62263348449afbe4ad924c6 /src | |
parent | 0ce484eed901f73cae89e25d9939a249729f15d3 (diff) |
Georg Lippitsch brought CURLOPT_SEEKFUNCTION and CURLOPT_SEEKDATA to allow
libcurl to seek in a given input stream. This is particularly important when
doing upload resumes when there's already a huge part of the file present
remotely. Before, and still if this callback isn't used, libcurl will read
and through away the entire file up to the point to where the resuming
begins (which of course can be a slow opereration depending on file size,
I/O bandwidth and more). This new function will also be preferred to get
used instead of the CURLOPT_IOCTLFUNCTION for seeking back in a stream when
doing multi-stage HTTP auth with POST/PUT.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c index c86bf2fe7..2b6cf4ab8 100644 --- a/src/main.c +++ b/src/main.c @@ -3020,6 +3020,7 @@ struct InStruct { struct Configurable *config; }; +#if 1 static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) { struct InStruct *in=(struct InStruct *)userp; @@ -3040,6 +3041,24 @@ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) } return CURLIOE_OK; } +#else +static int my_seek(void *stream, curl_off_t offset, int whence) +{ + struct InStruct *in=(struct InStruct *)stream; + + /* We can't use fseek() here since it can't do 64bit seeks on Windows and + possibly elsewhere. We need to switch to the lseek family of tricks. For + that to work, we need to switch from fread() to plain read() etc */ + + if(-1 == fseek(in->stream, (off_t)offset, whence)) + /* couldn't rewind, the reason is in errno but errno is just not + portable enough and we don't actually care that much why we failed. */ + return 1; + + return 0; +} + +#endif static size_t my_fread(void *buffer, size_t sz, size_t nmemb, void *userp) { @@ -4270,10 +4289,17 @@ operate(struct Configurable *config, int argc, argv_item_t argv[]) /* what call to read */ my_setopt(curl, CURLOPT_READFUNCTION, my_fread); +#if 1 /* the ioctl function is at this point only used to rewind files that are posted when using NTLM etc */ my_setopt(curl, CURLOPT_IOCTLDATA, &input); my_setopt(curl, CURLOPT_IOCTLFUNCTION, my_ioctl); +#else + /* in 7.18.0, the SEEKFUNCTION/DATA pair is taking over what IOCTL* + previously provided for seeking */ + my_setopt(curl, CURLOPT_SEEKDATA, &input); + my_setopt(curl, CURLOPT_SEEKFUNCTION, my_seek); +#endif if(config->recvpersecond) /* tell libcurl to use a smaller sized buffer as it allows us to |