summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--Makefile.am6
-rw-r--r--WIN32-Code/misc.c93
-rw-r--r--WIN32-Code/misc.h11
-rw-r--r--evdns.c4
-rw-r--r--event.c4
-rw-r--r--evutil.c21
-rw-r--r--include/event2/util.h6
8 files changed, 36 insertions, 111 deletions
diff --git a/ChangeLog b/ChangeLog
index cfc8e45f..fb2c68a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -95,6 +95,8 @@ Changes in current version:
o event_base_new_with_config() and corresponding config APIs.
o migrate the evhttp header to event2/ but accessors are still missing.
o deprecate timeout_* event functions by moving them to event_compat.h
+ o Move windows gettimeofday replacement into a new evutil_gettimeofday().
+
Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
diff --git a/Makefile.am b/Makefile.am
index b55468cd..c3144567 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,8 +39,8 @@ EXTRA_DIST = autogen.sh event.h event-internal.h log.h evsignal.h evdns.3 \
test/test-eof.c test/test-weof.c test/test-time.c \
test/test-init.c test/test.sh \
compat/sys/queue.h compat/sys/_time.h \
- WIN32-Code/config.h WIN32-Code/misc.c \
- WIN32-Code/win32.c WIN32-Code/misc.h \
+ WIN32-Code/config.h \
+ WIN32-Code/win32.c \
WIN32-Code/tree.h \
WIN32-Prj/event_test/event_test.dsp \
WIN32-Prj/event_test/test.txt WIN32-Prj/libevent.dsp \
@@ -54,7 +54,7 @@ SUBDIRS = . include sample test
if BUILD_WIN32
SYS_LIBS = -lws2_32
-SYS_SRC = WIN32-Code/misc.c WIN32-Code/win32.c
+SYS_SRC = WIN32-Code/win32.c
SYS_INCLUDES = -IWIN32-Code
else
diff --git a/WIN32-Code/misc.c b/WIN32-Code/misc.c
deleted file mode 100644
index 371e192b..00000000
--- a/WIN32-Code/misc.c
+++ /dev/null
@@ -1,93 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <windows.h>
-#include <sys/timeb.h>
-#include <time.h>
-
-#ifdef __GNUC__
-/*our prototypes for timeval and timezone are in here, just in case the above
- headers don't have them*/
-#include "misc.h"
-#endif
-
-/****************************************************************************
- *
- * Function: gettimeofday(struct timeval *, struct timezone *)
- *
- * Purpose: Get current time of day.
- *
- * Arguments: tv => Place to store the curent time of day.
- * tz => Ignored.
- *
- * Returns: 0 => Success.
- *
- ****************************************************************************/
-
-#ifndef HAVE_GETTIMEOFDAY
-int gettimeofday(struct timeval *tv, struct timezone *tz) {
- struct _timeb tb;
-
- if(tv == NULL)
- return -1;
-
- _ftime(&tb);
- tv->tv_sec = (long) tb.time;
- tv->tv_usec = ((int) tb.millitm) * 1000;
- return 0;
-}
-#endif
-
-#if 0
-int
-win_read(int fd, void *buf, unsigned int length)
-{
- DWORD dwBytesRead;
- int res = ReadFile((HANDLE) fd, buf, length, &dwBytesRead, NULL);
- if (res == 0) {
- DWORD error = GetLastError();
- if (error == ERROR_NO_DATA)
- return (0);
- return (-1);
- } else
- return (dwBytesRead);
-}
-
-int
-win_write(int fd, void *buf, unsigned int length)
-{
- DWORD dwBytesWritten;
- int res = WriteFile((HANDLE) fd, buf, length, &dwBytesWritten, NULL);
- if (res == 0) {
- DWORD error = GetLastError();
- if (error == ERROR_NO_DATA)
- return (0);
- return (-1);
- } else
- return (dwBytesWritten);
-}
-
-int
-socketpair(int d, int type, int protocol, int *sv)
-{
- static int count;
- char buf[64];
- HANDLE fd;
- DWORD dwMode;
- sprintf(buf, "\\\\.\\pipe\\levent-%d", count++);
- /* Create a duplex pipe which will behave like a socket pair */
- fd = CreateNamedPipe(buf, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_NOWAIT,
- PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, NULL);
- if (fd == INVALID_HANDLE_VALUE)
- return (-1);
- sv[0] = (int)fd;
-
- fd = CreateFile(buf, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (fd == INVALID_HANDLE_VALUE)
- return (-1);
- dwMode = PIPE_NOWAIT;
- SetNamedPipeHandleState(fd, &dwMode, NULL, NULL);
- sv[1] = (int)fd;
-
- return (0);
-}
-#endif
diff --git a/WIN32-Code/misc.h b/WIN32-Code/misc.h
deleted file mode 100644
index aced5746..00000000
--- a/WIN32-Code/misc.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef MISC_H
-#define MISC_H
-
-struct timezone;
-struct timeval;
-
-#ifndef HAVE_GETTIMEOFDAY
-int gettimeofday(struct timeval *,struct timezone *);
-#endif
-
-#endif
diff --git a/evdns.c b/evdns.c
index f0e9b969..c495bd34 100644
--- a/evdns.c
+++ b/evdns.c
@@ -1084,13 +1084,13 @@ default_transaction_id_fn(void)
#ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
struct timeval tv;
- gettimeofday(&tv, NULL);
+ evutil_gettimeofday(&tv, NULL);
trans_id = tv.tv_usec & 0xffff;
#endif
#ifdef DNS_USE_OPENSSL_FOR_ID
if (RAND_pseudo_bytes((u8 *) &trans_id, 2) == -1) {
- /* in the case that the RAND call fails we back */
+ /* in the case that the RAND call fails we used to back */
/* down to using gettimeofday. */
/*
struct timeval tv;
diff --git a/event.c b/event.c
index 2f5ffa93..3dab7773 100644
--- a/event.c
+++ b/event.c
@@ -171,7 +171,7 @@ gettime(struct event_base *base, struct timeval *tp)
}
#endif
- return (gettimeofday(tp, NULL));
+ return (evutil_gettimeofday(tp, NULL));
}
struct event_base *
@@ -895,7 +895,7 @@ event_pending(struct event *ev, short event, struct timeval *tv)
gettime(ev->ev_base, &now);
evutil_timersub(&ev->ev_timeout, &now, &res);
/* correctly remap to real time */
- gettimeofday(&now, NULL);
+ evutil_gettimeofday(&now, NULL);
evutil_timeradd(&now, &res, tv);
}
diff --git a/evutil.c b/evutil.c
index 7407a707..d6176cf6 100644
--- a/evutil.c
+++ b/evutil.c
@@ -51,6 +51,11 @@
#endif
#include <errno.h>
+#ifndef _EVENT_HAVE_GETTIMEOFDAY
+#include <sys/timeb.h>
+#include <time.h>
+#endif
+
#include "event2/util.h"
#include "log.h"
@@ -196,3 +201,19 @@ evutil_strtoll(const char *s, char **endptr, int base)
#error "I don't know how to parse 64-bit integers."
#endif
}
+
+#ifndef _EVENT_HAVE_GETTIMEOFDAY
+int
+evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ struct _timeb tb;
+
+ if(tv == NULL)
+ return -1;
+
+ _ftime(&tb);
+ tv->tv_sec = (long) tb.time;
+ tv->tv_usec = ((int) tb.millitm) * 1000;
+ return 0;
+}
+#endif
diff --git a/include/event2/util.h b/include/event2/util.h
index f697a53c..fbff7355 100644
--- a/include/event2/util.h
+++ b/include/event2/util.h
@@ -179,6 +179,12 @@ int evutil_make_socket_nonblocking(evutil_socket_t sock);
/* big-int related functions */
ev_int64_t evutil_strtoll(const char *s, char **endptr, int base);
+#ifdef _EVENT_HAVE_GETTIMEOFDAY
+#define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))
+#else
+int evutil_gettimeofday(struct timeval *tv, struct timezone *tz);
+#endif
+
#ifdef __cplusplus
}
#endif