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

use macros ERRNO, SET_ERRNO(), SOCKERRNO and SET_SOCKERRNO() for errno handling

This commit is contained in:
Yang Tse 2007-02-16 18:19:35 +00:00
parent 4894ce16fc
commit a1d5983991
22 changed files with 128 additions and 122 deletions

View File

@ -115,19 +115,6 @@ singleipconnect(struct connectdata *conn,
long timeout_ms,
bool *connected);
/*
* Curl_sockerrno() returns the *socket-related* errno (or equivalent) on this
* platform to hide platform specific for the function that calls this.
*/
int Curl_sockerrno(void)
{
#ifdef USE_WINSOCK
return (int)WSAGetLastError();
#else
return errno;
#endif
}
/*
* Curl_nonblock() set the given socket to either blocking or non-blocking
* mode based on the 'nonblock' boolean argument. This function is highly
@ -332,7 +319,7 @@ static CURLcode bindlocal(struct connectdata *conn,
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
data->set.device, strlen(data->set.device)+1) != 0) {
/* printf("Failed to BINDTODEVICE, socket: %d device: %s error: %s\n",
sockfd, data->set.device, Curl_strerror(Curl_sockerrno())); */
sockfd, data->set.device, Curl_strerror(SOCKERRNO)); */
infof(data, "SO_BINDTODEVICE %s failed\n",
data->set.device);
/* This is typically "errno 1, error: Operation not permitted" if
@ -409,7 +396,7 @@ static CURLcode bindlocal(struct connectdata *conn,
break;
} while(1);
data->state.os_errno = Curl_sockerrno();
data->state.os_errno = SOCKERRNO;
failf(data, "bind failure: %s",
Curl_strerror(conn, data->state.os_errno));
return CURLE_HTTP_PORT_FAILED;
@ -453,7 +440,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
(void *)&err, &errSize))
err = Curl_sockerrno();
err = SOCKERRNO;
#ifdef _WIN32_WCE
/* Always returns this error, bug in CE? */
@ -472,7 +459,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
#else
(void)sockfd;
if (error)
*error = Curl_sockerrno();
*error = SOCKERRNO;
#endif
return rc;
}
@ -613,7 +600,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
infof(data, "Connection failed\n");
if(trynextip(conn, sockindex, connected)) {
error = Curl_sockerrno();
error = SOCKERRNO;
data->state.os_errno = error;
failf(data, "Failed connect to %s:%d; %s",
conn->host.name, conn->port, Curl_strerror(conn,error));
@ -645,7 +632,7 @@ static void tcpnodelay(struct connectdata *conn,
if(setsockopt(sockfd, proto, TCP_NODELAY, (void *)&onoff,
sizeof(onoff)) < 0)
infof(data, "Could not set TCP_NODELAY: %s\n",
Curl_strerror(conn, Curl_sockerrno()));
Curl_strerror(conn, SOCKERRNO));
else
infof(data,"TCP_NODELAY set\n");
#else
@ -667,7 +654,7 @@ static void nosigpipe(struct connectdata *conn,
if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff,
sizeof(onoff)) < 0)
infof(data, "Could not set SO_NOSIGPIPE: %s\n",
Curl_strerror(conn, Curl_sockerrno()));
Curl_strerror(conn, SOCKERRNO));
}
#else
#define nosigpipe(x,y)
@ -731,7 +718,7 @@ singleipconnect(struct connectdata *conn,
rc = 0;
if(-1 == rc) {
error = Curl_sockerrno();
error = SOCKERRNO;
switch (error) {
case EINPROGRESS:

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -37,8 +37,6 @@ CURLcode Curl_connecthost(struct connectdata *conn,
bool *connected /* truly connected? */
);
int Curl_sockerrno(void);
CURLcode Curl_store_ip_addr(struct connectdata *conn);
#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */

View File

@ -750,17 +750,19 @@ CURLcode Curl_convert_to_network(struct SessionHandle *data,
/* do the translation ourselves */
char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc;
int error;
/* open an iconv conversion descriptor if necessary */
if(data->outbound_cd == (iconv_t)-1) {
data->outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK,
CURL_ICONV_CODESET_OF_HOST);
if(data->outbound_cd == (iconv_t)-1) {
error = ERRNO;
failf(data,
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
CURL_ICONV_CODESET_OF_NETWORK,
CURL_ICONV_CODESET_OF_HOST,
errno, strerror(errno));
error, strerror(error));
return CURLE_CONV_FAILED;
}
}
@ -770,9 +772,10 @@ CURLcode Curl_convert_to_network(struct SessionHandle *data,
rc = iconv(data->outbound_cd, (const char**)&input_ptr, &in_bytes,
&output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO;
failf(data,
"The Curl_convert_to_network iconv call failed with errno %i: %s",
errno, strerror(errno));
error, strerror(error));
return CURLE_CONV_FAILED;
}
#else
@ -807,17 +810,19 @@ CURLcode Curl_convert_from_network(struct SessionHandle *data,
/* do the translation ourselves */
char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc;
int error;
/* open an iconv conversion descriptor if necessary */
if(data->inbound_cd == (iconv_t)-1) {
data->inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_OF_NETWORK);
if(data->inbound_cd == (iconv_t)-1) {
error = ERRNO;
failf(data,
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_OF_NETWORK,
errno, strerror(errno));
error, strerror(error));
return CURLE_CONV_FAILED;
}
}
@ -827,9 +832,10 @@ CURLcode Curl_convert_from_network(struct SessionHandle *data,
rc = iconv(data->inbound_cd, (const char **)&input_ptr, &in_bytes,
&output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO;
failf(data,
"The Curl_convert_from_network iconv call failed with errno %i: %s",
errno, strerror(errno));
error, strerror(error));
return CURLE_CONV_FAILED;
}
#else
@ -864,17 +870,19 @@ CURLcode Curl_convert_from_utf8(struct SessionHandle *data,
/* do the translation ourselves */
char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc;
int error;
/* open an iconv conversion descriptor if necessary */
if(data->utf8_cd == (iconv_t)-1) {
data->utf8_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_FOR_UTF8);
if(data->utf8_cd == (iconv_t)-1) {
error = ERRNO;
failf(data,
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_FOR_UTF8,
errno, strerror(errno));
error, strerror(error));
return CURLE_CONV_FAILED;
}
}
@ -884,9 +892,10 @@ CURLcode Curl_convert_from_utf8(struct SessionHandle *data,
rc = iconv(data->utf8_cd, (const char**)&input_ptr, &in_bytes,
&output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO;
failf(data,
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
errno, strerror(errno));
error, strerror(error));
return CURLE_CONV_FAILED;
}
if (output_ptr < input_ptr) {

View File

@ -498,7 +498,7 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
case -1: /* select() error, stop reading */
result = CURLE_RECV_ERROR;
failf(data, "FTP response aborted due to select() error: %d",
Curl_sockerrno());
SOCKERRNO);
break;
case 0: /* timeout */
if(Curl_pgrsUpdate(conn))
@ -841,7 +841,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss);
if (getsockname(conn->sock[FIRSTSOCKET], (struct sockaddr *)&ss, &sslen)) {
failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) );
Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED;
}
@ -882,7 +882,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock == CURL_SOCKET_BAD) {
error = Curl_sockerrno();
error = SOCKERRNO;
continue;
}
break;
@ -902,7 +902,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if (getsockname(conn->sock[FIRSTSOCKET],
(struct sockaddr *)sa, &sslen)) {
failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) );
Curl_strerror(conn, SOCKERRNO) );
sclose(portsock);
return CURLE_FTP_PORT_FAILED;
}
@ -917,7 +917,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss);
if(bind(portsock, (struct sockaddr *)sa, sslen)) {
failf(data, "bind failed: %s", Curl_strerror(conn, Curl_sockerrno()));
failf(data, "bind failed: %s", Curl_strerror(conn, SOCKERRNO));
sclose(portsock);
return CURLE_FTP_PORT_FAILED;
}
@ -928,7 +928,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss);
if(getsockname(portsock, (struct sockaddr *)sa, &sslen)) {
failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) );
Curl_strerror(conn, SOCKERRNO) );
sclose(portsock);
return CURLE_FTP_PORT_FAILED;
}
@ -936,7 +936,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* step 4, listen on the socket */
if (listen(portsock, 1)) {
failf(data, "socket failure: %s", Curl_strerror(conn, Curl_sockerrno()));
failf(data, "socket failure: %s", Curl_strerror(conn, SOCKERRNO));
sclose(portsock);
return CURLE_FTP_PORT_FAILED;
}
@ -1080,7 +1080,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if (getsockname(conn->sock[FIRSTSOCKET],
(struct sockaddr *)&sa, &sslen)) {
failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) );
Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED;
}
if (sslen > (socklen_t)sizeof(sa))
@ -1116,7 +1116,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if(getsockname(portsock, (struct sockaddr *) &add,
&socksize)) {
failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) );
Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED;
}
porttouse = ntohs(add.sin_port);

