r19651@catbus: nickm | 2008-05-08 10:05:35 -0400

Replace gettimeofday() usage with a new evutil_gettimeofday().  This removes all previous need for win32-code/misc.[ch]


svn:r793
This commit is contained in:
Nick Mathewson 2008-05-08 14:08:12 +00:00
parent 52a851389f
commit 987597ff0f
8 changed files with 31 additions and 111 deletions

View File

@ -12,6 +12,7 @@ Changes in 1.4.4-stable:
o Build test directory correctly with CPPFLAGS set.
o Fix build under Visual C++ 2005.
o Expose evhttp_accept_socket() API.
o Merge windows gettimeofday() replacement into a new evutil_gettimeofday() function.
Changes in 1.4.3-stable:
o include Content-Length in reply for HTTP/1.0 requests with keep-alive

View File

@ -43,8 +43,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 \
@ -57,7 +57,7 @@ if BUILD_WIN32
SUBDIRS = . sample
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

View File

@ -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

View File

@ -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

View File

@ -1050,7 +1050,7 @@ 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
@ -1060,7 +1060,7 @@ default_transaction_id_fn(void)
/* down to using gettimeofday. */
/*
struct timeval tv;
gettimeofday(&tv, NULL);
evutil_gettimeofday(&tv, NULL);
trans_id = tv.tv_usec & 0xffff;
*/
abort();

View File

@ -157,7 +157,7 @@ gettime(struct event_base *base, struct timeval *tp)
}
#endif
return (gettimeofday(tp, NULL));
return (evutil_gettimeofday(tp, NULL));
}
struct event_base *
@ -683,7 +683,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);
}

View File

@ -196,3 +196,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

View File

@ -163,6 +163,13 @@ int evutil_make_socket_nonblocking(int 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