Make the test/ subdirectory buildable under Windows. Well, mingw at least. The tests still don't all pass, but at least now we know that.

svn:r447
This commit is contained in:
Nick Mathewson 2007-09-20 19:08:20 +00:00
parent d85bce4e96
commit 1e1f77c5b0
10 changed files with 85 additions and 12 deletions

View File

@ -22,3 +22,5 @@ Changes in current version:
o Fix http module on windows to close sockets properly.
o Make autogen.sh script run correctly on systems where /bin/sh isn't bash. (Patch from Trond Norbye, rewritten by Hagne Mahre and then Hannah Schroeter.)
o Skip calling gettime() in timeout_process if we are not in fact waiting for any events. (Patch from Trond Norbye)
o Make test subdirectory compile under mingw.

View File

@ -40,9 +40,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#ifdef WIN32
#include <windows.h>
#else
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/resource.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
@ -51,6 +55,7 @@
#include <errno.h>
#include <event.h>
#include <evutil.h>
static int count, writes, fired;
@ -117,7 +122,9 @@ run_once(void)
int
main (int argc, char **argv)
{
#ifndef WIN32
struct rlimit rl;
#endif
int i, c;
struct timeval *tv;
int *cp;
@ -143,11 +150,13 @@ main (int argc, char **argv)
}
}
#ifndef WIN32
rl.rlim_cur = rl.rlim_max = num_pipes * 2 + 50;
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
perror("setrlimit");
exit(1);
}
#endif
events = calloc(num_pipes, sizeof(struct event));
pipes = calloc(num_pipes * 2, sizeof(int));
@ -162,7 +171,7 @@ main (int argc, char **argv)
#ifdef USE_PIPES
if (pipe(cp) == -1) {
#else
if (socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, cp) == -1) {
#endif
perror("pipe");
exit(1);

View File

@ -45,8 +45,8 @@
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
#endif
#include <netdb.h>
#endif
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
@ -55,6 +55,7 @@
#include <errno.h>
#include "event.h"
#include "evutil.h"
#include "event-internal.h"
#include "log.h"
@ -76,6 +77,10 @@ static struct event_base *global_base;
#define TEST1 "this is a test"
#define SECONDS 1
#ifndef SHUT_WR
#define SHUT_WR 1
#endif
void
simple_read_cb(int fd, short event, void *arg)
{
@ -246,7 +251,7 @@ setup_test(char *name)
fprintf(stdout, "%s", name);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
fprintf(stderr, "%s: socketpair\n", __func__);
exit(1);
}

View File

@ -50,7 +50,9 @@
#ifdef HAVE_NETINET_IN6_H
#include <netinet/in6.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
@ -341,7 +343,7 @@ dns_server(void)
evdns_close_server_port(port);
evdns_shutdown(0); /* remove ourself as nameserver. */
#ifdef WIN32
CloseHandle(sock);
closesocket(sock);
#else
close(sock);
#endif

View File

@ -44,8 +44,8 @@
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
#endif
#include <netdb.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
@ -96,14 +96,34 @@ http_setup(short *pport, struct event_base *base)
return (myhttp);
}
#ifndef NI_MAXSERV
#define NI_MAXSERV 1024
#endif
int
http_connect(const char *address, u_short port)
{
/* Stupid code for connecting */
#ifdef WIN32
struct hostent *he;
struct sockaddr_in sin;
#else
struct addrinfo ai, *aitop;
char strport[NI_MAXSERV];
#endif
struct sockaddr *sa;
int slen;
int fd;
#ifdef WIN32
if (!(he = gethostbyname(address))) {
event_warn("gethostbyname");
}
memcpy(&sin.sin_addr, &he->h_addr, sizeof(struct in_addr));
sin.sin_port = htons(port);
slen = sizeof(struct sockaddr_in);
sa = (struct sockaddr*)&sin;
#else
memset(&ai, 0, sizeof (ai));
ai.ai_family = AF_INET;
ai.ai_socktype = SOCK_STREAM;
@ -112,15 +132,20 @@ http_connect(const char *address, u_short port)
event_warn("getaddrinfo");
return (-1);
}
sa = aitop->ai_addr;
slen = aitop->ai_addrlen;
#endif
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
event_err(1, "socket failed");
if (connect(fd, aitop->ai_addr, aitop->ai_addrlen) == -1)
if (connect(fd, sa, slen) == -1)
event_err(1, "connect failed");
#ifndef WIN32
freeaddrinfo(aitop);
#endif
return (fd);
}

View File

@ -44,8 +44,8 @@
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
#endif
#include <netdb.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

View File

@ -7,10 +7,15 @@
#endif
#ifdef WIN32
#include <winsock2.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
@ -19,6 +24,7 @@
#include <errno.h>
#include <event.h>
#include <evutil.h>
int test_okay = 1;
int called = 0;
@ -43,6 +49,10 @@ read_cb(int fd, short event, void *arg)
called++;
}
#ifndef SHUT_WR
#define SHUT_WR 1
#endif
int
main (int argc, char **argv)
{
@ -50,7 +60,7 @@ main (int argc, char **argv)
char *test = "test string";
int pair[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);

View File

@ -10,7 +10,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

View File

@ -25,6 +25,16 @@ int called = 0;
struct event *ev[NEVENT];
int
rand_int(int n)
{
#ifdef WIN32
return (int)(rand() * n);
#else
return (int)(random() % n);
#endif
}
void
time_cb(int fd, short event, void *arg)
{
@ -35,9 +45,9 @@ time_cb(int fd, short event, void *arg)
if (called < 10*NEVENT) {
for (i = 0; i < 10; i++) {
j = random() % NEVENT;
j = rand_int(NEVENT);
tv.tv_sec = 0;
tv.tv_usec = random() % 50000L;
tv.tv_usec = rand_int(50000);
if (tv.tv_usec % 2)
evtimer_add(ev[j], &tv);
else
@ -61,7 +71,7 @@ main (int argc, char **argv)
/* Initalize one event */
evtimer_set(ev[i], time_cb, ev[i]);
tv.tv_sec = 0;
tv.tv_usec = random() % 50000L;
tv.tv_usec = rand_int(50000);
evtimer_add(ev[i], &tv);
}

View File

@ -7,10 +7,15 @@
#endif
#ifdef WIN32
#include <winsock2.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
@ -20,6 +25,7 @@
#include <errno.h>
#include <event.h>
#include <evutil.h>
int pair[2];
int test_okay = 1;
@ -51,10 +57,12 @@ main (int argc, char **argv)
{
struct event ev;
#ifndef WIN32
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
return (1);
#endif
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
return (1);
/* Initalize the event library */