View File

@ -176,7 +176,7 @@ static CURLcode handshake(struct connectdata *conn,
}
else {
/* anything that gets here is fatally bad */
failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
failf(data, "select on SSL socket, errno: %d", SOCKERRNO);
return CURLE_SSL_CONNECT_ERROR;
}
}
@ -567,7 +567,7 @@ int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
}
else {
/* anything that gets here is fatally bad */
failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
failf(data, "select on SSL socket, errno: %d", SOCKERRNO);
retval = -1;
done = 1;
}

View File

@ -76,7 +76,7 @@
#include "strerror.h"
#include "url.h"
#include "multiif.h"
#include "connect.h" /* for the Curl_sockerrno() proto */
#include "connect.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@ -214,7 +214,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
break;
tvp = ares_timeout(data->state.areschannel, &store, &tv);
count = select(nfds, &read_fds, &write_fds, NULL, tvp);
if (count < 0 && Curl_sockerrno() != EINVAL)
if ((count < 0) && (SOCKERRNO != EINVAL))
break;
ares_process(data->state.areschannel, &read_fds, &write_fds);

View File

@ -253,7 +253,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
(struct hostent *)buf,
(struct hostent_data *)((char *)buf +
sizeof(struct hostent)));
h_errnop= errno; /* we don't deal with this, but set it anyway */
h_errnop = SOCKERRNO; /* we don't deal with this, but set it anyway */
}
else
res = -1; /* failure, too smallish buffer size */

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -210,7 +210,7 @@ static void dump_addrinfo(struct connectdata *conn, const struct addrinfo *ai)
if (Curl_printable_address(ai, buf, sizeof(buf)))
printf("%s\n", buf);
else
printf("failed; %s\n", Curl_strerror(conn, Curl_sockerrno()));
printf("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
}
}
#else

