diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-03-09 22:52:50 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-03-09 22:52:50 +0000 |
commit | ce5805a955c5a79d85792caad47594987f0e0b26 (patch) | |
tree | e22b4801edb6a5448aa38730d311ccace9eb2be3 | |
parent | dad0715d7907e8a64f2cccf1d21b648018f11f41 (diff) |
Use curl_socket_t instead of int for holding sockets. The typedefs and
defines are in setup.h.
-rw-r--r-- | lib/connect.c | 18 | ||||
-rw-r--r-- | lib/connect.h | 6 | ||||
-rw-r--r-- | lib/dict.c | 2 | ||||
-rw-r--r-- | lib/ftp.c | 18 | ||||
-rw-r--r-- | lib/http.c | 2 | ||||
-rw-r--r-- | lib/multi.c | 2 | ||||
-rw-r--r-- | lib/sendf.c | 10 | ||||
-rw-r--r-- | lib/sendf.h | 2 | ||||
-rw-r--r-- | lib/setup.h | 8 | ||||
-rw-r--r-- | lib/ssluse.c | 2 | ||||
-rw-r--r-- | lib/ssluse.h | 2 | ||||
-rw-r--r-- | lib/telnet.c | 2 | ||||
-rw-r--r-- | lib/transfer.c | 8 | ||||
-rw-r--r-- | lib/transfer.h | 8 | ||||
-rw-r--r-- | lib/urldata.h | 15 |
15 files changed, 59 insertions, 46 deletions
diff --git a/lib/connect.c b/lib/connect.c index 1aedcbfcf..dd4401585 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -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 */ } diff --git a/lib/connect.h b/lib/connect.h index 9bbf2c0ae..bccb84387 100644 --- a/lib/connect.h +++ b/lib/connect.h @@ -23,17 +23,17 @@ * $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? */ ); diff --git a/lib/dict.c b/lib/dict.c index a07760bbd..2a7ad22c7 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -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; @@ -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 diff --git a/lib/http.c b/lib/http.c index 66e38bf94..0de90c7c5 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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 */ diff --git a/lib/multi.c b/lib/multi.c index 83e0b1d8c..2f038d397 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -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]; diff --git a/lib/sendf.c b/lib/sendf.c index fb0c45e3c..f640e082f 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -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 */ diff --git a/lib/sendf.h b/lib/sendf.h index b2947918e..73cd215ae 100644 --- a/lib/sendf.h +++ b/lib/sendf.h @@ -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 */ diff --git a/lib/setup.h b/lib/setup.h index f95742460..536d4d90a 100644 --- a/lib/setup.h +++ b/lib/setup.h @@ -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) diff --git a/lib/ssluse.c b/lib/ssluse.c index 48c7c8e03..b2f1e82e6 100644 --- a/lib/ssluse.c +++ b/lib/ssluse.c @@ -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. */ diff --git a/lib/ssluse.h b/lib/ssluse.h index 7d1825437..4a34a7dd4 100644 --- a/lib/ssluse.h +++ b/lib/ssluse.h @@ -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 */ diff --git a/lib/telnet.c b/lib/telnet.c index c925ad52e..2d9adda51 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -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; diff --git a/lib/transfer.c b/lib/transfer.c index d44929407..b20204605 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -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; diff --git a/lib/transfer.h b/lib/transfer.h index d1b1a7697..cc6eca0df 100644 --- a/lib/transfer.h +++ b/lib/transfer.h @@ -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 diff --git a/lib/urldata.h b/lib/urldata.h index fc8c65be8..d487377f4 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -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 **/ |