Revert "Update to 7.40.1"
[platform/upstream/curl.git] / lib / pingpong.c
index 2c2741f..c7e89d0 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -165,7 +165,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
   size_t write_len;
   char *fmt_crlf;
   char *s;
-  CURLcode result;
+  CURLcode error;
   struct connectdata *conn = pp->conn;
   struct SessionHandle *data = conn->data;
 
@@ -191,26 +191,26 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
 
   Curl_pp_init(pp);
 
-  result = Curl_convert_to_network(data, s, write_len);
+  error = Curl_convert_to_network(data, s, write_len);
   /* Curl_convert_to_network calls failf if unsuccessful */
-  if(result) {
+  if(error) {
     free(s);
-    return result;
+    return error;
   }
 
 #ifdef HAVE_GSSAPI
   conn->data_prot = PROT_CMD;
 #endif
-  result = Curl_write(conn, conn->sock[FIRSTSOCKET], s, write_len,
+  error = Curl_write(conn, conn->sock[FIRSTSOCKET], s, write_len,
                      &bytes_written);
 #ifdef HAVE_GSSAPI
   DEBUGASSERT(data_sec > PROT_NONE && data_sec < PROT_LAST);
   conn->data_prot = data_sec;
 #endif
 
-  if(result) {
+  if(error) {
     free(s);
-    return result;
+    return error;
   }
 
   if(conn->data->set.verbose)
@@ -247,15 +247,15 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
 CURLcode Curl_pp_sendf(struct pingpong *pp,
                        const char *fmt, ...)
 {
-  CURLcode result;
+  CURLcode res;
   va_list ap;
   va_start(ap, fmt);
 
-  result = Curl_pp_vsendf(pp, fmt, ap);
+  res = Curl_pp_vsendf(pp, fmt, ap);
 
   va_end(ap);
 
-  return result;
+  return res;
 }
 
 /*
@@ -285,6 +285,8 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
   /* number of bytes in the current line, so far */
   perline = (ssize_t)(ptr-pp->linestart_resp);
 
+  keepon=TRUE;
+
   while((pp->nread_resp<BUFSIZE) && (keepon && !result)) {
 
     if(pp->cache) {
@@ -303,28 +305,30 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
       pp->cache_size = 0; /* zero the size just in case */
     }
     else {
+      int res;
 #ifdef HAVE_GSSAPI
       enum protection_level prot = conn->data_prot;
       conn->data_prot = PROT_CLEAR;
 #endif
       DEBUGASSERT((ptr+BUFSIZE-pp->nread_resp) <= (buf+BUFSIZE+1));
-      result = Curl_read(conn, sockfd, ptr, BUFSIZE-pp->nread_resp,
-                         &gotbytes);
+      res = Curl_read(conn, sockfd, ptr, BUFSIZE-pp->nread_resp,
+                      &gotbytes);
 #ifdef HAVE_GSSAPI
       DEBUGASSERT(prot  > PROT_NONE && prot < PROT_LAST);
       conn->data_prot = prot;
 #endif
-      if(result == CURLE_AGAIN)
+      if(res == CURLE_AGAIN)
         return CURLE_OK; /* return */
 
-      if(!result && (gotbytes > 0))
+      if((res == CURLE_OK) && (gotbytes > 0))
         /* convert from the network encoding */
-        result = Curl_convert_from_network(data, ptr, gotbytes);
+        res = Curl_convert_from_network(data, ptr, gotbytes);
       /* Curl_convert_from_network calls failf if unsuccessful */
 
-      if(result)
-        /* Set outer result variable to this error. */
+      if(CURLE_OK != res) {
+        result = (CURLcode)res; /* Set outer result variable to this error. */
         keepon = FALSE;
+      }
     }
 
     if(!keepon)
@@ -474,9 +478,11 @@ CURLcode Curl_pp_flushsend(struct pingpong *pp)
   /* we have a piece of a command still left to send */
   struct connectdata *conn = pp->conn;
   ssize_t written;
+  CURLcode result = CURLE_OK;
   curl_socket_t sock = conn->sock[FIRSTSOCKET];
-  CURLcode result = Curl_write(conn, sock, pp->sendthis + pp->sendsize -
-                               pp->sendleft, pp->sendleft, &written);
+
+  result = Curl_write(conn, sock, pp->sendthis + pp->sendsize -
+                      pp->sendleft, pp->sendleft, &written);
   if(result)
     return result;