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, long timeout_ms,
bool *connected); 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 * Curl_nonblock() set the given socket to either blocking or non-blocking
* mode based on the 'nonblock' boolean argument. This function is highly * 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, if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
data->set.device, strlen(data->set.device)+1) != 0) { data->set.device, strlen(data->set.device)+1) != 0) {
/* printf("Failed to BINDTODEVICE, socket: %d device: %s error: %s\n", /* 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", infof(data, "SO_BINDTODEVICE %s failed\n",
data->set.device); data->set.device);
/* This is typically "errno 1, error: Operation not permitted" if /* This is typically "errno 1, error: Operation not permitted" if
@ -409,7 +396,7 @@ static CURLcode bindlocal(struct connectdata *conn,
break; break;
} while(1); } while(1);
data->state.os_errno = Curl_sockerrno(); data->state.os_errno = SOCKERRNO;
failf(data, "bind failure: %s", failf(data, "bind failure: %s",
Curl_strerror(conn, data->state.os_errno)); Curl_strerror(conn, data->state.os_errno));
return CURLE_HTTP_PORT_FAILED; 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, if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
(void *)&err, &errSize)) (void *)&err, &errSize))
err = Curl_sockerrno(); err = SOCKERRNO;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
/* Always returns this error, bug in CE? */ /* Always returns this error, bug in CE? */
@ -472,7 +459,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
#else #else
(void)sockfd; (void)sockfd;
if (error) if (error)
*error = Curl_sockerrno(); *error = SOCKERRNO;
#endif #endif
return rc; return rc;
} }
@ -613,7 +600,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
infof(data, "Connection failed\n"); infof(data, "Connection failed\n");
if(trynextip(conn, sockindex, connected)) { if(trynextip(conn, sockindex, connected)) {
error = Curl_sockerrno(); error = SOCKERRNO;
data->state.os_errno = error; data->state.os_errno = error;
failf(data, "Failed connect to %s:%d; %s", failf(data, "Failed connect to %s:%d; %s",
conn->host.name, conn->port, Curl_strerror(conn,error)); 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, if(setsockopt(sockfd, proto, TCP_NODELAY, (void *)&onoff,
sizeof(onoff)) < 0) sizeof(onoff)) < 0)
infof(data, "Could not set TCP_NODELAY: %s\n", infof(data, "Could not set TCP_NODELAY: %s\n",
Curl_strerror(conn, Curl_sockerrno())); Curl_strerror(conn, SOCKERRNO));
else else
infof(data,"TCP_NODELAY set\n"); infof(data,"TCP_NODELAY set\n");
#else #else
@ -667,7 +654,7 @@ static void nosigpipe(struct connectdata *conn,
if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff, if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff,
sizeof(onoff)) < 0) sizeof(onoff)) < 0)
infof(data, "Could not set SO_NOSIGPIPE: %s\n", infof(data, "Could not set SO_NOSIGPIPE: %s\n",
Curl_strerror(conn, Curl_sockerrno())); Curl_strerror(conn, SOCKERRNO));
} }
#else #else
#define nosigpipe(x,y) #define nosigpipe(x,y)
@ -731,7 +718,7 @@ singleipconnect(struct connectdata *conn,
rc = 0; rc = 0;
if(-1 == rc) { if(-1 == rc) {
error = Curl_sockerrno(); error = SOCKERRNO;
switch (error) { switch (error) {
case EINPROGRESS: 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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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? */ bool *connected /* truly connected? */
); );
int Curl_sockerrno(void);
CURLcode Curl_store_ip_addr(struct connectdata *conn); CURLcode Curl_store_ip_addr(struct connectdata *conn);
#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */ #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 */ /* do the translation ourselves */
char *input_ptr, *output_ptr; char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc; size_t in_bytes, out_bytes, rc;
int error;
/* open an iconv conversion descriptor if necessary */ /* open an iconv conversion descriptor if necessary */
if(data->outbound_cd == (iconv_t)-1) { if(data->outbound_cd == (iconv_t)-1) {
data->outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK, data->outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK,
CURL_ICONV_CODESET_OF_HOST); CURL_ICONV_CODESET_OF_HOST);
if(data->outbound_cd == (iconv_t)-1) { if(data->outbound_cd == (iconv_t)-1) {
error = ERRNO;
failf(data, failf(data,
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s", "The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
CURL_ICONV_CODESET_OF_NETWORK, CURL_ICONV_CODESET_OF_NETWORK,
CURL_ICONV_CODESET_OF_HOST, CURL_ICONV_CODESET_OF_HOST,
errno, strerror(errno)); error, strerror(error));
return CURLE_CONV_FAILED; 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, rc = iconv(data->outbound_cd, (const char**)&input_ptr, &in_bytes,
&output_ptr, &out_bytes); &output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) { if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO;
failf(data, failf(data,
"The Curl_convert_to_network iconv call failed with errno %i: %s", "The Curl_convert_to_network iconv call failed with errno %i: %s",
errno, strerror(errno)); error, strerror(error));
return CURLE_CONV_FAILED; return CURLE_CONV_FAILED;
} }
#else #else
@ -807,17 +810,19 @@ CURLcode Curl_convert_from_network(struct SessionHandle *data,
/* do the translation ourselves */ /* do the translation ourselves */
char *input_ptr, *output_ptr; char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc; size_t in_bytes, out_bytes, rc;
int error;
/* open an iconv conversion descriptor if necessary */ /* open an iconv conversion descriptor if necessary */
if(data->inbound_cd == (iconv_t)-1) { if(data->inbound_cd == (iconv_t)-1) {
data->inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST, data->inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_OF_NETWORK); CURL_ICONV_CODESET_OF_NETWORK);
if(data->inbound_cd == (iconv_t)-1) { if(data->inbound_cd == (iconv_t)-1) {
error = ERRNO;
failf(data, failf(data,
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s", "The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
CURL_ICONV_CODESET_OF_HOST, CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_OF_NETWORK, CURL_ICONV_CODESET_OF_NETWORK,
errno, strerror(errno)); error, strerror(error));
return CURLE_CONV_FAILED; 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, rc = iconv(data->inbound_cd, (const char **)&input_ptr, &in_bytes,
&output_ptr, &out_bytes); &output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) { if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO;
failf(data, failf(data,
"The Curl_convert_from_network iconv call failed with errno %i: %s", "The Curl_convert_from_network iconv call failed with errno %i: %s",
errno, strerror(errno)); error, strerror(error));
return CURLE_CONV_FAILED; return CURLE_CONV_FAILED;
} }
#else #else
@ -864,17 +870,19 @@ CURLcode Curl_convert_from_utf8(struct SessionHandle *data,
/* do the translation ourselves */ /* do the translation ourselves */
char *input_ptr, *output_ptr; char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc; size_t in_bytes, out_bytes, rc;
int error;
/* open an iconv conversion descriptor if necessary */ /* open an iconv conversion descriptor if necessary */
if(data->utf8_cd == (iconv_t)-1) { if(data->utf8_cd == (iconv_t)-1) {
data->utf8_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST, data->utf8_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_FOR_UTF8); CURL_ICONV_CODESET_FOR_UTF8);
if(data->utf8_cd == (iconv_t)-1) { if(data->utf8_cd == (iconv_t)-1) {
error = ERRNO;
failf(data, failf(data,
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s", "The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
CURL_ICONV_CODESET_OF_HOST, CURL_ICONV_CODESET_OF_HOST,
CURL_ICONV_CODESET_FOR_UTF8, CURL_ICONV_CODESET_FOR_UTF8,
errno, strerror(errno)); error, strerror(error));
return CURLE_CONV_FAILED; 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, rc = iconv(data->utf8_cd, (const char**)&input_ptr, &in_bytes,
&output_ptr, &out_bytes); &output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) { if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO;
failf(data, failf(data,
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s", "The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
errno, strerror(errno)); error, strerror(error));
return CURLE_CONV_FAILED; return CURLE_CONV_FAILED;
} }
if (output_ptr < input_ptr) { 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 */ case -1: /* select() error, stop reading */
result = CURLE_RECV_ERROR; result = CURLE_RECV_ERROR;
failf(data, "FTP response aborted due to select() error: %d", failf(data, "FTP response aborted due to select() error: %d",
Curl_sockerrno()); SOCKERRNO);
break; break;
case 0: /* timeout */ case 0: /* timeout */
if(Curl_pgrsUpdate(conn)) if(Curl_pgrsUpdate(conn))
@ -841,7 +841,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss); sslen = sizeof(ss);
if (getsockname(conn->sock[FIRSTSOCKET], (struct sockaddr *)&ss, &sslen)) { if (getsockname(conn->sock[FIRSTSOCKET], (struct sockaddr *)&ss, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) ); Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED; 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); portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock == CURL_SOCKET_BAD) { if (portsock == CURL_SOCKET_BAD) {
error = Curl_sockerrno(); error = SOCKERRNO;
continue; continue;
} }
break; break;
@ -902,7 +902,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if (getsockname(conn->sock[FIRSTSOCKET], if (getsockname(conn->sock[FIRSTSOCKET],
(struct sockaddr *)sa, &sslen)) { (struct sockaddr *)sa, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) ); Curl_strerror(conn, SOCKERRNO) );
sclose(portsock); sclose(portsock);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -917,7 +917,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss); sslen = sizeof(ss);
if(bind(portsock, (struct sockaddr *)sa, sslen)) { 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); sclose(portsock);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -928,7 +928,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss); sslen = sizeof(ss);
if(getsockname(portsock, (struct sockaddr *)sa, &sslen)) { if(getsockname(portsock, (struct sockaddr *)sa, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) ); Curl_strerror(conn, SOCKERRNO) );
sclose(portsock); sclose(portsock);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -936,7 +936,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* step 4, listen on the socket */ /* step 4, listen on the socket */
if (listen(portsock, 1)) { 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); sclose(portsock);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -1080,7 +1080,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if (getsockname(conn->sock[FIRSTSOCKET], if (getsockname(conn->sock[FIRSTSOCKET],
(struct sockaddr *)&sa, &sslen)) { (struct sockaddr *)&sa, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) ); Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
if (sslen > (socklen_t)sizeof(sa)) 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, if(getsockname(portsock, (struct sockaddr *) &add,
&socksize)) { &socksize)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, Curl_sockerrno()) ); Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
porttouse = ntohs(add.sin_port); porttouse = ntohs(add.sin_port);

View File

@ -176,7 +176,7 @@ static CURLcode handshake(struct connectdata *conn,
} }
else { else {
/* anything that gets here is fatally bad */ /* 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; return CURLE_SSL_CONNECT_ERROR;
} }
} }
@ -567,7 +567,7 @@ int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
} }
else { else {
/* anything that gets here is fatally bad */ /* 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; retval = -1;
done = 1; done = 1;
} }

View File

@ -76,7 +76,7 @@
#include "strerror.h" #include "strerror.h"
#include "url.h" #include "url.h"
#include "multiif.h" #include "multiif.h"
#include "connect.h" /* for the Curl_sockerrno() proto */ #include "connect.h"
#define _MPRINTF_REPLACE /* use our functions only */ #define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h> #include <curl/mprintf.h>
@ -214,7 +214,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
break; break;
tvp = ares_timeout(data->state.areschannel, &store, &tv); tvp = ares_timeout(data->state.areschannel, &store, &tv);
count = select(nfds, &read_fds, &write_fds, NULL, tvp); count = select(nfds, &read_fds, &write_fds, NULL, tvp);
if (count < 0 && Curl_sockerrno() != EINVAL) if ((count < 0) && (SOCKERRNO != EINVAL))
break; break;
ares_process(data->state.areschannel, &read_fds, &write_fds); 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 *)buf,
(struct hostent_data *)((char *)buf + (struct hostent_data *)((char *)buf +
sizeof(struct hostent))); 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 else
res = -1; /* failure, too smallish buffer size */ 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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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))) if (Curl_printable_address(ai, buf, sizeof(buf)))
printf("%s\n", buf); printf("%s\n", buf);
else else
printf("failed; %s\n", Curl_strerror(conn, Curl_sockerrno())); printf("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
} }
} }
#else #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))) if (Curl_printable_address(ai, buf, sizeof(buf)))
trace_it("%s\n", buf); trace_it("%s\n", buf);
else else
trace_it("failed; %s\n", Curl_strerror(conn,WSAGetLastError())); trace_it("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
} }
} }
#endif #endif
@ -301,7 +301,8 @@ static unsigned __stdcall gethostbyname_thread (void *arg)
return (unsigned)-1; 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 /* Signaling that we have initialized all copies of data and handles we
need */ need */
@ -318,7 +319,7 @@ static unsigned __stdcall gethostbyname_thread (void *arg)
rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he); rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he);
} }
else { 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, TRACE(("Winsock-error %d, addr %s\n", conn->async.status,
he ? inet_ntoa(*(struct in_addr*)he->h_addr) : "unknown")); 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); 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 /* Signaling that we have initialized all copies of data and handles we
need */ need */
@ -383,7 +385,7 @@ static unsigned __stdcall getaddrinfo_thread (void *arg)
rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res); rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res);
} }
else { 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)); TRACE(("Winsock-error %d, no address\n", conn->async.status));
} }
release_thread_sync(&tsd); release_thread_sync(&tsd);
@ -461,7 +463,7 @@ static bool init_resolve_thread (struct connectdata *conn,
HANDLE thread_and_event[2] = {0}; HANDLE thread_and_event[2] = {0};
if (!td) { if (!td) {
SetLastError(ENOMEM); SET_ERRNO(ENOMEM);
return FALSE; return FALSE;
} }
@ -469,7 +471,7 @@ static bool init_resolve_thread (struct connectdata *conn,
conn->async.hostname = strdup(hostname); conn->async.hostname = strdup(hostname);
if (!conn->async.hostname) { if (!conn->async.hostname) {
free(td); free(td);
SetLastError(ENOMEM); SET_ERRNO(ENOMEM);
return FALSE; return FALSE;
} }
@ -486,7 +488,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->mutex_waiting = CreateMutex(NULL, TRUE, NULL); td->mutex_waiting = CreateMutex(NULL, TRUE, NULL);
if (td->mutex_waiting == NULL) { if (td->mutex_waiting == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
} }
@ -496,7 +498,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL); td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_resolved == NULL) { if (td->event_resolved == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
} }
/* Create the mutex used to serialize access to event_terminated /* 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); td->mutex_terminate = CreateMutex(NULL, FALSE, NULL);
if (td->mutex_terminate == NULL) { if (td->mutex_terminate == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
} }
/* Create the event used to signal thread that it should terminate. /* 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); td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_terminate == NULL) { if (td->event_terminate == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
} }
/* Create the event used by thread to inform it has initialized its own data. /* 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); td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_thread_started == NULL) { if (td->event_thread_started == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SetLastError(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
} }
@ -543,10 +545,10 @@ static bool init_resolve_thread (struct connectdata *conn,
if (!td->thread_hnd) { if (!td->thread_hnd) {
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn,GetLastError()))); TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn, ERRNO)));
#else #else
SetLastError(errno); SET_ERRNO(errno);
TRACE(("_beginthreadex() failed; %s\n", Curl_strerror(conn,errno))); TRACE(("_beginthreadex() failed; %s\n", Curl_strerror(conn, ERRNO)));
#endif #endif
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
return FALSE; return FALSE;
@ -627,7 +629,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
* thread. 'conn->async.done = TRUE' is set in * thread. 'conn->async.done = TRUE' is set in
* Curl_addrinfo4/6_callback(). * Curl_addrinfo4/6_callback().
*/ */
WSASetLastError(conn->async.status); SET_SOCKERRNO(conn->async.status);
GetExitCodeThread(td->thread_hnd, &td->thread_status); GetExitCodeThread(td->thread_hnd, &td->thread_status);
TRACE(("%s() status %lu, thread retval %lu, ", TRACE(("%s() status %lu, thread retval %lu, ",
THREAD_NAME, status, td->thread_status)); THREAD_NAME, status, td->thread_status));
@ -749,12 +751,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* fall-back to blocking version */ /* fall-back to blocking version */
infof(data, "init_resolve_thread() failed for %s; %s\n", infof(data, "init_resolve_thread() failed for %s; %s\n",
hostname, Curl_strerror(conn,GetLastError())); hostname, Curl_strerror(conn, ERRNO));
h = gethostbyname(hostname); h = gethostbyname(hostname);
if (!h) { if (!h) {
infof(data, "gethostbyname(2) failed for %s:%d; %s\n", 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 NULL;
} }
return Curl_he2ai(h, port); return Curl_he2ai(h, port);
@ -826,12 +828,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* fall-back to blocking version */ /* fall-back to blocking version */
infof(data, "init_resolve_thread() failed for %s; %s\n", 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); error = getaddrinfo(hostname, sbuf, &hints, &res);
if (error) { if (error) {
infof(data, "getaddrinfo() failed for %s:%d; %s\n", infof(data, "getaddrinfo() failed for %s:%d; %s\n",
hostname, port, Curl_strerror(conn,WSAGetLastError())); hostname, port, Curl_strerror(conn, SOCKERRNO));
return NULL; return NULL;
} }
return res; 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 * 1 if the address was valid for the specified address family
* 0 if the address wasn't valid (`dst' is untouched in this case) * 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) * -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: * author:
* Paul Vixie, 1996. * Paul Vixie, 1996.
*/ */
@ -83,7 +88,7 @@ Curl_inet_pton(int af, const char *src, void *dst)
return (inet_pton6(src, (unsigned char *)dst)); return (inet_pton6(src, (unsigned char *)dst));
#endif #endif
default: default:
errno = EAFNOSUPPORT; SET_ERRNO(EAFNOSUPPORT);
return (-1); return (-1);
} }
/* NOTREACHED */ /* 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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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) if(source)
fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n", fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func); source, line, func);
errno = ENOMEM; SET_ERRNO(ENOMEM);
return TRUE; /* RETURN ERROR! */ return TRUE; /* RETURN ERROR! */
} }
else else

