Alexander Krasnostavsky made the write callback get called even when a zero

byte file is downloaded.
This commit is contained in:
Daniel Stenberg 2004-08-20 12:09:09 +00:00
parent c3d74ffe48
commit cd52b9f0da
4 changed files with 20 additions and 11 deletions

View File

@ -6,6 +6,10 @@
Changelog
Daniel (20 August 2004)
- Alexander Krasnostavsky made the write callback get called even when a zero
byte file is downloaded.
Daniel (18 August 2004)
- Ling Thio pointed out that when libcurl is built ipv6-enabled, it still did
reverse DNS lookups when fed with a numerical IP-address (like

View File

@ -14,6 +14,7 @@ This release includes the following changes:
This release includes the following bugfixes:
o downloading empty files now calls the write callback properly
o no more reverse DNS lookups when getting ip-only address with ipv6-enabled
libcurl
o libcurl works better multi-threaded on AIX (when built with xlc)

View File

@ -44,10 +44,6 @@ may have been fixed since this was written!
libcurl thinks of it as the *compressed* lenght. Some explanations are here:
http://curl.haxx.se/mail/lib-2003-06/0146.html
* Downloading 0 (zero) bytes files over FTP will not create a zero byte file
locally, which is because libcurl doesn't call the write callback with zero
bytes. Explained here: http://curl.haxx.se/mail/archive-2003-04/0143.html
* IPv6 support on AIX 4.3.3 doesn't work due to a missing sockaddr_storage
struct. It has been reported to work on AIX 5.1 though.

View File

@ -250,7 +250,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if((k->keepon & KEEP_READ) &&
(!readfdp || FD_ISSET(conn->sockfd, readfdp))) {
bool readdone = TRUE;
bool is_empty_data = FALSE;
/* This is where we loop until we have read everything there is to
read or we get a EWOULDBLOCK */
@ -279,9 +279,11 @@ CURLcode Curl_readwrite(struct connectdata *conn,
}
didwhat |= KEEP_READ;
/* indicates data of zero size, i.e. empty file */
is_empty_data = (nread == 0 && k->bodywrites == 0);
/* NULL terminate, allowing string ops to be used */
if (0 < nread)
if (0 < nread || is_empty_data)
k->buf[nread] = 0;
/* if we receive 0 or less here, the server closed the connection and
@ -289,7 +291,6 @@ CURLcode Curl_readwrite(struct connectdata *conn,
else if (0 >= nread) {
k->keepon &= ~KEEP_READ;
FD_ZERO(&k->rkeepfd);
readdone = TRUE;
break;
}
@ -922,9 +923,9 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* This is not an 'else if' since it may be a rest from the header
parsing, where the beginning of the buffer is headers and the end
is non-headers. */
if (k->str && !k->header && (nread > 0)) {
if (k->str && !k->header && (nread > 0 || is_empty_data)) {
if(0 == k->bodywrites) {
if(0 == k->bodywrites && !is_empty_data) {
/* These checks are only made the first time we are about to
write a piece of the body */
if(conn->protocol&PROT_HTTP) {
@ -1037,7 +1038,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
Curl_pgrsSetDownloadCounter(data, k->bytecount);
if(!conn->bits.chunk && (nread || k->badheader)) {
if(!conn->bits.chunk && (nread || k->badheader || is_empty_data)) {
/* If this is chunky transfer, it was already written */
if(k->badheader && !k->ignorebody) {
@ -1094,7 +1095,14 @@ CURLcode Curl_readwrite(struct connectdata *conn,
} /* if (! header and data to read ) */
} while(!readdone);
if (is_empty_data) {
/* if we received nothing, the server closed the connection and we
are done */
k->keepon &= ~KEEP_READ;
FD_ZERO(&k->rkeepfd);
}
} while(0);
} /* if( read from socket ) */