]> granicus.if.org Git - curl/commitdiff
Use curl_socket_t instead of int for holding sockets. The typedefs and
authorDaniel Stenberg <daniel@haxx.se>
Tue, 9 Mar 2004 22:52:50 +0000 (22:52 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 9 Mar 2004 22:52:50 +0000 (22:52 +0000)
defines are in setup.h.

15 files changed:
lib/connect.c
lib/connect.h
lib/dict.c
lib/ftp.c
lib/http.c
lib/multi.c
lib/sendf.c
lib/sendf.h
lib/setup.h
lib/ssluse.c
lib/ssluse.h
lib/telnet.c
lib/transfer.c
lib/transfer.h
lib/urldata.h

index 1aedcbfcf073b465746bad03711e87cc297f0aaf..dd440158511c713c2114ff85cd081d8f7c49e4a3 100644 (file)
@@ -86,7 +86,7 @@
 #include "memdebug.h"
 #endif
 
-static bool verifyconnect(int sockfd);
+static bool verifyconnect(curl_socket_t sockfd);
 
 int Curl_ourerrno(void)
 {
@@ -104,7 +104,7 @@ int Curl_ourerrno(void)
  *  Set the socket to either blocking or non-blocking mode.
  */
 
-int Curl_nonblock(int sockfd,    /* operate on this */
+int Curl_nonblock(curl_socket_t sockfd,    /* operate on this */
                   int nonblock   /* TRUE or FALSE */)
 {
 #undef SETBLOCK
@@ -168,7 +168,7 @@ int Curl_nonblock(int sockfd,    /* operate on this */
  * 2    select() returned with an error condition
  */
 static
-int waitconnect(int sockfd, /* socket */
+int waitconnect(curl_socket_t sockfd, /* socket */
                 long timeout_msec)
 {
   fd_set fd;
@@ -212,7 +212,7 @@ int waitconnect(int sockfd, /* socket */
 }
 
 static CURLcode bindlocal(struct connectdata *conn,
-                          int sockfd)
+                          curl_socket_t sockfd)
 {
 #ifdef HAVE_INET_NTOA
   bool bindworked = FALSE;
@@ -401,7 +401,7 @@ static CURLcode bindlocal(struct connectdata *conn,
 /*
  * verifyconnect() returns TRUE if the connect really has happened.
  */
-static bool verifyconnect(int sockfd)
+static bool verifyconnect(curl_socket_t sockfd)
 {
 #if defined(SO_ERROR) && !defined(WIN32)
   int err = 0;
@@ -427,7 +427,7 @@ static bool verifyconnect(int sockfd)
  */
 
 CURLcode Curl_is_connected(struct connectdata *conn,
-                           int sockfd,
+                           curl_socket_t sockfd,
                            bool *connected)
 {
   int rc;
@@ -505,13 +505,13 @@ CURLcode Curl_is_connected(struct connectdata *conn,
 CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
                           struct Curl_dns_entry *remotehost, /* use this one */
                           int port,                  /* connect to this */
-                          int *sockconn,             /* the connected socket */
+                          curl_socket_t *sockconn,   /* the connected socket */
                           Curl_ipconnect **addr,     /* the one we used */
                           bool *connected)           /* really connected? */
 {
   struct SessionHandle *data = conn->data;
   int rc;
-  int sockfd=-1;
+  curl_socket_t sockfd= CURL_SOCKET_BAD;
   int aliasindex=0;
   char *hostname;
 
@@ -587,7 +587,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
 
     /* create an IPv4 TCP socket */
     sockfd = socket(AF_INET, SOCK_STREAM, 0);
-    if(-1 == sockfd) {
+    if(CURL_SOCKET_BAD == sockfd) {
       failf(data, "couldn't create socket");
       return CURLE_COULDNT_CONNECT; /* big time error */
     }
index 9bbf2c0ae692eafd35d31dfd72c75a37c212b134..bccb84387cabb7c6fe89969951a5aa2bb265622d 100644 (file)
  * $Id$
  ***************************************************************************/
 
-int Curl_nonblock(int sockfd,    /* operate on this */
+int Curl_nonblock(curl_socket_t sockfd,    /* operate on this */
                   int nonblock   /* TRUE or FALSE */);
 
 CURLcode Curl_is_connected(struct connectdata *conn,
-                           int sockfd,
+                           curl_socket_t sockfd,
                            bool *connected);
 
 CURLcode Curl_connecthost(struct connectdata *conn,
                           struct Curl_dns_entry *host, /* connect to this */
                           int port,       /* connect to this port number */
-                          int *sockconn,  /* not set if error is returned */
+                          curl_socket_t *sockconn, /* not set if error */
                           Curl_ipconnect **addr, /* the one we used */
                           bool *connected /* truly connected? */
                           );
index a07760bbd876927cbc071b93828c115c440ee7b7..2a7ad22c78f1c2db3fd870909e9b4aa4cf87c3ab 100644 (file)
@@ -89,7 +89,7 @@ CURLcode Curl_dict(struct connectdata *conn)
                           by RFC 2229 */
   CURLcode result=CURLE_OK;
   struct SessionHandle *data=conn->data;
-  int sockfd = conn->sock[FIRSTSOCKET];
+  curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
 
   char *path = conn->path;
   curl_off_t *bytecount = &conn->bytecount;
index adb7db50bdf141591319f34c1ee52a4c8e29a0c1..950ec0eaca92bb30238c051ed2269e662412ad0d 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -132,7 +132,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
   fd_set rdset;
   struct timeval dt;
   struct SessionHandle *data = conn->data;
-  int sock = conn->sock[SECONDARYSOCKET];
+  curl_socket_t sock = conn->sock[SECONDARYSOCKET];
   struct timeval now = Curl_tvnow();
   long timespent = Curl_tvdiff(Curl_tvnow(), now)/1000;
   long timeout = data->set.connecttimeout?data->set.connecttimeout:
@@ -211,7 +211,7 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
    * Alas, read as much as possible, split up into lines, use the ending
    * line in a response or continue reading.  */
 
-  int sockfd = conn->sock[FIRSTSOCKET];
+  curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
   int perline; /* count bytes per line */
   bool keepon=TRUE;
   ssize_t gotbytes;
@@ -1103,7 +1103,7 @@ static
 CURLcode ftp_use_port(struct connectdata *conn)
 {
   struct SessionHandle *data=conn->data;
-  int portsock=-1;
+  curl_socket_t portsock= CURL_SOCKET_BAD;
   ssize_t nread;
   int ftpcode; /* receive FTP response codes in this */
   CURLcode result;
@@ -1166,7 +1166,7 @@ CURLcode ftp_use_port(struct connectdata *conn)
     return CURLE_FTP_PORT_FAILED;
   }
   
-  portsock = -1;
+  portsock = CURL_SOCKET_BAD;
   for (ai = res; ai; ai = ai->ai_next) {
     /*
      * Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype):
@@ -1175,25 +1175,25 @@ CURLcode ftp_use_port(struct connectdata *conn)
       ai->ai_socktype = hints.ai_socktype;
 
     portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
-    if (portsock < 0)
+    if (portsock == CURL_SOCKET_BAD)
       continue;
 
     if (bind(portsock, ai->ai_addr, ai->ai_addrlen) < 0) {
       sclose(portsock);
-      portsock = -1;
+      portsock = CURL_SOCKET_BAD;
       continue;
     }
       
     if (listen(portsock, 1) < 0) {
       sclose(portsock);
-      portsock = -1;
+      portsock = CURL_SOCKET_BAD;
       continue;
     }
     
     break;
   }
   freeaddrinfo(res);
-  if (portsock < 0) {
+  if (portsock == CURL_SOCKET_BAD) {
     failf(data, "%s", strerror(errno));
     return CURLE_FTP_PORT_FAILED;
   }
@@ -1378,7 +1378,7 @@ CURLcode ftp_use_port(struct connectdata *conn)
     Curl_resolv_unlock(data, h);
 
   if ( h || sa_filled_in) {
-    if( (portsock = socket(AF_INET, SOCK_STREAM, 0)) >= 0 ) {
+    if( (portsock = socket(AF_INET, SOCK_STREAM, 0)) != CURL_SOCKET_BAD ) {
       int size;
       
       /* we set the secondary socket variable to this for now, it
index 66e38bf942d4c171457835c4eb37f2c3a7b076b6..0de90c7c5ac3b9f0c328210f5b50d66a2135e321 100644 (file)
@@ -531,7 +531,7 @@ CURLcode add_buffer_send(send_buffer *in,
   size_t size;
   struct HTTP *http = conn->proto.http;
   size_t sendsize;
-  int sockfd = conn->sock[FIRSTSOCKET];
+  curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
 
   /* The looping below is required since we use non-blocking sockets, but due
      to the circumstances we will just loop and try again and again etc */
index 83e0b1d8cadc348fd74ccafac7ac0af2f6036ca7..2f038d3973f4e12238c2bb661434033c72056fa8 100644 (file)
@@ -263,7 +263,7 @@ CURLMcode curl_multi_fdset(CURLM *multi_handle,
         /* when we're waiting for a connect, we wait for the socket to
            become writable */
         struct connectdata *conn = easy->easy_conn;
-        int sockfd;
+        curl_socket_t sockfd;
 
         if(CURLM_STATE_WAITCONNECT == easy->state) {
           sockfd = conn->sock[FIRSTSOCKET];
index fb0c45e3c95a7bf864a6e31c601777904c4db870..f640e082f1b61e6cef4bd4181c39fef204f8087c 100644 (file)
@@ -169,7 +169,7 @@ void Curl_failf(struct SessionHandle *data, const char *fmt, ...)
 }
 
 /* Curl_sendf() sends formated data to the server */
-CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
+CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn,
                     const char *fmt, ...)
 {
   struct SessionHandle *data = conn->data;
@@ -217,11 +217,11 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
 /*
  * Curl_write() is an internal write function that sends plain (binary) data
  * to the server. Works with plain sockets, SSL or kerberos.
- *
  */
 CURLcode Curl_write(struct connectdata *conn,
-                    int sockfd,
-                    void *mem, size_t len,
+                    curl_socket_t sockfd,
+                    void *mem,
+                    size_t len,
                     ssize_t *written)
 {
   ssize_t bytes_written;
@@ -363,7 +363,7 @@ CURLcode Curl_client_write(struct SessionHandle *data,
  * a regular CURLcode value.
  */
 int Curl_read(struct connectdata *conn, /* connection data */
-              int sockfd,               /* read from this file handle */
+              curl_socket_t sockfd,     /* read from this socket */
               char *buf,                /* store read data here */
               size_t buffersize,        /* max amount to read */
               ssize_t *n)               /* amount bytes read */
index b2947918e9b70d97f42072a14b7a0a0cb10b4647..73cd215aecce6f47820160c4cad7e70dd2a1a6ef 100644 (file)
@@ -38,7 +38,7 @@ CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr,
                            size_t len);
 
 /* internal read-function, does plain socket, SSL and krb4 */
-int Curl_read(struct connectdata *conn, int sockfd,
+int Curl_read(struct connectdata *conn, curl_socket_t sockfd,
               char *buf, size_t buffersize,
               ssize_t *n);
 /* internal write-function, does plain socket, SSL and krb4 */
index f95742460cab00eb126cf325759e890eb0f1ee61..536d4d90aac6b849b7bbc3264c19d6ec8ed364d2 100644 (file)
@@ -113,6 +113,14 @@ typedef unsigned char bool;
 #endif
 #endif
 
+#ifdef WIN32
+typedef SOCKET curl_socket_t;
+#define CURL_SOCKET_BAD INVALID_SOCKET
+#else
+typedef int curl_socket_t;
+#define CURL_SOCKET_BAD -1
+#endif
+
 #if defined(HAVE_X509_H) && defined(HAVE_SSL_H) && defined(HAVE_RSA_H) && \
 defined(HAVE_PEM_H) && defined(HAVE_ERR_H) && defined(HAVE_CRYPTO_H) && \
 defined(HAVE_LIBSSL) && defined(HAVE_LIBCRYPTO)
index 48c7c8e03dae4045881e51a0625a0db3f11f3063..b2f1e82e6bfdede7874bacf6d171c5ef3c4dfb54 100644 (file)
@@ -922,7 +922,7 @@ Curl_SSLConnect(struct connectdata *conn,
   SSL_METHOD *req_method;
   SSL_SESSION *ssl_sessionid=NULL;
   ASN1_TIME *certdate;
-  int sockfd = conn->sock[sockindex];
+  curl_socket_t sockfd = conn->sock[sockindex];
   struct ssl_connect_data *connssl = &conn->ssl[sockindex];
 
   /* mark this is being ssl enabled from here on out. */
index 7d18254378476acb2e6c745c4ace353aea6f04f9..4a34a7dd4f391648213b37636ce66ddbdb78c74f 100644 (file)
@@ -23,7 +23,7 @@
  * $Id$
  ***************************************************************************/
 #include "urldata.h"
-CURLcode Curl_SSLConnect(struct connectdata *conn, int sockfd);
+CURLcode Curl_SSLConnect(struct connectdata *conn, curl_socket_t sockfd);
 
 void Curl_SSL_init(void);    /* Global SSL init */
 void Curl_SSL_cleanup(void); /* Global SSL cleanup */
index c925ad52e83c5e33e6c1a20b619f2950839f4a08..2d9adda51aadc68710306d96c38f0eb9f6a593ce 100644 (file)
@@ -1079,7 +1079,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
 {
   CURLcode code;
   struct SessionHandle *data = conn->data;
-  int sockfd = conn->sock[FIRSTSOCKET];
+  curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
 #ifdef WIN32
   HMODULE wsock2;
   WSOCK2_FUNC close_event_func;
index d4492940751ba119427f7d031568af27a52e151a..b202046058e9bd5799e6d7f4bf84f299cd592404 100644 (file)
@@ -2012,14 +2012,16 @@ Curl_Transfer(struct connectdata *c_conn, /* connection data */
   if(!conn)
     return CURLE_BAD_FUNCTION_ARGUMENT;
 
-  curlassert(sockindex <= 1);
+  curlassert((sockindex <= 1) && (sockindex >= -1));
 
   /* now copy all input parameters */
-  conn->sockfd = sockindex==-1?-1:conn->sock[sockindex];
+  conn->sockfd = sockindex==-1?
+    CURL_SOCKET_BAD:conn->sock[sockindex];
   conn->size = size;
   conn->bits.getheader = getheader;
   conn->bytecountp = bytecountp;
-  conn->writesockfd = writesockindex==-1?-1:conn->sock[writesockindex];
+  conn->writesockfd = writesockindex==-1?
+    CURL_SOCKET_BAD:conn->sock[writesockindex];
   conn->writebytecountp = writecountp;
 
   return CURLE_OK;
index d1b1a76972e5c59704c1c095dec601abe32f05c1..cc6eca0df2a7a87dff6b28239729aaeb55ff0cdc 100644 (file)
@@ -37,12 +37,14 @@ CURLcode Curl_readwrite_init(struct connectdata *conn);
 /* This sets up a forthcoming transfer */
 CURLcode 
 Curl_Transfer (struct connectdata *data,
-               int sockfd,             /* socket to read from or -1 */
+               curl_socket_t sockfd,   /* socket to read from or
+                                           CURL_SOCKET_BAD */
                curl_off_t size,                /* -1 if unknown at this point */
                bool getheader,         /* TRUE if header parsing is wanted */
                curl_off_t *bytecountp, /* return number of bytes read */
-               int writesockfd,      /* socket to write to, it may very well be
-                                        the same we read from. -1 disables */
+               curl_socket_t writesockfd, /* socket to write to, it may very
+                                             well be the same we read from.
+                                             CURL_SOCKET_BAD disables */
                curl_off_t *writecountp /* return number of bytes written */
 );
 #endif
index fc8c65be80fc8f6b0bcb4cf47cf4cc5c39fd0b1b..d487377f44549af33cc500e93a37f0f6b4ff50a7 100644 (file)
@@ -361,7 +361,7 @@ struct Curl_transfer_keeper {
 
   char *buf;
   char *uploadbuf;
-  int maxfd;
+  curl_socket_t maxfd;
 
   /* pointers to the actual descriptors we check */
   fd_set *readfdp;
@@ -451,10 +451,10 @@ struct connectdata {
   
   struct timeval now;     /* "current" time */
   struct timeval created; /* creation time */
-  int sock[2];       /* two sockets, the second is used for the data transfer
-                        when doing FTP */
+  curl_socket_t sock[2]; /* two sockets, the second is used for the data
+                            transfer when doing FTP */
   curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0
-                        means unlimited */
+                             means unlimited */
   
   struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
   struct ssl_config_data ssl_config;
@@ -490,13 +490,14 @@ struct connectdata {
   /**** curl_get() phase fields */
 
   /* READ stuff */
-  int sockfd;            /* socket to read from or -1 */
+  curl_socket_t sockfd;          /* socket to read from or CURL_SOCKET_BAD */
   curl_off_t size;       /* -1 if unknown at this point */
   curl_off_t *bytecountp; /* return number of bytes read or NULL */
           
   /* WRITE stuff */
-  int writesockfd;       /* socket to write to, it may very
-                            well be the same we read from. -1 disables */
+  curl_socket_t writesockfd; /* socket to write to, it may very
+                                well be the same we read from.
+                                CURL_SOCKET_BAD disables */
   curl_off_t *writebytecountp; /* return number of bytes written or NULL */
 
   /** Dynamicly allocated strings, may need to be freed before this **/