1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

Use curl_socket_t instead of int for holding sockets. The typedefs and

defines are in setup.h.
This commit is contained in:
Daniel Stenberg 2004-03-09 22:52:50 +00:00
parent dad0715d79
commit ce5805a955
15 changed files with 59 additions and 46 deletions

View File

@ -86,7 +86,7 @@
#include "memdebug.h" #include "memdebug.h"
#endif #endif
static bool verifyconnect(int sockfd); static bool verifyconnect(curl_socket_t sockfd);
int Curl_ourerrno(void) int Curl_ourerrno(void)
{ {
@ -104,7 +104,7 @@ int Curl_ourerrno(void)
* Set the socket to either blocking or non-blocking mode. * 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 */) int nonblock /* TRUE or FALSE */)
{ {
#undef SETBLOCK #undef SETBLOCK
@ -168,7 +168,7 @@ int Curl_nonblock(int sockfd, /* operate on this */
* 2 select() returned with an error condition * 2 select() returned with an error condition
*/ */
static static
int waitconnect(int sockfd, /* socket */ int waitconnect(curl_socket_t sockfd, /* socket */
long timeout_msec) long timeout_msec)
{ {
fd_set fd; fd_set fd;
@ -212,7 +212,7 @@ int waitconnect(int sockfd, /* socket */
} }
static CURLcode bindlocal(struct connectdata *conn, static CURLcode bindlocal(struct connectdata *conn,
int sockfd) curl_socket_t sockfd)
{ {
#ifdef HAVE_INET_NTOA #ifdef HAVE_INET_NTOA
bool bindworked = FALSE; bool bindworked = FALSE;
@ -401,7 +401,7 @@ static CURLcode bindlocal(struct connectdata *conn,
/* /*
* verifyconnect() returns TRUE if the connect really has happened. * 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) #if defined(SO_ERROR) && !defined(WIN32)
int err = 0; int err = 0;
@ -427,7 +427,7 @@ static bool verifyconnect(int sockfd)
*/ */
CURLcode Curl_is_connected(struct connectdata *conn, CURLcode Curl_is_connected(struct connectdata *conn,
int sockfd, curl_socket_t sockfd,
bool *connected) bool *connected)
{ {
int rc; int rc;
@ -505,13 +505,13 @@ CURLcode Curl_is_connected(struct connectdata *conn,
CURLcode Curl_connecthost(struct connectdata *conn, /* context */ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
struct Curl_dns_entry *remotehost, /* use this one */ struct Curl_dns_entry *remotehost, /* use this one */
int port, /* connect to this */ int port, /* connect to this */
int *sockconn, /* the connected socket */ curl_socket_t *sockconn, /* the connected socket */
Curl_ipconnect **addr, /* the one we used */ Curl_ipconnect **addr, /* the one we used */
bool *connected) /* really connected? */ bool *connected) /* really connected? */
{ {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
int rc; int rc;
int sockfd=-1; curl_socket_t sockfd= CURL_SOCKET_BAD;
int aliasindex=0; int aliasindex=0;
char *hostname; char *hostname;
@ -587,7 +587,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
/* create an IPv4 TCP socket */ /* create an IPv4 TCP socket */
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(-1 == sockfd) { if(CURL_SOCKET_BAD == sockfd) {
failf(data, "couldn't create socket"); failf(data, "couldn't create socket");
return CURLE_COULDNT_CONNECT; /* big time error */ return CURLE_COULDNT_CONNECT; /* big time error */
} }

View File

@ -23,17 +23,17 @@
* $Id$ * $Id$
***************************************************************************/ ***************************************************************************/
int Curl_nonblock(int sockfd, /* operate on this */ int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
int nonblock /* TRUE or FALSE */); int nonblock /* TRUE or FALSE */);
CURLcode Curl_is_connected(struct connectdata *conn, CURLcode Curl_is_connected(struct connectdata *conn,
int sockfd, curl_socket_t sockfd,
bool *connected); bool *connected);
CURLcode Curl_connecthost(struct connectdata *conn, CURLcode Curl_connecthost(struct connectdata *conn,
struct Curl_dns_entry *host, /* connect to this */ struct Curl_dns_entry *host, /* connect to this */
int port, /* connect to this port number */ 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 */ Curl_ipconnect **addr, /* the one we used */
bool *connected /* truly connected? */ bool *connected /* truly connected? */
); );

View File

@ -89,7 +89,7 @@ CURLcode Curl_dict(struct connectdata *conn)
by RFC 2229 */ by RFC 2229 */
CURLcode result=CURLE_OK; CURLcode result=CURLE_OK;
struct SessionHandle *data=conn->data; struct SessionHandle *data=conn->data;
int sockfd = conn->sock[FIRSTSOCKET]; curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
char *path = conn->path; char *path = conn->path;
curl_off_t *bytecount = &conn->bytecount; curl_off_t *bytecount = &conn->bytecount;

View File

@ -132,7 +132,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
fd_set rdset; fd_set rdset;
struct timeval dt; struct timeval dt;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
int sock = conn->sock[SECONDARYSOCKET]; curl_socket_t sock = conn->sock[SECONDARYSOCKET];
struct timeval now = Curl_tvnow(); struct timeval now = Curl_tvnow();
long timespent = Curl_tvdiff(Curl_tvnow(), now)/1000; long timespent = Curl_tvdiff(Curl_tvnow(), now)/1000;
long timeout = data->set.connecttimeout?data->set.connecttimeout: 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 * Alas, read as much as possible, split up into lines, use the ending
* line in a response or continue reading. */ * 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 */ int perline; /* count bytes per line */
bool keepon=TRUE; bool keepon=TRUE;
ssize_t gotbytes; ssize_t gotbytes;
@ -1103,7 +1103,7 @@ static
CURLcode ftp_use_port(struct connectdata *conn) CURLcode ftp_use_port(struct connectdata *conn)
{ {
struct SessionHandle *data=conn->data; struct SessionHandle *data=conn->data;
int portsock=-1; curl_socket_t portsock= CURL_SOCKET_BAD;
ssize_t nread; ssize_t nread;
int ftpcode; /* receive FTP response codes in this */ int ftpcode; /* receive FTP response codes in this */
CURLcode result; CURLcode result;
@ -1166,7 +1166,7 @@ CURLcode ftp_use_port(struct connectdata *conn)
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
portsock = -1; portsock = CURL_SOCKET_BAD;
for (ai = res; ai; ai = ai->ai_next) { for (ai = res; ai; ai = ai->ai_next) {
/* /*
* Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype): * 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; ai->ai_socktype = hints.ai_socktype;
portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock < 0) if (portsock == CURL_SOCKET_BAD)
continue; continue;
if (bind(portsock, ai->ai_addr, ai->ai_addrlen) < 0) { if (bind(portsock, ai->ai_addr, ai->ai_addrlen) < 0) {
sclose(portsock); sclose(portsock);
portsock = -1; portsock = CURL_SOCKET_BAD;
continue; continue;
} }
if (listen(portsock, 1) < 0) { if (listen(portsock, 1) < 0) {
sclose(portsock); sclose(portsock);
portsock = -1; portsock = CURL_SOCKET_BAD;
continue; continue;
} }
break; break;
} }
freeaddrinfo(res); freeaddrinfo(res);
if (portsock < 0) { if (portsock == CURL_SOCKET_BAD) {
failf(data, "%s", strerror(errno)); failf(data, "%s", strerror(errno));
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -1378,7 +1378,7 @@ CURLcode ftp_use_port(struct connectdata *conn)
Curl_resolv_unlock(data, h); Curl_resolv_unlock(data, h);
if ( h || sa_filled_in) { 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; int size;
/* we set the secondary socket variable to this for now, it /* we set the secondary socket variable to this for now, it

View File

@ -531,7 +531,7 @@ CURLcode add_buffer_send(send_buffer *in,
size_t size; size_t size;
struct HTTP *http = conn->proto.http; struct HTTP *http = conn->proto.http;
size_t sendsize; 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 /* 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 */ to the circumstances we will just loop and try again and again etc */

View 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 /* when we're waiting for a connect, we wait for the socket to
become writable */ become writable */
struct connectdata *conn = easy->easy_conn; struct connectdata *conn = easy->easy_conn;
int sockfd; curl_socket_t sockfd;
if(CURLM_STATE_WAITCONNECT == easy->state) { if(CURLM_STATE_WAITCONNECT == easy->state) {
sockfd = conn->sock[FIRSTSOCKET]; sockfd = conn->sock[FIRSTSOCKET];

View File

@ -169,7 +169,7 @@ void Curl_failf(struct SessionHandle *data, const char *fmt, ...)
} }
/* Curl_sendf() sends formated data to the server */ /* 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, ...) const char *fmt, ...)
{ {
struct SessionHandle *data = conn->data; 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 * Curl_write() is an internal write function that sends plain (binary) data
* to the server. Works with plain sockets, SSL or kerberos. * to the server. Works with plain sockets, SSL or kerberos.
*
*/ */
CURLcode Curl_write(struct connectdata *conn, CURLcode Curl_write(struct connectdata *conn,
int sockfd, curl_socket_t sockfd,
void *mem, size_t len, void *mem,
size_t len,
ssize_t *written) ssize_t *written)
{ {
ssize_t bytes_written; ssize_t bytes_written;
@ -363,7 +363,7 @@ CURLcode Curl_client_write(struct SessionHandle *data,
* a regular CURLcode value. * a regular CURLcode value.
*/ */
int Curl_read(struct connectdata *conn, /* connection data */ 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 */ char *buf, /* store read data here */
size_t buffersize, /* max amount to read */ size_t buffersize, /* max amount to read */
ssize_t *n) /* amount bytes read */ ssize_t *n) /* amount bytes read */

View File

@ -38,7 +38,7 @@ CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr,
size_t len); size_t len);
/* internal read-function, does plain socket, SSL and krb4 */ /* 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, char *buf, size_t buffersize,
ssize_t *n); ssize_t *n);
/* internal write-function, does plain socket, SSL and krb4 */ /* internal write-function, does plain socket, SSL and krb4 */

View File

@ -113,6 +113,14 @@ typedef unsigned char bool;
#endif #endif
#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) && \ #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_PEM_H) && defined(HAVE_ERR_H) && defined(HAVE_CRYPTO_H) && \
defined(HAVE_LIBSSL) && defined(HAVE_LIBCRYPTO) defined(HAVE_LIBSSL) && defined(HAVE_LIBCRYPTO)

View File

@ -922,7 +922,7 @@ Curl_SSLConnect(struct connectdata *conn,
SSL_METHOD *req_method; SSL_METHOD *req_method;
SSL_SESSION *ssl_sessionid=NULL; SSL_SESSION *ssl_sessionid=NULL;
ASN1_TIME *certdate; ASN1_TIME *certdate;
int sockfd = conn->sock[sockindex]; curl_socket_t sockfd = conn->sock[sockindex];
struct ssl_connect_data *connssl = &conn->ssl[sockindex]; struct ssl_connect_data *connssl = &conn->ssl[sockindex];
/* mark this is being ssl enabled from here on out. */ /* mark this is being ssl enabled from here on out. */

View File

@ -23,7 +23,7 @@
* $Id$ * $Id$
***************************************************************************/ ***************************************************************************/
#include "urldata.h" #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_init(void); /* Global SSL init */
void Curl_SSL_cleanup(void); /* Global SSL cleanup */ void Curl_SSL_cleanup(void); /* Global SSL cleanup */

View File

@ -1079,7 +1079,7 @@ CURLcode Curl_telnet(struct connectdata *conn)
{ {
CURLcode code; CURLcode code;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
int sockfd = conn->sock[FIRSTSOCKET]; curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
#ifdef WIN32 #ifdef WIN32
HMODULE wsock2; HMODULE wsock2;
WSOCK2_FUNC close_event_func; WSOCK2_FUNC close_event_func;

View File

@ -2012,14 +2012,16 @@ Curl_Transfer(struct connectdata *c_conn, /* connection data */
if(!conn) if(!conn)
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
curlassert(sockindex <= 1); curlassert((sockindex <= 1) && (sockindex >= -1));
/* now copy all input parameters */ /* 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->size = size;
conn->bits.getheader = getheader; conn->bits.getheader = getheader;
conn->bytecountp = bytecountp; conn->bytecountp = bytecountp;
conn->writesockfd = writesockindex==-1?-1:conn->sock[writesockindex]; conn->writesockfd = writesockindex==-1?
CURL_SOCKET_BAD:conn->sock[writesockindex];
conn->writebytecountp = writecountp; conn->writebytecountp = writecountp;
return CURLE_OK; return CURLE_OK;

View File

@ -37,12 +37,14 @@ CURLcode Curl_readwrite_init(struct connectdata *conn);
/* This sets up a forthcoming transfer */ /* This sets up a forthcoming transfer */
CURLcode CURLcode
Curl_Transfer (struct connectdata *data, 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 */ curl_off_t size, /* -1 if unknown at this point */
bool getheader, /* TRUE if header parsing is wanted */ bool getheader, /* TRUE if header parsing is wanted */
curl_off_t *bytecountp, /* return number of bytes read */ curl_off_t *bytecountp, /* return number of bytes read */
int writesockfd, /* socket to write to, it may very well be curl_socket_t writesockfd, /* socket to write to, it may very
the same we read from. -1 disables */ well be the same we read from.
CURL_SOCKET_BAD disables */
curl_off_t *writecountp /* return number of bytes written */ curl_off_t *writecountp /* return number of bytes written */
); );
#endif #endif

View File

@ -361,7 +361,7 @@ struct Curl_transfer_keeper {
char *buf; char *buf;
char *uploadbuf; char *uploadbuf;
int maxfd; curl_socket_t maxfd;
/* pointers to the actual descriptors we check */ /* pointers to the actual descriptors we check */
fd_set *readfdp; fd_set *readfdp;
@ -451,8 +451,8 @@ struct connectdata {
struct timeval now; /* "current" time */ struct timeval now; /* "current" time */
struct timeval created; /* creation time */ struct timeval created; /* creation time */
int sock[2]; /* two sockets, the second is used for the data transfer curl_socket_t sock[2]; /* two sockets, the second is used for the data
when doing FTP */ transfer when doing FTP */
curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0 curl_off_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0
means unlimited */ means unlimited */
@ -490,13 +490,14 @@ struct connectdata {
/**** curl_get() phase fields */ /**** curl_get() phase fields */
/* READ stuff */ /* 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 size; /* -1 if unknown at this point */
curl_off_t *bytecountp; /* return number of bytes read or NULL */ curl_off_t *bytecountp; /* return number of bytes read or NULL */
/* WRITE stuff */ /* WRITE stuff */
int writesockfd; /* socket to write to, it may very curl_socket_t writesockfd; /* socket to write to, it may very
well be the same we read from. -1 disables */ well be the same we read from.
CURL_SOCKET_BAD disables */
curl_off_t *writebytecountp; /* return number of bytes written or NULL */ curl_off_t *writebytecountp; /* return number of bytes written or NULL */
/** Dynamicly allocated strings, may need to be freed before this **/ /** Dynamicly allocated strings, may need to be freed before this **/