aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-01-14 23:14:59 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-01-14 23:14:59 +0000
commit4931fbce49887f7d4022c39ea7d94c4294b5f479 (patch)
treede5a20a6d1624ad07fe7509e10900773160d711b
parentfefc7ea6008c48cbc3c346da4da55169da8c3adc (diff)
Curl_read() now returns a negative return code if EWOULDBLOCK or similar
-rw-r--r--lib/ftp.c13
-rw-r--r--lib/http.c9
-rw-r--r--lib/sendf.c26
-rw-r--r--lib/sendf.h6
-rw-r--r--lib/telnet.c2
-rw-r--r--lib/transfer.c17
6 files changed, 53 insertions, 20 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index 1acf2dd7e..2def61f08 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -267,9 +267,16 @@ int Curl_GetFTPResponse(char *buf,
ftp->cache = NULL; /* clear the pointer */
ftp->cache_size = 0; /* zero the size just in case */
}
- else if(CURLE_OK != Curl_read(conn, sockfd, ptr,
- BUFSIZE-nread, &gotbytes))
- keepon = FALSE;
+ else {
+ int res = Curl_read(conn, sockfd, ptr,
+ BUFSIZE-nread, &gotbytes);
+ if(res < 0)
+ /* EWOULDBLOCK */
+ continue; /* go looping again */
+
+ if(CURLE_OK != res)
+ keepon = FALSE;
+ }
if(!keepon)
;
diff --git a/lib/http.c b/lib/http.c
index ffb442089..795a6f79c 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -235,6 +235,7 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
int subversion=0;
struct SessionHandle *data=conn->data;
CURLcode result;
+ int res;
int nread; /* total size read */
int perline; /* count bytes per line */
@@ -317,8 +318,12 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
* to read, but when we use Curl_read() it may do so. Do confirm
* that this is still ok and then remove this comment!
*/
- if(CURLE_OK != Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread,
- &gotbytes))
+ res= Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread,
+ &gotbytes);
+ if(res< 0)
+ /* EWOULDBLOCK */
+ continue; /* go loop yourself */
+ else if(res)
keepon = FALSE;
else if(gotbytes <= 0) {
keepon = FALSE;
diff --git a/lib/sendf.c b/lib/sendf.c
index 78581f585..afb6991d6 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -266,14 +266,18 @@ CURLcode Curl_client_write(struct SessionHandle *data,
return CURLE_OK;
}
-
/*
* Internal read-from-socket function. This is meant to deal with plain
* sockets, SSL sockets and kerberos sockets.
+ *
+ * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
+ * a regular CURLcode value.
*/
-CURLcode Curl_read(struct connectdata *conn, int sockfd,
- char *buf, size_t buffersize,
- ssize_t *n)
+int Curl_read(struct connectdata *conn,
+ int sockfd,
+ char *buf,
+ size_t buffersize,
+ ssize_t *n)
{
ssize_t nread;
@@ -300,7 +304,9 @@ CURLcode Curl_read(struct connectdata *conn, int sockfd,
/* if there's data pending, then we re-invoke SSL_read() */
break;
}
- } while(loop && SSL_pending(conn->ssl.handle));
+ } while(0);
+ if(loop && SSL_pending(conn->ssl.handle))
+ return -1; /* basicly EWOULDBLOCK */
}
else {
#endif
@@ -310,6 +316,16 @@ CURLcode Curl_read(struct connectdata *conn, int sockfd,
else
#endif
nread = sread (sockfd, buf, buffersize);
+
+ if(-1 == nread) {
+#ifdef WIN32
+ if(EWOULDBLOCK == GetLastError())
+#else
+ if(EWOULDBLOCK == errno)
+#endif
+ return -1;
+ }
+
#ifdef USE_SSLEAY
}
#endif /* USE_SSLEAY */
diff --git a/lib/sendf.h b/lib/sendf.h
index b23191416..7b6cff7de 100644
--- a/lib/sendf.h
+++ b/lib/sendf.h
@@ -45,9 +45,9 @@ CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr,
size_t len);
/* internal read-function, does plain socket, SSL and krb4 */
-CURLcode Curl_read(struct connectdata *conn, int sockfd,
- char *buf, size_t buffersize,
- ssize_t *n);
+int Curl_read(struct connectdata *conn, int sockfd,
+ char *buf, size_t buffersize,
+ ssize_t *n);
/* internal write-function, does plain socket, SSL and krb4 */
CURLcode Curl_write(struct connectdata *conn, int sockfd,
void *mem, size_t len,
diff --git a/lib/telnet.c b/lib/telnet.c
index a46e0196c..5dfed6970 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -1116,6 +1116,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
{
if(events.lNetworkEvents & FD_READ)
{
+ /* This reallu OUGHT to check its return code. */
Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
telrcv(conn, (unsigned char *)buf, nread);
@@ -1176,6 +1177,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
}
if(FD_ISSET(sockfd, &readfd)) {
+ /* This OUGHT to check the return code... */
Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
/* if we receive 0 or less here, the server closed the connection and
diff --git a/lib/transfer.c b/lib/transfer.c
index 2985cd654..4111653b1 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -173,7 +173,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
{
struct Curl_transfer_keeper *k = &conn->keep;
struct SessionHandle *data = conn->data;
- CURLcode result;
+ int result;
ssize_t nread; /* number of bytes read */
int didwhat=0;
@@ -181,18 +181,21 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if((k->keepon & KEEP_READ) &&
FD_ISSET(conn->sockfd, &k->readfd)) {
- if ((k->bytecount == 0) && (k->writebytecount == 0))
- Curl_pgrsTime(data, TIMER_STARTTRANSFER);
-
- didwhat |= KEEP_READ;
-
/* read! */
result = Curl_read(conn, conn->sockfd, k->buf,
BUFSIZE -1, &nread);
- if(result)
+ if(0>result)
+ break; /* get out of loop */
+ if(result>0)
return result;
+ if ((k->bytecount == 0) && (k->writebytecount == 0))
+ Curl_pgrsTime(data, TIMER_STARTTRANSFER);
+
+
+ didwhat |= KEEP_READ;
+
/* NULL terminate, allowing string ops to be used */
if (0 < (signed int) nread)
k->buf[nread] = 0;