Replace gettimeofday() usage with a new evutil_gettimeofday(). This removes all previous need for win32-code/misc.[ch]
svn:r792
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.
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 \
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
+++ /dev/null
-#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
+++ /dev/null
-#ifndef MISC_H
-#define MISC_H
-
-struct timezone;
-struct timeval;
-
-#ifndef HAVE_GETTIMEOFDAY
-int gettimeofday(struct timeval *,struct timezone *);
-#endif
-
-#endif
#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;
}
#endif
- return (gettimeofday(tp, NULL));
+ return (evutil_gettimeofday(tp, NULL));
}
struct event_base *
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);
}
#endif
#include <errno.h>
+#ifndef _EVENT_HAVE_GETTIMEOFDAY
+#include <sys/timeb.h>
+#include <time.h>
+#endif
+
#include "event2/util.h"
#include "log.h"
#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
/* 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