--- transfer.c_old Tue Aug 17 16:36:07 2004 +++ transfer.c Tue Aug 17 16:36:13 2004 @@ -251,6 +251,7 @@ (!readfdp || FD_ISSET(conn->sockfd, readfdp))) { bool readdone = TRUE; + bool is_first_time = TRUE; /* This is where we loop until we have read everything there is to read or we get a EWOULDBLOCK */ @@ -281,7 +282,7 @@ didwhat |= KEEP_READ; /* NULL terminate, allowing string ops to be used */ - if (0 < nread) + if (0 < nread || (nread == 0 && is_first_time)) k->buf[nread] = 0; /* if we receive 0 or less here, the server closed the connection and @@ -922,7 +923,7 @@ /* 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_first_time)) { if(0 == k->bodywrites) { /* These checks are only made the first time we are about to @@ -1037,7 +1038,7 @@ Curl_pgrsSetDownloadCounter(data, k->bytecount); - if(!conn->bits.chunk && (nread || k->badheader)) { + if(!conn->bits.chunk && (nread || k->badheader || is_first_time)) { /* If this is chunky transfer, it was already written */ if(k->badheader && !k->ignorebody) { @@ -1093,6 +1094,18 @@ } } /* if (! header and data to read ) */ + + if (is_first_time) { + is_first_time = FALSE; + + /* if we receive 0 here, the server closed the connection + and we are done*/ + if (nread == 0) { + k->keepon &= ~KEEP_READ; + FD_ZERO(&k->rkeepfd); + readdone = TRUE; + } + } } while(!readdone);