]> granicus.if.org Git - curl/commitdiff
- Eric Wong introduced curlx_nonblock() that the curl tool now (re-)uses for
authorDaniel Stenberg <daniel@haxx.se>
Thu, 9 Jul 2009 21:47:24 +0000 (21:47 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 9 Jul 2009 21:47:24 +0000 (21:47 +0000)
  setting a file descriptor non-blocking. Used by the functionality Eric
  himself brough on June 15th.

CHANGES
lib/Makefile.inc
lib/connect.c
lib/connect.h
lib/curlx.h
lib/ftp.c
lib/socks.c
src/Makefile.inc
src/main.c

diff --git a/CHANGES b/CHANGES
index 5c275a5e7a2248837a3b8ec7bf80c6c3de269d02..18bca2706a0e39855fc9ef060b4f672fea307afc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,11 @@
 
                                   Changelog
 
+Daniel Stenberg (9 Jul 2009)
+- Eric Wong introduced curlx_nonblock() that the curl tool now (re-)uses for
+  setting a file descriptor non-blocking. Used by the functionality Eric
+  himself brough on June 15th.
+
 Daniel Stenberg (8 Jul 2009)
 - Constantine Sapuntzakis posted bug report #2813123
   (http://curl.haxx.se/bug/view.cgi?id=2813123) and an a patch that fixes the
index 412f5dece01bc45708eddf7d6c7378f3ac5778d2..99a6a723c95dc7ab70b1b2f3d4a09ebb1f00477a 100644 (file)
@@ -10,7 +10,7 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c   \
   hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c       \
   inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c      \
   strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c          \
-  socks_gssapi.c socks_sspi.c curl_sspi.c slist.c
+  socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c
 
 HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h      \
   progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h     \
@@ -21,4 +21,4 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h     \
   strtoofft.h strerror.h inet_ntop.h curlx.h curl_memory.h setup.h     \
   transfer.h select.h easyif.h multiif.h parsedate.h sslgen.h gtls.h   \
   tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h ssh.h nssg.h \
-  curl_base64.h rawstr.h curl_addrinfo.h curl_sspi.h slist.h
+  curl_base64.h rawstr.h curl_addrinfo.h curl_sspi.h slist.h nonblock.h
index 49914e82f6bac6320d77c3a9cfeee7591b293a79..7865216bd080a08d375dc5b4f42f81cf6056a402 100644 (file)
@@ -177,59 +177,6 @@ long Curl_timeleft(struct connectdata *conn,
   return timeout_ms;
 }
 
-
-/*
- * Curl_nonblock() set the given socket to either blocking or non-blocking
- * mode based on the 'nonblock' boolean argument. This function is highly
- * portable.
- */
-int Curl_nonblock(curl_socket_t sockfd,    /* operate on this */
-                  int nonblock   /* TRUE or FALSE */)
-{
-#if defined(USE_BLOCKING_SOCKETS)
-
-  return 0; /* returns success */
-
-#elif defined(HAVE_FCNTL_O_NONBLOCK)
-
-  /* most recent unix versions */
-  int flags;
-  flags = fcntl(sockfd, F_GETFL, 0);
-  if(FALSE != nonblock)
-    return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
-  else
-    return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
-
-#elif defined(HAVE_IOCTL_FIONBIO)
-
-  /* older unix versions */
-  int flags;
-  flags = nonblock;
-  return ioctl(sockfd, FIONBIO, &flags);
-
-#elif defined(HAVE_IOCTLSOCKET_FIONBIO)
-
-  /* Windows */
-  unsigned long flags;
-  flags = nonblock;
-  return ioctlsocket(sockfd, FIONBIO, &flags);
-
-#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO)
-
-  /* Amiga */
-  return IoctlSocket(sockfd, FIONBIO, (long)nonblock);
-
-#elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK)
-
-  /* BeOS */
-  long b = nonblock ? 1 : 0;
-  return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
-
-#else
-#  error "no non-blocking method was found/used/set"
-#endif
-}
-
 /*
  * waitconnect() waits for a TCP connect on the given socket for the specified
  * number if milliseconds. It returns:
@@ -846,7 +793,7 @@ singleipconnect(struct connectdata *conn,
   }
 
   /* set socket non-blocking */
-  Curl_nonblock(sockfd, TRUE);
+  curlx_nonblock(sockfd, TRUE);
 
   /* Connect TCP sockets, bind UDP */
   if(conn->socktype == SOCK_STREAM)
index ae47c21745400f97036b67f34cba0a5899335a72..e8261776a9a0bfadb85953f8968e15675b8a7604 100644 (file)
@@ -23,8 +23,7 @@
  * $Id$
  ***************************************************************************/
 
-int Curl_nonblock(curl_socket_t sockfd,    /* operate on this */
-                  int nonblock   /* TRUE or FALSE */);
+#include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
 
 CURLcode Curl_is_connected(struct connectdata *conn,
                            int sockindex,
index 9558845e98295c4312dd973c6f78af4e01c34e0a..1e03a05fcfa5c13da60b831377eb97e742d5c12a 100644 (file)
@@ -53,6 +53,9 @@
   curlx_tvdiff_secs()
 */
 
+#include "nonblock.h"
+/* "nonblock.h" provides curlx_nonblock() */
+
 /* Now setup curlx_ * names for the functions that are to become curlx_ and
    be removed from a future libcurl official API:
    curlx_getenv
index 8360e585934351603fe26e72f189116c69269155..d2a80e07f4746b595ddc960bf93d62757e14ed57 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -351,7 +351,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
       infof(data, "Connection accepted from server\n");
 
       conn->sock[SECONDARYSOCKET] = s;
-      Curl_nonblock(s, TRUE); /* enable non-blocking */
+      curlx_nonblock(s, TRUE); /* enable non-blocking */
     }
     break;
   }
index 826e1383a4971b349bb54089cabff9b68189b8ca..fba0bef3828da0388645193e8a50a56de09aa666 100644 (file)
@@ -144,7 +144,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
     return CURLE_OPERATION_TIMEDOUT;
   }
 
