diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-01-12 06:42:32 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-01-12 06:42:32 +0000 |
commit | 324b192f68bfe697009831a5bad3acdd7bd2cec5 (patch) | |
tree | 13f8d3bd453244fcad1f519667bb4483156113bf /src/common/fakepoll.c | |
parent | 9b578f2fe2665a1b1a75f6fb5a85f8a77ee31545 (diff) | |
download | tor-324b192f68bfe697009831a5bad3acdd7bd2cec5.tar tor-324b192f68bfe697009831a5bad3acdd7bd2cec5.tar.gz |
Make Tor use Niels Provos's libevent instead of it's current
poll-but-sometimes-select mess. This will let us use faster async cores
(like epoll, kpoll, and /dev/poll), and hopefully work better on Windows
too.
There are some fairly nasty changes to main.c here; this will almost
certainly break something. But hey, that's what alphas are for.
svn:r3341
Diffstat (limited to 'src/common/fakepoll.c')
-rw-r--r-- | src/common/fakepoll.c | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/src/common/fakepoll.c b/src/common/fakepoll.c deleted file mode 100644 index 19f5c1de3..000000000 --- a/src/common/fakepoll.c +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright 2002,2003 Nick Mathewson, Roger Dingledine */ -/* See LICENSE for licensing information */ -/* $Id$ */ -const char fakepoll_c_id[] = "$Id$"; - -/** - * \file fakepoll.c - * - * \brief On systems where poll() doesn't exist, fake it with select(). - **/ - -#include "orconfig.h" -#include "fakepoll.h" - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#include <assert.h> -#include <stdlib.h> -#include "util.h" -#include "log.h" - -#ifndef USE_FAKE_POLL -int -tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout) -{ - unsigned int i; - for (i=0;i<nfds;++i) { - tor_assert(ufds[i].fd >= 0); - } - return poll(ufds,nfds,timeout); -} -#else -int -tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout) -{ - unsigned int idx; - int maxfd, fd; - int r; -#ifdef MS_WINDOWS - int any_fds_set = 0; -#endif - fd_set readfds, writefds, exceptfds; -#ifdef USING_FAKE_TIMEVAL -#undef timeval -#undef tv_sec -#undef tv_usec -#endif - struct timeval _timeout; - _timeout.tv_sec = timeout/1000; - _timeout.tv_usec = (timeout%1000)*1000; - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&exceptfds); - - maxfd = -1; - for (idx = 0; idx < nfds; ++idx) { - ufds[idx].revents = 0; - fd = ufds[idx].fd; - tor_assert(SOCKET_IS_POLLABLE(fd)); - if (fd > maxfd) { - maxfd = fd; -#ifdef MS_WINDOWS - any_fds_set = 1; -#endif - } - if (ufds[idx].events & POLLIN) - FD_SET(fd, &readfds); - if (ufds[idx].events & POLLOUT) - FD_SET(fd, &writefds); - FD_SET(fd, &exceptfds); - } -#ifdef MS_WINDOWS - if (!any_fds_set) { - Sleep(timeout); - return 0; - } -#endif - r = select(maxfd+1, &readfds, &writefds, &exceptfds, - timeout == -1 ? NULL : &_timeout); - if (r <= 0) - return r; - r = 0; - for (idx = 0; idx < nfds; ++idx) { - fd = ufds[idx].fd; - if (FD_ISSET(fd, &readfds)) - ufds[idx].revents |= POLLIN; - if (FD_ISSET(fd, &writefds)) - ufds[idx].revents |= POLLOUT; - if (FD_ISSET(fd, &exceptfds)) - ufds[idx].revents |= POLLERR; - if (ufds[idx].revents) - ++r; - } - return r; -} -#endif - |