View File

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

View File

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

View File

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

View File

@ -49,7 +49,7 @@
#include "url.h" /* for the ssl config check function */ #include "url.h" /* for the ssl config check function */
#include "inet_pton.h" #include "inet_pton.h"
#include "ssluse.h" #include "ssluse.h"
#include "connect.h" /* Curl_sockerrno() proto */ #include "connect.h"
#include "strequal.h" #include "strequal.h"
#include "select.h" #include "select.h"
#include "sslgen.h" #include "sslgen.h"
@ -781,7 +781,7 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
sslerror = ERR_get_error(); sslerror = ERR_get_error();
failf(conn->data, "SSL read: %s, errno %d", failf(conn->data, "SSL read: %s, errno %d",
ERR_error_string(sslerror, buf), ERR_error_string(sslerror, buf),
Curl_sockerrno() ); SOCKERRNO);
done = 1; done = 1;
break; break;
} }
@ -794,7 +794,7 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
} }
else { else {
/* anything that gets here is fatally bad */ /* 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; retval = -1;
done = 1; done = 1;
} }
@ -1739,7 +1739,7 @@ Curl_ossl_connect_common(struct connectdata *conn,
} }
else { else {
/* anything that gets here is fatally bad */ /* 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; return CURLE_SSL_CONNECT_ERROR;
} }
} /* while()-loop for the select() */ } /* while()-loop for the select() */
@ -1822,7 +1822,7 @@ ssize_t Curl_ossl_send(struct connectdata *conn,
return 0; return 0;
case SSL_ERROR_SYSCALL: case SSL_ERROR_SYSCALL:
failf(conn->data, "SSL_write() returned SYSCALL, errno = %d\n", failf(conn->data, "SSL_write() returned SYSCALL, errno = %d\n",
Curl_sockerrno()); SOCKERRNO);
return -1; return -1;
case SSL_ERROR_SSL: case SSL_ERROR_SSL:
/* A failure in the SSL library occurred, usually a protocol error. /* 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(); sslerror = ERR_get_error();
failf(conn->data, "SSL read: %s, errno %d", failf(conn->data, "SSL read: %s, errno %d",
ERR_error_string(sslerror, error_buffer), ERR_error_string(sslerror, error_buffer),
Curl_sockerrno() ); SOCKERRNO);
return -1; 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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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 else
value = CURL_LLONG_MAX; value = CURL_LLONG_MAX;
errno = ERANGE; SET_ERRNO(ERANGE);
} }
if (endptr) 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); bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
if(bytes_written < 0) { if(bytes_written < 0) {
err = Curl_sockerrno(); err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err); 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); CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE);
bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
if(bytes_written < 0) { if(bytes_written < 0) {
err = Curl_sockerrno(); err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err); failf(data,"Sending data failed (%d)",err);
} }
printsub(data, '>', &temp[2], len-2); 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); CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE);
bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
if(bytes_written < 0) { if(bytes_written < 0) {
err = Curl_sockerrno(); err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err); failf(data,"Sending data failed (%d)",err);
} }
printsub(data, '>', &temp[2], len-2); printsub(data, '>', &temp[2], len-2);
@ -911,7 +911,7 @@ static void suboption(struct connectdata *conn)
len += 2; len += 2;
bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
if(bytes_written < 0) { if(bytes_written < 0) {
err = Curl_sockerrno(); err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err); failf(data,"Sending data failed (%d)",err);
} }
printsub(data, '>', &temp[2], len-2); 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. */ /* load ws2_32.dll and get the function pointers we need. */
wsock2 = LoadLibrary("WS2_32.DLL"); wsock2 = LoadLibrary("WS2_32.DLL");
if (wsock2 == NULL) { 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; return CURLE_FAILED_INIT;
} }
@ -1148,7 +1148,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
create_event_func = GetProcAddress(wsock2,"WSACreateEvent"); create_event_func = GetProcAddress(wsock2,"WSACreateEvent");
if (create_event_func == NULL) { if (create_event_func == NULL) {
failf(data,"failed to find WSACreateEvent function (%d)", failf(data,"failed to find WSACreateEvent function (%d)",
GetLastError()); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -1157,7 +1157,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
close_event_func = GetProcAddress(wsock2,"WSACloseEvent"); close_event_func = GetProcAddress(wsock2,"WSACloseEvent");
if (close_event_func == NULL) { if (close_event_func == NULL) {
failf(data,"failed to find WSACloseEvent function (%d)", failf(data,"failed to find WSACloseEvent function (%d)",
GetLastError()); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -1166,7 +1166,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
event_select_func = GetProcAddress(wsock2,"WSAEventSelect"); event_select_func = GetProcAddress(wsock2,"WSAEventSelect");
if (event_select_func == NULL) { if (event_select_func == NULL) {
failf(data,"failed to find WSAEventSelect function (%d)", failf(data,"failed to find WSAEventSelect function (%d)",
GetLastError()); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -1175,7 +1175,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents"); enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents");
if (enum_netevents_func == NULL) { if (enum_netevents_func == NULL) {
failf(data,"failed to find WSAEnumNetworkEvents function (%d)", failf(data,"failed to find WSAEnumNetworkEvents function (%d)",
GetLastError()); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -1188,7 +1188,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* First, create a sockets event object */ /* First, create a sockets event object */
event_handle = (WSAEVENT)create_event_func(); event_handle = (WSAEVENT)create_event_func();
if (event_handle == WSA_INVALID_EVENT) { if (event_handle == WSA_INVALID_EVENT) {
failf(data,"WSACreateEvent failed (%d)",WSAGetLastError()); failf(data,"WSACreateEvent failed (%d)", SOCKERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -1316,7 +1316,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* We called WSACreateEvent, so call WSACloseEvent */ /* We called WSACreateEvent, so call WSACloseEvent */
if (close_event_func(event_handle) == FALSE) { 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 */ /* "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 */ /* We called LoadLibrary, so call FreeLibrary */
if (!FreeLibrary(wsock2)) if (!FreeLibrary(wsock2))
infof(data,"FreeLibrary(wsock2) failed (%d)",GetLastError()); infof(data,"FreeLibrary(wsock2) failed (%d)", ERRNO);
#else #else
pfd[0].fd = sockfd; pfd[0].fd = sockfd;
pfd[0].events = POLLIN; 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_addr,
state->conn->ip_addr->ai_addrlen); state->conn->ip_addr->ai_addrlen);
if(sbytes < 0) { 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); Curl_safefree(filename);
break; break;
@ -370,7 +370,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
(struct sockaddr *)&state->remote_addr, (struct sockaddr *)&state->remote_addr,
state->remote_addrlen); state->remote_addrlen);
if(sbytes < 0) { 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) */ /* 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); state->remote_addrlen);
/* Check all sbytes were sent */ /* Check all sbytes were sent */
if(sbytes<0) { if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno())); failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
} }
} }
break; break;
@ -456,7 +456,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen); state->remote_addrlen);
/* Check all sbytes were sent */ /* Check all sbytes were sent */
if(sbytes<0) { 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; res = CURLE_SEND_ERROR;
} }
} }
@ -481,7 +481,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen); state->remote_addrlen);
/* Check all sbytes were sent */ /* Check all sbytes were sent */
if(sbytes<0) { if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno())); failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
} }
break; break;
@ -502,7 +502,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen); state->remote_addrlen);
/* Check all sbytes were sent */ /* Check all sbytes were sent */
if(sbytes<0) { if(sbytes<0) {
failf(data, "%s\n", Curl_strerror(state->conn, Curl_sockerrno())); failf(data, "%s\n", Curl_strerror(state->conn, SOCKERRNO));
} }
} }
break; break;
@ -607,7 +607,7 @@ CURLcode Curl_tftp_connect(struct connectdata *conn, bool *done)
conn->ip_addr->ai_addrlen); conn->ip_addr->ai_addrlen);
if(rc) { if(rc) {
failf(conn->data, "bind() failed; %s\n", failf(conn->data, "bind() failed; %s\n",
Curl_strerror(conn, Curl_sockerrno())); Curl_strerror(conn, SOCKERRNO));
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
} }
@ -689,7 +689,7 @@ CURLcode Curl_tftp(struct connectdata *conn, bool *done)
if(rc == -1) { if(rc == -1) {
/* bail out */ /* bail out */
int error = Curl_sockerrno(); int error = SOCKERRNO;
failf(data, "%s\n", Curl_strerror(conn, error)); failf(data, "%s\n", Curl_strerror(conn, error));
event = TFTP_EVENT_ERROR; event = TFTP_EVENT_ERROR;
} }

View File

@ -1811,7 +1811,7 @@ Transfer(struct connectdata *conn)
#ifdef EINTR #ifdef EINTR
/* The EINTR is not serious, and it seems you might get this more /* The EINTR is not serious, and it seems you might get this more
ofen when using the lib in a multi-threaded environment! */ ofen when using the lib in a multi-threaded environment! */
if(errno == EINTR) if(SOCKERRNO == EINTR)
; ;
else else
#endif #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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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) void win32_perror (const char *msg)
{ {
char buf[256]; char buf[256];
DWORD err = WSAGetLastError(); DWORD err = SOCKERRNO;
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
LANG_NEUTRAL, buf, sizeof(buf), NULL)) 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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms