defines are in setup.h.
#include "memdebug.h"
#endif
-static bool verifyconnect(int sockfd);
+static bool verifyconnect(curl_socket_t sockfd);
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
* 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;
}
static CURLcode bindlocal(struct connectdata *conn,
- int sockfd)
+ curl_socket_t sockfd)
{
#ifdef HAVE_INET_NTOA
bool bindworked = FALSE;
/*
* 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;
*/
CURLcode Curl_is_connected(struct connectdata *conn,
- int sockfd,
+ curl_socket_t sockfd,
bool *connected)
{
int rc;
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;
/* 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 */
}
* $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? */
);
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;
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:
* 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;
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;
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):
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;
}
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
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 */
/* 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];
}
/* 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;
/*
* 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;
* 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 */
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 */
#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)
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. */
* $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 */
{
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;
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;
/* 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
char *buf;
char *uploadbuf;
- int maxfd;
+ curl_socket_t maxfd;
/* pointers to the actual descriptors we check */
fd_set *readfdp;
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;
/**** 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 **/