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.
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 */
}
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
else if (0 >= nread) {
k->keepon &= ~KEEP_READ;
FD_ZERO(&k->rkeepfd);
- readdone = TRUE;
break;
}
/* 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) {
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) {
} /* 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 ) */