aboutsummaryrefslogtreecommitdiff
path: root/lib/telnet.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2009-03-12 02:12:05 +0000
committerYang Tse <yangsita@gmail.com>2009-03-12 02:12:05 +0000
commitd15b8273d6bdb5f0aa590cce802ab75f9c3c3625 (patch)
tree32b485b6aa1b9d453570856aed5def27b408226d /lib/telnet.c
parent0a5cf3a9283883a209d6f447d84f4320ce2f4b7b (diff)
Add Curl_read() return code checking
Diffstat (limited to 'lib/telnet.c')
-rw-r--r--lib/telnet.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/telnet.c b/lib/telnet.c
index d0d211a6b..109e081d8 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -1200,6 +1200,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
int interval_ms;
struct pollfd pfd[2];
#endif
+ int ret;
ssize_t nread;
struct timeval now;
bool keepon = TRUE;
@@ -1370,8 +1371,23 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
break;
}
if(events.lNetworkEvents & FD_READ) {
- /* This reallu OUGHT to check its return code. */
- (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
+ /* 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)
+ 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);
@@ -1441,12 +1457,20 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
}
if(pfd[0].revents & POLLIN) {
- /* This OUGHT to check the return code... */
- (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
-
- /* if we receive 0 or less here, the server closed the connection and
- we bail out from this! */
- if(nread <= 0) {
+ /* 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)
+ 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;
}