View File

@ -147,7 +147,7 @@ static void dump_addrinfo (struct connectdata *conn, const struct addrinfo *ai)
if (Curl_printable_address(ai, buf, sizeof(buf)))
trace_it("%s\n", buf);
else
trace_it("failed; %s\n", Curl_strerror(conn,WSAGetLastError()));
trace_it("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
}
}
#endif
@ -301,7 +301,8 @@ static unsigned __stdcall gethostbyname_thread (void *arg)
return (unsigned)-1;
}
WSASetLastError (conn->async.status = NO_DATA); /* pending status */
conn->async.status = NO_DATA; /* pending status */
SET_SOCKERRNO(conn->async.status);
/* Signaling that we have initialized all copies of data and handles we
need */
@ -318,7 +319,7 @@ static unsigned __stdcall gethostbyname_thread (void *arg)
rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he);
}
else {
rc = Curl_addrinfo4_callback(conn, (int)WSAGetLastError(), NULL);
rc = Curl_addrinfo4_callback(conn, SOCKERRNO, NULL);
}
TRACE(("Winsock-error %d, addr %s\n", conn->async.status,
he ? inet_ntoa(*(struct in_addr*)he->h_addr) : "unknown"));
@ -362,7 +363,8 @@ static unsigned __stdcall getaddrinfo_thread (void *arg)
itoa(conn->async.port, service, 10);
WSASetLastError(conn->async.status = NO_DATA); /* pending status */
conn->async.status = NO_DATA; /* pending status */
SET_SOCKERRNO(conn->async.status);
/* Signaling that we have initialized all copies of data and handles we
need */
@ -383,7 +385,7 @@ static unsigned __stdcall getaddrinfo_thread (void *arg)
rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res);
}
else {
rc = Curl_addrinfo6_callback(conn, (int)WSAGetLastError(), NULL);
rc = Curl_addrinfo6_callback(conn, SOCKERRNO, NULL);
TRACE(("Winsock-error %d, no address\n", conn->async.status));
}
release_thread_sync(&tsd);
@ -461,7 +463,7 @@ static bool init_resolve_thread (struct connectdata *conn,
HANDLE thread_and_event[2] = {0};
if (!td) {
SetLastError(ENOMEM);
SET_ERRNO(ENOMEM);
return FALSE;
}
@ -469,7 +471,7 @@ static bool init_resolve_thread (struct connectdata *conn,
conn->async.hostname = strdup(hostname);
if (!conn->async.hostname) {
free(td);
SetLastError(ENOMEM);
SET_ERRNO(ENOMEM);
return FALSE;
}
@ -486,7 +488,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->mutex_waiting = CreateMutex(NULL, TRUE, NULL);
if (td->mutex_waiting == NULL) {
Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN);
SET_ERRNO(EAGAIN);
return FALSE;
}
@ -496,7 +498,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_resolved == NULL) {
Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the mutex used to serialize access to event_terminated
@ -505,7 +507,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->mutex_terminate = CreateMutex(NULL, FALSE, NULL);
if (td->mutex_terminate == NULL) {
Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the event used to signal thread that it should terminate.
@ -513,7 +515,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_terminate == NULL) {
Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the event used by thread to inform it has initialized its own data.
@ -521,7 +523,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_thread_started == NULL) {
Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN);
SET_ERRNO(EAGAIN);
return FALSE;
}
@ -543,10 +545,10 @@ static bool init_resolve_thread (struct connectdata *conn,
if (!td->thread_hnd) {
#ifdef _WIN32_WCE
TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn,GetLastError())));
TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn, ERRNO)));
#else
SetLastError(errno);
TRACE(("_beginthreadex() failed; %s\n", Curl_strerror(conn,errno)));
SET_ERRNO(errno);
TRACE(("_beginthreadex() failed; %s\n", Curl_strerror(conn, ERRNO)));
#endif
Curl_destroy_thread_data(&conn->async);
return FALSE;
@ -627,7 +629,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
* thread. 'conn->async.done = TRUE' is set in
* Curl_addrinfo4/6_callback().
*/
WSASetLastError(conn->async.status);
SET_SOCKERRNO(conn->async.status);
GetExitCodeThread(td->thread_hnd, &td->thread_status);
TRACE(("%s() status %lu, thread retval %lu, ",
THREAD_NAME, status, td->thread_status));
@ -749,12 +751,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* fall-back to blocking version */
infof(data, "init_resolve_thread() failed for %s; %s\n",
hostname, Curl_strerror(conn,GetLastError()));
hostname, Curl_strerror(conn, ERRNO));
h = gethostbyname(hostname);
if (!h) {
infof(data, "gethostbyname(2) failed for %s:%d; %s\n",
hostname, port, Curl_strerror(conn,WSAGetLastError()));
hostname, port, Curl_strerror(conn, SOCKERRNO));
return NULL;
}
return Curl_he2ai(h, port);
@ -826,12 +828,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* fall-back to blocking version */
infof(data, "init_resolve_thread() failed for %s; %s\n",
hostname, Curl_strerror(conn,GetLastError()));
hostname, Curl_strerror(conn, ERRNO));
error = getaddrinfo(hostname, sbuf, &hints, &res);
if (error) {
infof(data, "getaddrinfo() failed for %s:%d; %s\n",
hostname, port, Curl_strerror(conn,WSAGetLastError()));
hostname, port, Curl_strerror(conn, SOCKERRNO));
return NULL;
}
return res;

