Skip to content

Commit

Permalink
test servers: fix errno, ERRNO and SOCKERRNO usage for W32/W64
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtse committed Jan 9, 2013
1 parent a9ca5e6 commit a684825
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 78 deletions.
10 changes: 5 additions & 5 deletions tests/server/fake_ntlm.c
Expand Up @@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2010, Mandy Wu, <mandy.wu@intel.com>
* Copyright (C) 2011 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2011 - 2013, 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
Expand Down Expand Up @@ -184,7 +184,7 @@ int main(int argc, char *argv[])
filename = test2file(testnum);
stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
Expand All @@ -202,7 +202,7 @@ int main(int argc, char *argv[])

stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
Expand All @@ -222,7 +222,7 @@ int main(int argc, char *argv[])
if(strcmp(buf, type1_input) == 0) {
stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
Expand All @@ -243,7 +243,7 @@ int main(int argc, char *argv[])
else if(strncmp(buf, type3_input, strlen(type3_input)) == 0) {
stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum);
Expand Down
45 changes: 26 additions & 19 deletions tests/server/rtspd.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2013, 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
Expand Down Expand Up @@ -54,6 +54,13 @@
/* include memdebug.h last */
#include "memdebug.h"

#ifdef USE_WINSOCK
#undef EINTR
#define EINTR 4 /* errno.h value */
#undef ERANGE
#define ERANGE 34 /* errno.h value */
#endif

#ifdef ENABLE_IPV6
static bool use_ipv6 = FALSE;
#endif
Expand Down Expand Up @@ -236,43 +243,43 @@ static volatile int exit_signal = 0;

static RETSIGTYPE exit_signal_handler(int signum)
{
int old_errno = ERRNO;
int old_errno = errno;
if(got_exit_signal == 0) {
got_exit_signal = 1;
exit_signal = signum;
}
(void)signal(signum, exit_signal_handler);
SET_ERRNO(old_errno);
errno = old_errno;
}

static void install_signal_handlers(void)
{
#ifdef SIGHUP
/* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO));
logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif
#ifdef SIGPIPE
/* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO));
logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif
#ifdef SIGALRM
/* ignore SIGALRM signal */
if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(ERRNO));
logmsg("cannot install SIGALRM handler: %s", strerror(errno));
#endif
#ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO));
logmsg("cannot install SIGINT handler: %s", strerror(errno));
else
siginterrupt(SIGINT, 1);
#endif
#ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO));
logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else
siginterrupt(SIGTERM, 1);
#endif
Expand Down Expand Up @@ -395,7 +402,7 @@ static int ProcessRequest(struct httprequest *req)

stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", req->testno);
Expand Down Expand Up @@ -575,9 +582,9 @@ static int ProcessRequest(struct httprequest *req)
while(*ptr && ISSPACE(*ptr))
ptr++;
endptr = ptr;
SET_ERRNO(0);
errno = 0;
clen = strtoul(ptr, &endptr, 10);
if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == ERRNO)) {
if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
/* this assumes that a zero Content-Length is valid */
logmsg("Found invalid Content-Length: (%s) in the request", ptr);
req->open = FALSE; /* closes connection */
Expand Down Expand Up @@ -709,7 +716,7 @@ static void storerequest(char *reqbuf, size_t totalsize)

do {
dump = fopen(REQUEST_DUMP, "ab");
} while ((dump == NULL) && ((error = ERRNO) == EINTR));
} while ((dump == NULL) && ((error = errno) == EINTR));
if (dump == NULL) {
logmsg("Error opening file %s error: %d %s",
REQUEST_DUMP, error, strerror(error));
Expand All @@ -725,7 +732,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
} while ((writeleft > 0) && ((error = ERRNO) == EINTR));
} while ((writeleft > 0) && ((error = errno) == EINTR));

if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to " REQUEST_DUMP, totalsize);
Expand All @@ -740,7 +747,7 @@ static void storerequest(char *reqbuf, size_t totalsize)

do {
res = fclose(dump);
} while(res && ((error = ERRNO) == EINTR));
} while(res && ((error = errno) == EINTR));
if(res)
logmsg("Error closing file %s error: %d %s",
REQUEST_DUMP, error, strerror(error));
Expand Down Expand Up @@ -954,7 +961,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)

stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file");
Expand All @@ -979,7 +986,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
/* re-open the same file again */
stream=fopen(filename, "rb");
if(!stream) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file");
Expand Down Expand Up @@ -1024,7 +1031,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)

dump = fopen(RESPONSE_DUMP, "ab");
if(!dump) {
error = ERRNO;
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", RESPONSE_DUMP);
logmsg("couldn't create logfile: " RESPONSE_DUMP);
Expand Down Expand Up @@ -1082,7 +1089,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)

