diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2014-10-08 20:14:20 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2014-10-08 20:14:20 +0000 |
commit | 3a0bde45db1184b2deb9643a522da1bc33cab699 (patch) | |
tree | 30bc4a904d8011185eefe73d5aaa4d3854ae7acd /lib | |
parent | 4fca234da86241cf7a7617fceabf992548ad5f3d (diff) |
iRemove the #ifdef WIN32 implementation from libevent.
OK nicm@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libevent/buffer.c | 20 | ||||
-rw-r--r-- | lib/libevent/evbuffer.c | 14 | ||||
-rw-r--r-- | lib/libevent/event.c | 15 | ||||
-rw-r--r-- | lib/libevent/event.h | 6 | ||||
-rw-r--r-- | lib/libevent/event_tagging.c | 11 | ||||
-rw-r--r-- | lib/libevent/evutil.c | 144 | ||||
-rw-r--r-- | lib/libevent/log.c | 7 | ||||
-rw-r--r-- | lib/libevent/signal.c | 18 |
8 files changed, 16 insertions, 219 deletions
diff --git a/lib/libevent/buffer.c b/lib/libevent/buffer.c index 71e9fb54584..783fd93a0a2 100644 --- a/lib/libevent/buffer.c +++ b/lib/libevent/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.19 2010/07/17 17:16:47 chl Exp $ */ +/* $OpenBSD: buffer.c,v 1.20 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright (c) 2002, 2003 Niels Provos <provos@citi.umich.edu> @@ -31,11 +31,6 @@ #include "config.h" #endif -#ifdef WIN32 -#include <winsock2.h> -#include <windows.h> -#endif - #ifdef HAVE_VASPRINTF /* If we have vasprintf, we need to define this before we include stdio.h. */ #define _GNU_SOURCE @@ -442,12 +437,7 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch) int n = EVBUFFER_MAX_READ; #if defined(FIONREAD) -#ifdef WIN32 - long lng = n; - if (ioctlsocket(fd, FIONREAD, &lng) == -1 || (n=lng) <= 0) { -#else if (ioctl(fd, FIONREAD, &n) == -1 || n <= 0) { -#endif n = EVBUFFER_MAX_READ; } else if (n > EVBUFFER_MAX_READ && n > howmuch) { /* @@ -473,11 +463,7 @@ evbuffer_read(struct evbuffer *buf, int fd, int howmuch) /* We can append new data at this point */ p = buf->buffer + buf->off; -#ifndef WIN32 n = read(fd, p, howmuch); -#else - n = recv(fd, p, howmuch, 0); -#endif if (n == -1) return (-1); if (n == 0) @@ -497,11 +483,7 @@ evbuffer_write(struct evbuffer *buffer, int fd) { int n; -#ifndef WIN32 n = write(fd, buffer->buffer, buffer->off); -#else - n = send(fd, buffer->buffer, buffer->off, 0); -#endif if (n == -1) return (-1); if (n == 0) diff --git a/lib/libevent/evbuffer.c b/lib/libevent/evbuffer.c index 1c0f46e0a2c..13dacfe22be 100644 --- a/lib/libevent/evbuffer.c +++ b/lib/libevent/evbuffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evbuffer.c,v 1.12 2010/04/21 20:02:40 nicm Exp $ */ +/* $OpenBSD: evbuffer.c,v 1.13 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright (c) 2002-2004 Niels Provos <provos@citi.umich.edu> @@ -45,10 +45,6 @@ #include <stdarg.h> #endif -#ifdef WIN32 -#include <winsock2.h> -#endif - #include "evutil.h" #include "event.h" @@ -177,20 +173,12 @@ bufferevent_writecb(int fd, short event, void *arg) if (EVBUFFER_LENGTH(bufev->output)) { res = evbuffer_write(bufev->output, fd); if (res == -1) { -#ifndef WIN32 -/*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not - *set errno. thus this error checking is not portable*/ if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS) goto reschedule; /* error case */ what |= EVBUFFER_ERROR; - -#else - goto reschedule; -#endif - } else if (res == 0) { /* eof case */ what |= EVBUFFER_EOF; diff --git a/lib/libevent/event.c b/lib/libevent/event.c index 99dfde61a08..c4f43b647af 100644 --- a/lib/libevent/event.c +++ b/lib/libevent/event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: event.c,v 1.29 2014/09/01 13:26:29 bluhm Exp $ */ +/* $OpenBSD: event.c,v 1.30 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> @@ -30,11 +30,6 @@ #include "config.h" #endif -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#endif #include <sys/types.h> #include <sys/socket.h> #ifdef HAVE_SYS_TIME_H @@ -45,9 +40,7 @@ #include <sys/queue.h> #include <stdio.h> #include <stdlib.h> -#ifndef WIN32 #include <unistd.h> -#endif #include <errno.h> #include <signal.h> #include <string.h> @@ -79,9 +72,6 @@ extern const struct eventop kqops; #ifdef HAVE_DEVPOLL extern const struct eventop devpollops; #endif -#ifdef WIN32 -extern const struct eventop win32ops; -#endif /* In order of preference */ static const struct eventop *eventops[] = { @@ -103,9 +93,6 @@ static const struct eventop *eventops[] = { #ifdef HAVE_SELECT &selectops, #endif -#ifdef WIN32 - &win32ops, -#endif NULL }; diff --git a/lib/libevent/event.h b/lib/libevent/event.h index 4594bd7884d..1a9fb52d147 100644 --- a/lib/libevent/event.h +++ b/lib/libevent/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.26 2014/04/03 11:27:02 eric Exp $ */ +/* $OpenBSD: event.h,v 1.27 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> @@ -633,11 +633,7 @@ int event_pending(struct event *ev, short event, struct timeval *tv); @return 1 if the structure has been initialized, or 0 if it has not been initialized */ -#ifdef WIN32 -#define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT && (ev)->ev_fd != (int)INVALID_HANDLE_VALUE) -#else #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) -#endif /** diff --git a/lib/libevent/event_tagging.c b/lib/libevent/event_tagging.c index 90b18824ab3..1e069ee8cd2 100644 --- a/lib/libevent/event_tagging.c +++ b/lib/libevent/event_tagging.c @@ -1,4 +1,4 @@ -/* $OpenBSD: event_tagging.c,v 1.4 2013/04/17 15:33:02 deraadt Exp $ */ +/* $OpenBSD: event_tagging.c,v 1.5 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright (c) 2003, 2004 Niels Provos <provos@citi.umich.edu> @@ -38,14 +38,7 @@ #include <sys/param.h> #endif -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include <winsock2.h> -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#else #include <sys/ioctl.h> -#endif #include <sys/queue.h> #ifdef HAVE_SYS_TIME_H @@ -56,9 +49,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifndef WIN32 #include <syslog.h> -#endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif diff --git a/lib/libevent/evutil.c b/lib/libevent/evutil.c index c33d5b6ac45..fa14468d8c4 100644 --- a/lib/libevent/evutil.c +++ b/lib/libevent/evutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evutil.c,v 1.3 2010/07/12 18:03:38 nicm Exp $ */ +/* $OpenBSD: evutil.c,v 1.4 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright (c) 2007 Niels Provos <provos@citi.umich.edu> @@ -30,13 +30,6 @@ #include "config.h" #endif -#ifdef WIN32 -#include <winsock2.h> -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#endif - #include <sys/types.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> @@ -51,9 +44,6 @@ #include <stdlib.h> #endif #include <errno.h> -#if defined WIN32 && !defined(HAVE_GETTIMEOFDAY_H) -#include <sys/timeb.h> -#endif #include <stdio.h> #include <signal.h> @@ -66,122 +56,22 @@ int evutil_socketpair(int family, int type, int protocol, int fd[2]) { -#ifndef WIN32 return socketpair(family, type, protocol, fd); -#else - /* This code is originally from Tor. Used with permission. */ - - /* This socketpair does not work when localhost is down. So - * it's really not the same thing at all. But it's close enough - * for now, and really, when localhost is down sometimes, we - * have other problems too. - */ - int listener = -1; - int connector = -1; - int acceptor = -1; - struct sockaddr_in listen_addr; - struct sockaddr_in connect_addr; - int size; - int saved_errno = -1; - - if (protocol -#ifdef AF_UNIX - || family != AF_UNIX -#endif - ) { - EVUTIL_SET_SOCKET_ERROR(WSAEAFNOSUPPORT); - return -1; - } - if (!fd) { - EVUTIL_SET_SOCKET_ERROR(WSAEINVAL); - return -1; - } - - listener = socket(AF_INET, type, 0); - if (listener < 0) - return -1; - memset(&listen_addr, 0, sizeof(listen_addr)); - listen_addr.sin_family = AF_INET; - listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - listen_addr.sin_port = 0; /* kernel chooses port. */ - if (bind(listener, (struct sockaddr *) &listen_addr, sizeof (listen_addr)) - == -1) - goto tidy_up_and_fail; - if (listen(listener, 1) == -1) - goto tidy_up_and_fail; - - connector = socket(AF_INET, type, 0); - if (connector < 0) - goto tidy_up_and_fail; - /* We want to find out the port number to connect to. */ - size = sizeof(connect_addr); - if (getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1) - goto tidy_up_and_fail; - if (size != sizeof (connect_addr)) - goto abort_tidy_up_and_fail; - if (connect(connector, (struct sockaddr *) &connect_addr, - sizeof(connect_addr)) == -1) - goto tidy_up_and_fail; - - size = sizeof(listen_addr); - acceptor = accept(listener, (struct sockaddr *) &listen_addr, &size); - if (acceptor < 0) - goto tidy_up_and_fail; - if (size != sizeof(listen_addr)) - goto abort_tidy_up_and_fail; - EVUTIL_CLOSESOCKET(listener); - /* Now check we are talking to ourself by matching port and host on the - two sockets. */ - if (getsockname(connector, (struct sockaddr *) &connect_addr, &size) == -1) - goto tidy_up_and_fail; - if (size != sizeof (connect_addr) - || listen_addr.sin_family != connect_addr.sin_family - || listen_addr.sin_addr.s_addr != connect_addr.sin_addr.s_addr - || listen_addr.sin_port != connect_addr.sin_port) - goto abort_tidy_up_and_fail; - fd[0] = connector; - fd[1] = acceptor; - - return 0; - - abort_tidy_up_and_fail: - saved_errno = WSAECONNABORTED; - tidy_up_and_fail: - if (saved_errno < 0) - saved_errno = WSAGetLastError(); - if (listener != -1) - EVUTIL_CLOSESOCKET(listener); - if (connector != -1) - EVUTIL_CLOSESOCKET(connector); - if (acceptor != -1) - EVUTIL_CLOSESOCKET(acceptor); - - EVUTIL_SET_SOCKET_ERROR(saved_errno); - return -1; -#endif } int evutil_make_socket_nonblocking(int fd) { -#ifdef WIN32 - { - unsigned long nonblocking = 1; - ioctlsocket(fd, FIONBIO, (unsigned long*) &nonblocking); + int flags; + + if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) { + event_warn("fcntl(%d, F_GETFL)", fd); + return -1; } -#else - { - int flags; - if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) { - event_warn("fcntl(%d, F_GETFL)", fd); - return -1; - } - if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { - event_warn("fcntl(%d, F_SETFL)", fd); - return -1; - } + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { + event_warn("fcntl(%d, F_SETFL)", fd); + return -1; } -#endif return 0; } @@ -192,22 +82,6 @@ evutil_strtoll(const char *s, char **endptr, int base) return (ev_int64_t)strtoll(s, endptr, base); #elif SIZEOF_LONG == 8 return (ev_int64_t)strtol(s, endptr, base); -#elif defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1300 - /* XXXX on old versions of MS APIs, we only support base - * 10. */ - ev_int64_t r; - if (base != 10) - return 0; - r = (ev_int64_t) _atoi64(s); - while (isspace(*s)) - ++s; - while (isdigit(*s)) - ++s; - if (endptr) - *endptr = (char*) s; - return r; -#elif defined(WIN32) - return (ev_int64_t) _strtoi64(s, endptr, base); #else #error "I don't know how to parse 64-bit integers." #endif diff --git a/lib/libevent/log.c b/lib/libevent/log.c index 07b65e85ba6..673792bc80a 100644 --- a/lib/libevent/log.c +++ b/lib/libevent/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.6 2010/04/21 20:02:40 nicm Exp $ */ +/* $OpenBSD: log.c,v 1.7 2014/10/08 20:14:19 bluhm Exp $ */ /* * log.c @@ -41,11 +41,6 @@ #include "config.h" #endif -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#endif #include <sys/types.h> #ifdef HAVE_SYS_TIME_H #include <sys/time.h> diff --git a/lib/libevent/signal.c b/lib/libevent/signal.c index 156a5250c55..a1119e9961b 100644 --- a/lib/libevent/signal.c +++ b/lib/libevent/signal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: signal.c,v 1.18 2014/10/08 05:41:42 deraadt Exp $ */ +/* $OpenBSD: signal.c,v 1.19 2014/10/08 20:14:19 bluhm Exp $ */ /* * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu> @@ -30,12 +30,6 @@ #include "config.h" #endif -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include <winsock2.h> -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#endif #include <sys/types.h> #ifdef HAVE_SYS_TIME_H #include <sys/time.h> @@ -72,11 +66,7 @@ static void evsignal_cb(int fd, short what, void *arg) { static char signals[1]; -#ifdef WIN32 - SSIZE_T n; -#else ssize_t n; -#endif n = recv(fd, signals, sizeof(signals), 0); if (n == -1) @@ -104,13 +94,7 @@ evsignal_init(struct event_base *base) */ if (evutil_socketpair( AF_UNIX, SOCK_STREAM, 0, base->sig.ev_signal_pair) == -1) { -#ifdef WIN32 - /* Make this nonfatal on win32, where sometimes people - have localhost firewalled. */ - event_warn("%s: socketpair", __func__); -#else event_err(1, "%s: socketpair", __func__); -#endif return -1; } |