diff --git a/lib/easy.c b/lib/easy.c index 53f417f..637d99b 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -1108,7 +1108,6 @@ CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n) { curl_socket_t sfd; CURLcode ret; - int ret1; ssize_t n1; struct connectdata *c; struct SessionHandle *data = (struct SessionHandle *)curl; @@ -1118,13 +1117,10 @@ CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n) return ret; *n = 0; - ret1 = Curl_read(c, sfd, buffer, buflen, &n1); + ret = Curl_read(c, sfd, buffer, buflen, &n1); - if(ret1 == -1) - return CURLE_AGAIN; - - if(ret1 != CURLE_OK) - return (CURLcode)ret1; + if(ret != CURLE_OK) + return ret; *n = (size_t)n1; diff --git a/lib/http.c b/lib/http.c index fc01ee8..d510e6a 100644 --- a/lib/http.c +++ b/lib/http.c @@ -1283,7 +1283,6 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn, struct SessionHandle *data=conn->data; struct SingleRequest *k = &data->req; CURLcode result; - int res; long timeout = data->set.timeout?data->set.timeout:PROXY_TIMEOUT; /* in milliseconds */ curl_socket_t tunnelsocket = conn->sock[sockindex]; @@ -1467,11 +1466,10 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn, break; default: DEBUGASSERT(ptr+BUFSIZE-nread <= data->state.buffer+BUFSIZE+1); - res = Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread, &gotbytes); - if(res< 0) - /* EWOULDBLOCK */ + result = Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread, &gotbytes); + if(result==CURLE_AGAIN) continue; /* go loop yourself */ - else if(res) + else if(result) keepon = FALSE; else if(gotbytes <= 0) { keepon = FALSE; diff --git a/lib/pingpong.c b/lib/pingpong.c index c6b6f2f..6172833 100644 --- a/lib/pingpong.c +++ b/lib/pingpong.c @@ -340,8 +340,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd, #if defined(HAVE_KRB4) || defined(HAVE_GSSAPI) conn->data_prot = prot; #endif - if(res < 0) - /* EWOULDBLOCK */ + if(res == CURLE_AGAIN) return CURLE_OK; /* return */ #ifdef CURL_DOES_CONVERSIONS diff --git a/lib/sendf.c b/lib/sendf.c index 4843214..1693a46 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -238,7 +238,7 @@ CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn, * Curl_write() is an internal write function that sends data to the * server. Works with plain sockets, SCP, SSL or kerberos. * - * If the write would block (EWOULDBLOCK), we return CURLE_OK and + * If the write would block (CURLE_AGAIN), we return CURLE_OK and * (*written == 0). Otherwise we return regular CURLcode value. */ CURLcode Curl_write(struct connectdata *conn, @@ -258,7 +258,7 @@ CURLcode Curl_write(struct connectdata *conn, /* we completely ignore the curlcode value when -1 is not returned */ return CURLE_OK; - /* handle EWOULDBLOCK or a send failure */ + /* handle CURLE_AGAIN or a send failure */ switch(curlcode) { case CURLE_AGAIN: *written = 0; @@ -437,7 +437,7 @@ CURLcode Curl_client_write(struct connectdata *conn, return CURLE_OK; } -int Curl_read_plain(curl_socket_t sockfd, +CURLcode Curl_read_plain(curl_socket_t sockfd, char *buf, size_t bytesfromsocket, ssize_t *n) @@ -451,7 +451,7 @@ int Curl_read_plain(curl_socket_t sockfd, #else if((EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err)) #endif - return -1; + return CURLE_AGAIN; else return CURLE_RECV_ERROR; } @@ -465,10 +465,9 @@ int Curl_read_plain(curl_socket_t sockfd, * 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. + * Returns a regular CURLcode value. */ -int Curl_read(struct connectdata *conn, /* connection data */ +CURLcode Curl_read(struct connectdata *conn, /* connection data */ curl_socket_t sockfd, /* read from this socket */ char *buf, /* store read data here */ size_t sizerequested, /* max amount to read */ diff --git a/lib/sendf.h b/lib/sendf.h index 5732a0b..ed3b3a5 100644 --- a/lib/sendf.h +++ b/lib/sendf.h @@ -55,13 +55,13 @@ CURLcode Curl_client_write(struct connectdata *conn, int type, char *ptr, size_t len); /* internal read-function, does plain socket only */ -int Curl_read_plain(curl_socket_t sockfd, +CURLcode Curl_read_plain(curl_socket_t sockfd, char *buf, size_t bytesfromsocket, ssize_t *n); /* internal read-function, does plain socket, SSL and krb4 */ -int Curl_read(struct connectdata *conn, curl_socket_t sockfd, +CURLcode Curl_read(struct connectdata *conn, curl_socket_t sockfd, char *buf, size_t buffersize, ssize_t *n); /* internal write-function, does plain socket, SSL, SCP, SFTP and krb4 */ diff --git a/lib/telnet.c b/lib/telnet.c index e7f05eb..b94415d 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -1209,7 +1209,6 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done) struct pollfd pfd[2]; int poll_cnt; #endif - int ret; ssize_t nread; struct timeval now; bool keepon = TRUE; @@ -1383,14 +1382,13 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done) } if(events.lNetworkEvents & FD_READ) { /* read data from network */ - ret = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread); - /* returned sub-zero, this would've blocked. Loop again */ - if(ret < 0) + code = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread); + /* read would've blocked. Loop again */ + if(code == CURLE_AGAIN) break; /* returned not-zero, this an error */ - else if(ret) { + else if(code) { keepon = FALSE; - code = (CURLcode)ret; break; } /* returned zero but actually received 0 or less here, @@ -1472,14 +1470,13 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done) default: /* read! */ if(pfd[0].revents & POLLIN) { /* read data from network */ - ret = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread); - /* returned sub-zero, this would've blocked. Loop again */ - if(ret < 0) + code = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread); + /* read would've blocked. Loop again */ + if(code == CURLE_AGAIN) break; /* returned not-zero, this an error */ - else if(ret) { + else if(code) { keepon = FALSE; - code = (CURLcode)ret; break; } /* returned zero but actually received 0 or less here, diff --git a/lib/transfer.c b/lib/transfer.c index 92a59d0..c9234a7 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -376,12 +376,11 @@ static CURLcode readwrite_data(struct SessionHandle *data, *done = FALSE; /* This is where we loop until we have read everything there is to - read or we get a EWOULDBLOCK */ + read or we get a CURLE_AGAIN */ do { size_t buffersize = data->set.buffer_size? data->set.buffer_size : BUFSIZE; size_t bytestoread = buffersize; - int readrc; if(k->size != -1 && !k->header) { /* make sure we don't read "too much" if we can help it since we @@ -394,15 +393,12 @@ static CURLcode readwrite_data(struct SessionHandle *data, if(bytestoread) { /* receive data from the network! */ - readrc = Curl_read(conn, conn->sockfd, k->buf, bytestoread, &nread); + result = Curl_read(conn, conn->sockfd, k->buf, bytestoread, &nread); - /* subzero, this would've blocked */ - if(0 > readrc) + /* read would've blocked */ + if(CURLE_AGAIN == result) break; /* get out of loop */ - /* get the CURLcode from the int */ - result = (CURLcode)readrc; - if(result>0) return result; }