do {
res = fclose(dump);
} while(res && ((error = ERRNO) == EINTR));
} while(res && ((error = errno) == EINTR));
if(res)
logmsg("Error closing file %s error: %d %s",
RESPONSE_DUMP, error, strerror(error));
Expand Down Expand Up @@ -1128,7 +1135,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
break;
if(res) {
/* should not happen */
error = SOCKERRNO;
error = errno;
logmsg("wait_ms() failed with error: (%d) %s",
error, strerror(error));
break;
Expand Down
45 changes: 28 additions & 17 deletions tests/server/sockfilt.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2013, 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
Expand Down Expand Up @@ -109,6 +109,17 @@
/* include memdebug.h last */
#include "memdebug.h"

#ifdef USE_WINSOCK
#undef EINTR
#define EINTR 4 /* errno.h value */
#undef EAGAIN
#define EAGAIN 11 /* errno.h value */
#undef ENOMEM
#define ENOMEM 12 /* errno.h value */
#undef EINVAL
#define EINVAL 22 /* errno.h value */
#endif

#define DEFAULT_PORT 8999

#ifndef DEFAULT_LOGFILE
Expand Down Expand Up @@ -178,43 +189,43 @@ static volatile int exit_signal = 0;

static RETSIGTYPE exit_signal_handler(int signum)
{
int old_errno = ERRNO;
int old_errno = errno;
if(got_exit_signal == 0) {
got_exit_signal = 1;
exit_signal = signum;
}
(void)signal(signum, exit_signal_handler);
SET_ERRNO(old_errno);
errno = old_errno;
}

static void install_signal_handlers(void)
{
#ifdef SIGHUP
/* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO));
logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif
#ifdef SIGPIPE
/* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO));
logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif
#ifdef SIGALRM
/* ignore SIGALRM signal */
if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(ERRNO));
logmsg("cannot install SIGALRM handler: %s", strerror(errno));
#endif
#ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO));
logmsg("cannot install SIGINT handler: %s", strerror(errno));
else
siginterrupt(SIGINT, 1);
#endif
#ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO));
logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else
siginterrupt(SIGTERM, 1);
#endif
Expand Down Expand Up @@ -266,7 +277,7 @@ static ssize_t fullread(int filedes, void *buffer, size_t nbytes)
}

if(rc < 0) {
error = ERRNO;
error = errno;
if((error == EINTR) || (error == EAGAIN))
continue;
logmsg("unrecoverable read() failure: (%d) %s",
Expand Down Expand Up @@ -311,7 +322,7 @@ static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes)
}

if(wc < 0) {
error = ERRNO;
error = errno;
if((error == EINTR) || (error == EAGAIN))
continue;
logmsg("unrecoverable write() failure: (%d) %s",
Expand Down Expand Up @@ -435,7 +446,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,

/* check if the input value is valid */
if(nfds < 0) {
SET_SOCKERRNO(EINVAL);
errno = EINVAL;
return -1;
}

Expand All @@ -448,28 +459,28 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
/* allocate internal array for the original input handles */
fdarr = malloc(nfds * sizeof(curl_socket_t));
if(fdarr == NULL) {
SET_SOCKERRNO(ENOMEM);
errno = ENOMEM;
return -1;
}

/* allocate internal array for the internal event handles */
handles = malloc(nfds * sizeof(HANDLE));
if(handles == NULL) {
SET_SOCKERRNO(ENOMEM);
errno = ENOMEM;
return -1;
}

/* allocate internal array for the internal socket handles */
wsasocks = malloc(nfds * sizeof(curl_socket_t));
if(wsasocks == NULL) {
SET_SOCKERRNO(ENOMEM);
errno = ENOMEM;
return -1;
}

/* allocate internal array for the internal WINSOCK2 events */
wsaevents = malloc(nfds * sizeof(WSAEVENT));
if(wsaevents == NULL) {
SET_SOCKERRNO(ENOMEM);
errno = ENOMEM;
return -1;
}

Expand Down Expand Up @@ -743,7 +754,7 @@ static bool juggle(curl_socket_t *sockfdp,
return FALSE;
}

} while((rc == -1) && ((error = SOCKERRNO) == EINTR));
} while((rc == -1) && ((error = errno) == EINTR));

if(rc < 0) {
logmsg("select() failed with error: (%d) %s",
Expand Down Expand Up @@ -933,7 +944,7 @@ static curl_socket_t sockdaemon(curl_socket_t sock,
rc = wait_ms(delay);
if(rc) {
/* should not happen */
error = SOCKERRNO;
error = errno;
logmsg("wait_ms() failed with error: (%d) %s",
error, strerror(error));
sclose(sock);
Expand Down

0 comments on commit a684825

Please sign in to comment.