--- curl-7.11.1-20040219/tests/server/sws.c Sat Feb 14 03:00:04 2004 +++ curl-new/tests/server/sws.c Mon Feb 23 12:03:34 2004 @@ -38,15 +38,17 @@ #include #include #include -#include + +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif #ifdef _XOPEN_SOURCE_EXTENDED /* This define is "almost" required to build on HPUX 11 */ -#include +#include #endif -#include - #ifndef FALSE #define FALSE 0 #endif @@ -54,6 +56,21 @@ #define TRUE 1 #endif +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#include +#include +#define EINPROGRESS WSAEINPROGRESS +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EISCONN WSAEISCONN +#define ENOTSOCK WSAENOTSOCK +#define ECONNREFUSED WSAECONNREFUSED +#endif + +#ifndef __MINGW32__ +#include +#include +#endif + const char * spitout(FILE *stream, const char *main, @@ -114,7 +131,7 @@ "The requested URL was not found on this server.\n" "


" SWSVERSION "
\n" "\n"; -#ifdef HAVE_SIGNAL +#ifdef SIGPIPE static volatile int sigpipe; #endif static FILE *logfp; @@ -139,7 +156,7 @@ } -#ifdef HAVE_SIGNAL +#ifdef SIGPIPE static void sigpipe_handler(int sig) { (void)sig; /* prevent warning */ @@ -531,6 +548,39 @@ return 0; } +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +static void win32_init(void) +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + wVersionRequested = MAKEWORD(2, 0); + + err = WSAStartup(wVersionRequested, &wsaData); + + if (err != 0) { + perror("Winsock init failed"); + fprintf(logfp, "Error initializing winsock -- aborting\n"); + fclose(logfp); + exit(1); + } + + if ( LOBYTE( wsaData.wVersion ) != 2 || + HIBYTE( wsaData.wVersion ) != 0 ) { + + WSACleanup(); + perror("Winsock init failed"); + fprintf(logfp, "No suitable winsock.dll found -- aborting\n"); + fclose(logfp); + exit(1); + } +} +static void win32_cleanup(void) +{ + WSACleanup(); +} +#endif + int main(int argc, char *argv[]) { struct sockaddr_in me; @@ -553,13 +603,19 @@ perror(logfile); exit(1); } + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) + win32_init(); +#endif +#ifdef SIGPIPE #ifdef HAVE_SIGNAL signal(SIGPIPE, sigpipe_handler); #endif #ifdef HAVE_SIGINTERRUPT siginterrupt(SIGPIPE, 1); #endif +#endif sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { @@ -640,6 +696,10 @@ sclose(sock); fclose(logfp); +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) + win32_cleanup(); +#endif + return 0; }