-  Curl_nonblock(sock, FALSE);
+  curlx_nonblock(sock, FALSE);
 
   /*
    * Compose socks4 request
@@ -344,7 +344,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
     }
   }
 
-  Curl_nonblock(sock, TRUE);
+  curlx_nonblock(sock, TRUE);
 
   return CURLE_OK; /* Proxy was successful! */
 }
@@ -406,7 +406,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
     return CURLE_OPERATION_TIMEDOUT;
   }
 
-  Curl_nonblock(sock, TRUE);
+  curlx_nonblock(sock, TRUE);
 
   /* wait until socket gets connected */
   result = Curl_socket_ready(CURL_SOCKET_BAD, sock, (int)timeout);
@@ -437,7 +437,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
   socksreq[3] = 2; /* username/password */
 #endif
 
-  Curl_nonblock(sock, FALSE);
+  curlx_nonblock(sock, FALSE);
 
   code = Curl_write_plain(conn, sock, (char *)socksreq, (2 + (int)socksreq[1]),
                           &written);
@@ -446,7 +446,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
     return CURLE_COULDNT_CONNECT;
   }
 
-  Curl_nonblock(sock, TRUE);
+  curlx_nonblock(sock, TRUE);
 
   result = Curl_socket_ready(sock, CURL_SOCKET_BAD, (int)timeout);
 
@@ -464,7 +464,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
     return CURLE_RECV_ERROR;
   }
 
-  Curl_nonblock(sock, FALSE);
+  curlx_nonblock(sock, FALSE);
 
   result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread,
                             timeout);
@@ -719,7 +719,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
   }
 #endif
 
-  Curl_nonblock(sock, TRUE);
+  curlx_nonblock(sock, TRUE);
   return CURLE_OK; /* Proxy was successful! */
 }
 
index e0c132137c6ab989e7751e827a901d294e2fff56..8ea5dae4d3ae23d2c79b2645970e1fcd812ae7bb 100644 (file)
@@ -4,7 +4,8 @@
 # the official API, but we re-use the code here to avoid duplication.
 CURLX_ONES =  $(top_srcdir)/lib/strtoofft.c \
        $(top_srcdir)/lib/strdup.c \
-       $(top_srcdir)/lib/rawstr.c 
+       $(top_srcdir)/lib/rawstr.c \
+       $(top_srcdir)/lib/nonblock.c
 
 CURL_SOURCES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
        getpass.c homedir.c curlutil.c os-specific.c
index 87674b83a49100603356c0e3540acf5f657f1edc..b3c470f4493b6f6e34562faa43e9efae43463489 100644 (file)
@@ -3231,22 +3231,6 @@ static void go_sleep(long ms)
 #endif
 }
 
-/* maybe we could just use Curl_nonblock() instead ... */
-static void set_nonblocking(struct Configurable *config, int fd)
-{
-#if defined(HAVE_FCNTL_O_NONBLOCK)
-  int flags = fcntl(fd, F_GETFL, 0);
-
-  if (flags >= 0)
-    flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
-  else
-    warnf(config, "fcntl failed on fd=%d: %s\n", fd, strerror(errno));
-#else
-  (void) config;
-  (void) fd;
-#endif
-}
-
 static size_t my_fwrite(void *buffer, size_t sz, size_t nmemb, void *stream)
 {
   size_t rc;
@@ -4523,7 +4507,8 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
         else if(uploadfile && curlx_strequal(uploadfile, "-")) {
           SET_BINMODE(stdin);
           infd = STDIN_FILENO;
-          set_nonblocking(config, infd);
+          if (curlx_nonblock((curl_socket_t)infd, TRUE) < 0)
+            warnf(config, "fcntl failed on fd=%d: %s\n", infd, strerror(errno));
         }
 
         if(uploadfile && config->resume_from_current)