Add Curl_read() return code checking

This commit is contained in:
Yang Tse 2009-03-12 02:12:05 +00:00
parent 0a5cf3a928
commit d15b8273d6
1 changed files with 32 additions and 8 deletions

View File

@ -1200,6 +1200,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
int interval_ms; int interval_ms;
struct pollfd pfd[2]; struct pollfd pfd[2];
#endif #endif
int ret;
ssize_t nread; ssize_t nread;
struct timeval now; struct timeval now;
bool keepon = TRUE; bool keepon = TRUE;
@ -1370,8 +1371,23 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
break; break;
} }
if(events.lNetworkEvents & FD_READ) { if(events.lNetworkEvents & FD_READ) {
/* This reallu OUGHT to check its return code. */ /* read data from network */
(void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread); ret = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
/* returned sub-zero, this would've blocked. Loop again */
if(ret < 0)
break;
/* returned not-zero, this an error */
else if(ret) {
keepon = FALSE;
code = (CURLcode)ret;
break;
}
/* returned zero but actually received 0 or less here,
the server closed the connection and we bail out */
else if(nread <= 0) {
keepon = FALSE;
break;
}
telrcv(conn, (unsigned char *)buf, nread); telrcv(conn, (unsigned char *)buf, nread);
@ -1441,12 +1457,20 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
} }
if(pfd[0].revents & POLLIN) { if(pfd[0].revents & POLLIN) {
/* This OUGHT to check the return code... */ /* read data from network */
(void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread); ret = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
/* returned sub-zero, this would've blocked. Loop again */
/* if we receive 0 or less here, the server closed the connection and if(ret < 0)
we bail out from this! */ break;
if(nread <= 0) { /* returned not-zero, this an error */
else if(ret) {
keepon = FALSE;
code = (CURLcode)ret;
break;
}
/* returned zero but actually received 0 or less here,
the server closed the connection and we bail out */
else if(nread <= 0) {
keepon = FALSE; keepon = FALSE;
break; break;
} }