--- transfer.c.old	2007-01-24 22:02:12.000000000 +0530
+++ transfer.c.new	2007-01-24 22:05:10.000000000 +0530
@@ -259,9 +259,12 @@
 /* FIX: this is nasty OpenSSL-specific code that really shouldn't be here */
 static int data_pending(struct connectdata *conn)
 {
-  if(conn->ssl[FIRSTSOCKET].handle)
+    int ret;
+  if(conn->ssl[FIRSTSOCKET].handle){
     /* SSL is in use */
-    return SSL_pending(conn->ssl[FIRSTSOCKET].handle);
+    ret = SSL_pending(conn->ssl[FIRSTSOCKET].handle);
+    return ret;
+  }
 
   return 0; /* nothing */
 }
@@ -282,6 +285,7 @@
   CURLcode result;
   ssize_t nread; /* number of bytes read */
   int didwhat=0;
+  int readrc;
 
   curl_socket_t fd_read;
   curl_socket_t fd_write;
@@ -319,7 +323,7 @@
           data->set.buffer_size:BUFSIZE;
 
         /* receive data from the network! */
-        int readrc = Curl_read(conn, conn->sockfd, k->buf, buffersize, &nread);
+        readrc = Curl_read(conn, conn->sockfd, k->buf, buffersize, &nread);
 
         /* subzero, this would've blocked */
         if(0>readrc)
@@ -327,6 +331,7 @@
 
         /* get the CURLcode from the int */
         result = (CURLcode)readrc;
+        readrc = nread; /* Bug FIX */
 
         if(result>0)
           return result;
@@ -1205,7 +1210,7 @@
           k->keepon &= ~KEEP_READ;
         }
 
-      } while(data_pending(conn));
+      } while(data_pending(conn) || (readrc > 0));
 
     } /* if( read from socket ) */
 
