]> granicus.if.org Git - libevent/commitdiff
r19649@catbus: nickm | 2008-05-08 10:00:14 -0400
authorNick Mathewson <nickm@torproject.org>
Thu, 8 May 2008 14:06:33 +0000 (14:06 +0000)
committerNick Mathewson <nickm@torproject.org>
Thu, 8 May 2008 14:06:33 +0000 (14:06 +0000)
 Replace gettimeofday() usage with a new evutil_gettimeofday().  This removes all previous need for win32-code/misc.[ch]

svn:r792

ChangeLog
Makefile.am
WIN32-Code/misc.c [deleted file]
WIN32-Code/misc.h [deleted file]
evdns.c
event.c
evutil.c
include/event2/util.h

index cfc8e45f7c4cfdd80c952fda0798682d54cf697a..fb2c68a2310bc53ec062a54393d6ecf33805b7d3 100644 (file)
--- 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.
index b55468cd5b06e01bf7bee1bde9606774d80e6b9f..c3144567d0e0770945065b81b0cc67167bdcff16 100644 (file)
@@ -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 (file)
index 371e192..0000000
+++ /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 (file)
index aced574..0000000
+++ /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 f0e9b969c9d660daf268d50334bdaac86c0b17f6..c495bd34d885715404269536e3e5d14b4cafe24d 100644 (file)
--- 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 2f5ffa930eb97575c2b29d567eaf6f60bfb3662c..3dab7773dada6c9441b5f9e247b174a193f9e798 100644 (file)
--- 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);
        }
 
index 7407a70710ac6617acff184e54e3b7959500471f..d6176cf6bda20ad6b4aa044f8a2f875e0ce4ed80 100644 (file)
--- a/evutil.c
+++ b/evutil.c
 #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
index f697a53cd63e179e3f61607736f90a83e6132ad9..fbff73550f538c9447c922ac9f4954c1cb5c2776 100644 (file)
@@ -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