From f76b599d28cc72f0f4790195ab7528e711620a6a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 16 Nov 2009 19:21:25 +0000 Subject: [PATCH] Fix 1.4 compilation on msvc, and add a couple of minimal (not-quite-right) nmakefiles. svn:r1534 --- Makefile.nmake | 48 +++++++++++++++++++++++++++++++++++++++ WIN32-Code/event-config.h | 2 ++ event.h | 7 +++++- test/Makefile.nmake | 47 ++++++++++++++++++++++++++++++++++++++ test/test-eof.c | 8 +++++-- test/test-init.c | 7 ++++++ test/test-time.c | 7 ++++++ test/test-weof.c | 8 +++++-- 8 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 Makefile.nmake create mode 100644 test/Makefile.nmake diff --git a/Makefile.nmake b/Makefile.nmake new file mode 100644 index 00000000..f8d57220 --- /dev/null +++ b/Makefile.nmake @@ -0,0 +1,48 @@ +# WATCH OUT! This makefile is a work in progress. It is probably missing +# tons of important things. DO NOT RELY ON IT TO BUILD A GOOD LIBEVENT. + +# Needed for correctness +CFLAGS=/Iinclude /Icompat /IWIN32-Code /DWIN32 /DHAVE_CONFIG_H /I. + +# For optimization and warnings +CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo + +# XXXX have a debug mode + +LIBFLAGS=/nologo + + +CORE_OBJS=event.obj buffer.obj evbuffer.obj \ + log.obj evutil.obj \ + strlcpy.obj signal.obj win32.obj +EXTRA_OBJS=event_tagging.obj http.obj evdns.obj evrpc.obj + +ALL_OBJS=$(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS) +STATIC_LIBS=libevent_core.lib libevent_extras.lib libevent.lib + + +all: static_libs tests + +static_libs: $(STATIC_LIBS) + +win32.obj: WIN32-Code\win32.c + $(CC) $(CFLAGS) /c WIN32-Code\win32.c + +libevent_core.lib: $(CORE_OBJS) + lib $(LIBFLAGS) $(CORE_OBJS) /out:libevent_core.lib + +libevent_extras.lib: $(EXTRA_OBJS) + lib $(LIBFLAGS) $(EXTRA_OBJS) /out:libevent_extras.lib + +libevent.lib: $(CORE_OBJ) $(EXTRA_OBJS) + lib $(LIBFLAGS) $(CORE_OBJS) $(EXTRA_OBJS) /out:libevent.lib + +clean: + del $(ALL_OBJS) + del $(STATIC_LIBS) + cd test + $(MAKE) /F Makefile.nmake clean + +tests: + cd test + $(MAKE) /F Makefile.nmake diff --git a/WIN32-Code/event-config.h b/WIN32-Code/event-config.h index 30590802..2a827443 100644 --- a/WIN32-Code/event-config.h +++ b/WIN32-Code/event-config.h @@ -221,6 +221,8 @@ #define _EVENT_inline __inline #endif +#define _EVENT___func__ __FUNCTION__ + /* Define to `int' if does not define. */ /* #undef _EVENT_pid_t */ diff --git a/event.h b/event.h index 3674216c..cfa0fc3f 100644 --- a/event.h +++ b/event.h @@ -209,6 +209,7 @@ struct { \ #endif /* !TAILQ_ENTRY */ struct event_base; +#ifndef EVENT_NO_STRUCT struct event { TAILQ_ENTRY (event) ev_next; TAILQ_ENTRY (event) ev_active_next; @@ -232,6 +233,9 @@ struct event { int ev_res; /* result passed to event callback */ int ev_flags; }; +#else +struct event; +#endif #define EVENT_SIGNAL(ev) (int)(ev)->ev_fd #define EVENT_FD(ev) (int)(ev)->ev_fd @@ -747,6 +751,7 @@ struct event_watermark { size_t high; }; +#ifndef EVENT_NO_STRUCT struct bufferevent { struct event_base *ev_base; @@ -769,7 +774,7 @@ struct bufferevent { short enabled; /* events that are currently enabled */ }; - +#endif /** Create a new bufferevent. diff --git a/test/Makefile.nmake b/test/Makefile.nmake new file mode 100644 index 00000000..320abe70 --- /dev/null +++ b/test/Makefile.nmake @@ -0,0 +1,47 @@ + +CFLAGS=/I.. /I../include /I../WIN32-Code /I../compat /DWIN32 /DHAVE_CONFIG_H + +CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo + +REGRESS_OBJS=regress.obj regress_http.obj regress_dns.obj \ + regress_rpc.obj regress.gen.obj \ + +OTHER_OBJS=test-init.obj test-eof.obj test-weof.obj test-time.obj \ + bench.obj bench_cascade.obj bench_http.obj bench_httpclient.obj + +PROGRAMS=regress.exe \ + test-init.exe test-eof.exe test-weof.exe test-time.exe + +# Disabled for now: +# bench.exe bench_cascade.exe bench_http.exe bench_httpclient.exe + + +LIBS=..\libevent.lib ws2_32.lib advapi32.lib + +all: $(PROGRAMS) + +regress.exe: $(REGRESS_OBJS) + $(CC) $(CFLAGS) $(LIBS) $(REGRESS_OBJS) + +test-init.exe: test-init.obj + $(CC) $(CFLAGS) $(LIBS) test-init.obj +test-eof.exe: test-eof.obj + $(CC) $(CFLAGS) $(LIBS) test-eof.obj +test-weof.exe: test-weof.obj + $(CC) $(CFLAGS) $(LIBS) test-weof.obj +test-time.exe: test-time.obj + $(CC) $(CFLAGS) $(LIBS) test-time.obj + +bench.exe: bench.obj + $(CC) $(CFLAGS) $(LIBS) bench.obj +bench_cascade.exe: bench_cascade.obj + $(CC) $(CFLAGS) $(LIBS) bench_cascade.obj +bench_http.exe: bench_http.obj + $(CC) $(CFLAGS) $(LIBS) bench_http.obj +bench_httpclient.exe: bench_httpclient.obj + $(CC) $(CFLAGS) $(LIBS) bench_httpclient.obj + +clean: + -del $(REGRESS_OBJS) + -del $(OTHER_OBJS) + -del regress.exe diff --git a/test/test-eof.c b/test/test-eof.c index 4fc1a19f..3264a7b7 100644 --- a/test/test-eof.c +++ b/test/test-eof.c @@ -12,7 +12,9 @@ #endif #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -20,7 +22,9 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include @@ -35,7 +39,7 @@ read_cb(int fd, short event, void *arg) char buf[256]; int len; - len = read(fd, buf, sizeof(buf)); + len = recv(fd, buf, sizeof(buf), 0); printf("%s: read %d%s\n", __func__, len, len ? "" : " - means EOF"); @@ -64,7 +68,7 @@ main (int argc, char **argv) return (1); - write(pair[0], test, strlen(test)+1); + send(pair[0], test, strlen(test)+1, 0); shutdown(pair[0], SHUT_WR); /* Initalize the event library */ diff --git a/test/test-init.c b/test/test-init.c index c368715f..d60aa36b 100644 --- a/test/test-init.c +++ b/test/test-init.c @@ -6,10 +6,15 @@ #include "config.h" #endif +#ifdef WIN32 +#include +#endif #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -17,7 +22,9 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include diff --git a/test/test-time.c b/test/test-time.c index a847d55e..703bc32b 100644 --- a/test/test-time.c +++ b/test/test-time.c @@ -6,15 +6,22 @@ #include "config.h" #endif +#ifdef WIN32 +#include +#endif #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif #include #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include diff --git a/test/test-weof.c b/test/test-weof.c index 5d87ceb8..7fd6c8b1 100644 --- a/test/test-weof.c +++ b/test/test-weof.c @@ -12,7 +12,9 @@ #endif #include #include +#ifdef HAVE_SYS_TIME_H #include +#endif #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -21,7 +23,9 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include @@ -37,7 +41,7 @@ write_cb(int fd, short event, void *arg) const char *test = "test string"; int len; - len = write(fd, test, strlen(test) + 1); + len = send(fd, test, strlen(test) + 1, 0); printf("%s: write %d%s\n", __func__, len, len ? "" : " - means EOF"); @@ -45,7 +49,7 @@ write_cb(int fd, short event, void *arg) if (len > 0) { if (!called) event_add(arg, NULL); - close(pair[0]); + EVUTIL_CLOSESOCKET(pair[0]); } else if (called == 1) test_okay = 0;