curl-library
[PATCH] lib/file.c: Add option to make writes unbuffered
From: Sebastian Rasmussen <sebrn_at_axis.com>
Date: Fri, 5 Oct 2012 11:15:12 +0200
Date: Fri, 5 Oct 2012 11:15:12 +0200
The default is, as it has been before, buffered writes.
--- docs/libcurl/curl_easy_setopt.3 | 4 ++++ docs/libcurl/symbols-in-versions | 1 + include/curl/curl.h | 3 +++ lib/file.c | 11 +++++++++++ lib/url.c | 7 +++++++ lib/urldata.h | 1 + 6 files changed, 27 insertions(+) diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3 index 3b0dc6c..2fb1d00 100644 --- a/docs/libcurl/curl_easy_setopt.3 +++ b/docs/libcurl/curl_easy_setopt.3 @@ -2507,6 +2507,10 @@ be assigned to newly created directories on the remote server. The default value is \fI0755\fP, but any valid value can be used. The only protocols that can use this are \fIsftp://\fP, \fIscp://\fP, and \fIfile://\fP. (Added in 7.16.4) +.IP CURLOPT_UNBUFFERED_WRITES +Pass a long. If set to 1, any writes for file uploads over the file protocol +will be unbuffered and will be flushed to the file system. Set to 0 (default +behavior) to keep writes buffered. (Added in 7.27.1) .SH TELNET OPTIONS .IP CURLOPT_TELNETOPTIONS Provide a pointer to a curl_slist with variables to pass to the telnet diff --git a/docs/libcurl/symbols-in-versions b/docs/libcurl/symbols-in-versions index 1de1ace..e69d449 100644 --- a/docs/libcurl/symbols-in-versions +++ b/docs/libcurl/symbols-in-versions @@ -503,6 +503,7 @@ CURLOPT_TLSAUTH_TYPE 7.21.4 CURLOPT_TLSAUTH_USERNAME 7.21.4 CURLOPT_TRANSFERTEXT 7.1.1 CURLOPT_TRANSFER_ENCODING 7.21.6 +CURLOPT_UNBUFFERED_WRITES 7.27.1 CURLOPT_UNRESTRICTED_AUTH 7.10.4 CURLOPT_UPLOAD 7.1 CURLOPT_URL 7.1 diff --git a/include/curl/curl.h b/include/curl/curl.h index 5b39a24..83087b4 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -1536,6 +1536,9 @@ typedef enum { /* set the SMTP auth originator */ CINIT(MAIL_AUTH, OBJECTPOINT, 217), + /* Enable unbuffered writes to the file system */ + CINIT(UNBUFFERED_WRITES, LONG, 218), + CURLOPT_LASTENTRY /* the last unused */ } CURLoption; diff --git a/lib/file.c b/lib/file.c index 1025022..9ce7549 100644 --- a/lib/file.c +++ b/lib/file.c @@ -364,6 +364,10 @@ static CURLcode file_upload(struct connectdata *conn) return CURLE_WRITE_ERROR; } + if(data->set.unbuffered_writes) { + setbuf(fp, NULL); + } + if(-1 != data->set.infilesize) /* known size of data to "upload" */ Curl_pgrsSetUploadSize(data, data->set.infilesize); @@ -413,6 +417,13 @@ static CURLcode file_upload(struct connectdata *conn) break; } + if(data->set.unbuffered_writes) { + int fd = fileno(fp); + if (fd != -1) { + fsync(fd); + } + } + bytecount += nread; Curl_pgrsSetUploadCounter(data, bytecount); diff --git a/lib/url.c b/lib/url.c index 8bbd3e4..8dc3210 100644 --- a/lib/url.c +++ b/lib/url.c @@ -757,6 +757,9 @@ CURLcode Curl_init_userdefined(struct UserDefined *set) set->tcp_keepintvl = 60; set->tcp_keepidle = 60; + /* the default is to use buffered writes for the file protocol */ + set->unbuffered_writes = FALSE; + return res; } @@ -2609,6 +2612,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, data->set.tcp_keepintvl = va_arg(param, long); break; + case CURLOPT_UNBUFFERED_WRITES: + data->set.unbuffered_writes = (0 != va_arg(param, long))?TRUE:FALSE; + break; + default: /* unknown tag and its companion, just ignore: */ result = CURLE_UNKNOWN_OPTION; diff --git a/lib/urldata.h b/lib/urldata.h index 5f893c9..dfee973 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -1594,6 +1594,7 @@ struct UserDefined { bool tcp_keepalive; /* use TCP keepalives */ long tcp_keepidle; /* seconds in idle before sending keepalive probe */ long tcp_keepintvl; /* seconds between TCP keepalive probes */ + bool unbuffered_writes; /* use unbuffered writes for the file procotol */ }; struct Names { -- 1.7.10.4 --------------010807060303070805020600 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html --------------010807060303070805020600--Received on 2001-09-17