View File

@ -66,6 +66,11 @@ static int inet_pton6(const char *src, unsigned char *dst);
* 1 if the address was valid for the specified address family
* 0 if the address wasn't valid (`dst' is untouched in this case)
* -1 if some other error occurred (`dst' is untouched in this case, too)
* notice:
* On Windows we store the error in the thread errno, not
* in the winsock error code. This is to avoid loosing the
* actual last winsock error. So use macro ERRNO to fetch the
* errno this funtion sets when returning (-1), not SOCKERRNO.
* author:
* Paul Vixie, 1996.
*/
@ -83,7 +88,7 @@ Curl_inet_pton(int af, const char *src, void *dst)
return (inet_pton6(src, (unsigned char *)dst));
#endif
default:
errno = EAFNOSUPPORT;
SET_ERRNO(EAFNOSUPPORT);
return (-1);
}
/* NOTREACHED */

View File

@ -6,7 +6,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -99,7 +99,7 @@ static bool countcheck(const char *func, int line, const char *source)
if(source)
fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func);
errno = ENOMEM;
SET_ERRNO(ENOMEM);
return TRUE; /* RETURN ERROR! */
}
else

View File

@ -42,7 +42,7 @@
#include "sendf.h"
#include "formdata.h" /* for the boundary function */
#include "url.h" /* for the ssl config check function */
#include "connect.h" /* Curl_sockerrno() proto */
#include "connect.h"
#include "strequal.h"
#include "select.h"
#include "sslgen.h"

View File

@ -54,13 +54,15 @@
#include "connect.h"
#include "select.h"
/* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */
#if defined(USE_WINSOCK) || defined(TPF)
#define VERIFY_SOCK(x) /* sockets are not in range [0..FD_SETSIZE] */
#define VERIFY_SOCK(x) do { } while (0)
#else
#define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE))
#define VERIFY_SOCK(x) do { \
if(!VALID_SOCK(x)) { \
errno = EINVAL; \
SET_SOCKERRNO(EINVAL); \
return -1; \
} \
} while(0)
@ -96,13 +98,13 @@ int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms)
num++;
}
#ifdef HAVE_POLL_FINE
do {
r = poll(pfd, num, timeout_ms);
} while((r == -1) && (errno == EINTR));
#ifdef CURL_HAVE_WSAPOLL
r = WSAPoll(pfd, num, timeout_ms);
#else
r = WSAPoll(pfd, num, timeout_ms);
r = poll(pfd, num, timeout_ms);
#endif
} while((r == -1) && (SOCKERRNO == EINTR));
if (r < 0)
return -1;
@ -117,7 +119,7 @@ int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms)
if (pfd[num].revents & POLLERR) {
#ifdef __CYGWIN__
/* Cygwin 1.5.21 needs this hack to pass test 160 */
if (errno == EINPROGRESS)
if (ERRNO == EINPROGRESS)
ret |= CSELECT_IN;
else
#endif
@ -182,7 +184,7 @@ int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms)
do {
r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
} while((r == -1) && (Curl_sockerrno() == EINTR));
} while((r == -1) && (SOCKERRNO == EINTR));
if (r < 0)
return -1;
@ -222,11 +224,13 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
int r;
#ifdef HAVE_POLL_FINE
do {
r = poll(ufds, nfds, timeout_ms);
} while((r == -1) && (errno == EINTR));
#elif defined(CURL_HAVE_WSAPOLL)
r = WSAPoll(ufds, nfds, timeout_ms);
#ifdef CURL_HAVE_WSAPOLL
r = WSAPoll(ufds, nfds, timeout_ms);
#else
r = poll(ufds, nfds, timeout_ms);
#endif
} while((r == -1) && (SOCKERRNO == EINTR));
#else /* HAVE_POLL_FINE */
struct timeval timeout;
struct timeval *ptimeout;
fd_set fds_read;
@ -243,9 +247,10 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
for (i = 0; i < nfds; i++) {
if (ufds[i].fd == CURL_SOCKET_BAD)
continue;
#ifndef USE_WINSOCK /* winsock sockets are not in range [0..FD_SETSIZE] */
#if !defined(USE_WINSOCK) && !defined(TPF)
/* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */
if (ufds[i].fd >= FD_SETSIZE) {
errno = EINVAL;
SET_SOCKERRNO(EINVAL);
return -1;
}
#endif
@ -269,7 +274,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
do {
r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
} while((r == -1) && (Curl_sockerrno() == EINTR));
} while((r == -1) && (SOCKERRNO == EINTR));
if (r < 0)
return -1;
@ -290,7 +295,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
if (ufds[i].revents != 0)
r++;
}
#endif
#endif /* HAVE_POLL_FINE */
return r;
}

View File

@ -43,7 +43,7 @@
#include <curl/curl.h>
#include "urldata.h"
#include "sendf.h"
#include "connect.h" /* for the Curl_sockerrno() proto */
#include "connect.h"
#include "sslgen.h"
#include "ssh.h"
#include "multiif.h"
@ -323,7 +323,7 @@ static ssize_t Curl_plain_send(struct connectdata *conn,
ssize_t bytes_written = swrite(sockfd, mem, len);
if(-1 == bytes_written) {
int err = Curl_sockerrno();
int err = SOCKERRNO;
if(
#ifdef WSAEWOULDBLOCK
@ -539,7 +539,7 @@ int Curl_read(struct connectdata *conn, /* connection data */
nread = sread(sockfd, buffertofill, bytesfromsocket);
if(-1 == nread) {
int err = Curl_sockerrno();
int err = SOCKERRNO;
#ifdef USE_WINSOCK
if(WSAEWOULDBLOCK == err)
#else

View File

@ -49,7 +49,7 @@
#include "url.h" /* for the ssl config check function */
#include "inet_pton.h"
#include "ssluse.h"
#include "connect.h" /* Curl_sockerrno() proto */
#include "connect.h"
#include "strequal.h"
#include "select.h"
#include "sslgen.h"
@ -781,7 +781,7 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
sslerror = ERR_get_error();
failf(conn->data, "SSL read: %s, errno %d",
ERR_error_string(sslerror, buf),
Curl_sockerrno() );
SOCKERRNO);
done = 1;
break;
}
@ -794,7 +794,7 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
}
else {
/* anything that gets here is fatally bad */
failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
failf(data, "select on SSL socket, errno: %d", SOCKERRNO);
retval = -1;
done = 1;
}
@ -1739,7 +1739,7 @@ Curl_ossl_connect_common(struct connectdata *conn,
}
else {
/* anything that gets here is fatally bad */
failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
failf(data, "select on SSL socket, errno: %d", SOCKERRNO);
return CURLE_SSL_CONNECT_ERROR;
}
} /* while()-loop for the select() */
@ -1822,7 +1822,7 @@ ssize_t Curl_ossl_send(struct connectdata *conn,
return 0;
case SSL_ERROR_SYSCALL:
failf(conn->data, "SSL_write() returned SYSCALL, errno = %d\n",
Curl_sockerrno());
SOCKERRNO);
return -1;
case SSL_ERROR_SSL:
/* A failure in the SSL library occurred, usually a protocol error.
@ -1874,7 +1874,7 @@ ssize_t Curl_ossl_recv(struct connectdata *conn, /* connection data */
sslerror = ERR_get_error();
failf(conn->data, "SSL read: %s, errno %d",
ERR_error_string(sslerror, error_buffer),
Curl_sockerrno() );
SOCKERRNO);
return -1;
}
}

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -124,7 +124,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
else
value = CURL_LLONG_MAX;
errno = ERANGE;
SET_ERRNO(ERANGE);
}
if (endptr)

View File

@ -303,7 +303,7 @@ static void send_negotiation(struct connectdata *conn, int cmd, int option)
bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
if(bytes_written < 0) {
err = Curl_sockerrno();
err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err);
}
@ -872,7 +872,7 @@ static void suboption(struct connectdata *conn)
CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE);
bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
if(bytes_written < 0) {
err = Curl_sockerrno();
err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err);
}
printsub(data, '>', &temp[2], len-2);
@ -884,7 +884,7 @@ static void suboption(struct connectdata *conn)
CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE);
bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
if(bytes_written < 0) {
err = Curl_sockerrno();
err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err);
}
printsub(data, '>', &temp[2], len-2);
@ -911,7 +911,7 @@ static void suboption(struct connectdata *conn)
len += 2;
bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
if(bytes_written < 0) {
err = Curl_sockerrno();
err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err);
}
printsub(data, '>', &temp[2], len-2);
@ -1140,7 +1140,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* load ws2_32.dll and get the function pointers we need. */
wsock2 = LoadLibrary("WS2_32.DLL");
if (wsock2 == NULL) {
failf(data,"failed to load WS2_32.DLL (%d)",GetLastError());
failf(data,"failed to load WS2_32.DLL (%d)", ERRNO);
return CURLE_FAILED_INIT;
}
@ -1148,7 +1148,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
create_event_func = GetProcAddress(wsock2,"WSACreateEvent");
if (create_event_func == NULL) {
failf(data,"failed to find WSACreateEvent function (%d)",
GetLastError());
ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@ -1157,7 +1157,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
close_event_func = GetProcAddress(wsock2,"WSACloseEvent");
if (close_event_func == NULL) {
failf(data,"failed to find WSACloseEvent function (%d)",
GetLastError());
ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@ -1166,7 +1166,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
event_select_func = GetProcAddress(wsock2,"WSAEventSelect");
if (event_select_func == NULL) {
failf(data,"failed to find WSAEventSelect function (%d)",
GetLastError());
ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@ -1175,7 +1175,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents");
if (enum_netevents_func == NULL) {
failf(data,"failed to find WSAEnumNetworkEvents function (%d)",
GetLastError());
ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@ -1188,7 +1188,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* First, create a sockets event object */
event_handle = (WSAEVENT)create_event_func();
if (event_handle == WSA_INVALID_EVENT) {
failf(data,"WSACreateEvent failed (%d)",WSAGetLastError());
failf(data,"WSACreateEvent failed (%d)", SOCKERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@ -1316,7 +1316,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* We called WSACreateEvent, so call WSACloseEvent */
if (close_event_func(event_handle) == FALSE) {
infof(data,"WSACloseEvent failed (%d)",WSAGetLastError());
infof(data,"WSACloseEvent failed (%d)", SOCKERRNO);
}
/* "Forget" pointers into the library we're about to free */
@ -1327,7 +1327,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* We called LoadLibrary, so call FreeLibrary */
if (!FreeLibrary(wsock2))
infof(data,"FreeLibrary(wsock2) failed (%d)",GetLastError());
infof(data,"FreeLibrary(wsock2) failed (%d)", ERRNO);
#else
pfd[0].fd = sockfd;
pfd[0].events = POLLIN;

View File

@ -302,7 +302,7 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
state->conn->ip_addr->ai_addr,
state->conn->ip_addr->ai_addrlen);
if(sbytes < 0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
}
Curl_safefree(filename);
break;
@ -370,7 +370,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
if(sbytes < 0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
}
/* Check if completed (That is, a less than full packet is received) */
@ -399,7 +399,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen);
/* Check all sbytes were sent */
if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
}
}
break;
@ -456,7 +456,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen);
/* Check all sbytes were sent */
if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
res = CURLE_SEND_ERROR;
}
}
@ -481,7 +481,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen);
/* Check all sbytes were sent */
if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
}
break;
@ -502,7 +502,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen);
/* Check all sbytes were sent */
if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno()));
failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
}
}
break;
@ -607,7 +607,7 @@ CURLcode Curl_tftp_connect(struct connectdata *conn, bool *done)
conn->ip_addr->ai_addrlen);
if(rc) {
failf(conn->data, "bind() failed; %s\n",
Curl_strerror(conn, Curl_sockerrno()));
Curl_strerror(conn, SOCKERRNO));
return CURLE_COULDNT_CONNECT;
}
}
@ -689,7 +689,7 @@ CURLcode Curl_tftp(struct connectdata *conn, bool *done)
if(rc == -1) {
/* bail out */
int error = Curl_sockerrno();
int error = SOCKERRNO;
failf(data, "%s\n", Curl_strerror(conn, error));
event = TFTP_EVENT_ERROR;
}

View File

@ -1811,7 +1811,7 @@ Transfer(struct connectdata *conn)
#ifdef EINTR
/* The EINTR is not serious, and it seems you might get this more
ofen when using the lib in a multi-threaded environment! */
if(errno == EINTR)
if(SOCKERRNO == EINTR)
;
else
#endif

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -93,7 +93,7 @@ void logmsg(const char *msg, ...)
void win32_perror (const char *msg)
{
char buf[256];
DWORD err = WSAGetLastError();
DWORD err = SOCKERRNO;
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
LANG_NEUTRAL, buf, sizeof(buf), NULL))

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms