[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Make non-fake tor_poll robust against -1 fds
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv1567/src/common
Modified Files:
fakepoll.c fakepoll.h
Log Message:
Make non-fake tor_poll robust against -1 fds
Index: fakepoll.c
===================================================================
RCS file: /home/or/cvsroot/src/common/fakepoll.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- fakepoll.c 4 May 2004 18:17:28 -0000 1.27
+++ fakepoll.c 5 May 2004 01:01:34 -0000 1.28
@@ -9,8 +9,9 @@
#include "orconfig.h"
#include "fakepoll.h"
-#ifdef USE_FAKE_POLL
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -27,16 +28,27 @@
#include <winsock.h>
#endif
-/* by default, windows handles only 64 fd's */
-#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
-#define FD_SETSIZE MAXCONNECTIONS
-#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)
+{
+ int i;
+ for (i=0;i<nfds;++i) {
+ tor_assert(ufds[i].fd >= 0);
+ }
+ return poll(ufds,nfds,timeout);
+}
+#else
+/* by default, windows handles only 64 fd's */
+#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)
+#define FD_SETSIZE MAXCONNECTIONS
+#endif
+
int
tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout)
{
Index: fakepoll.h
===================================================================
RCS file: /home/or/cvsroot/src/common/fakepoll.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- fakepoll.h 1 May 2004 20:46:27 -0000 1.8
+++ fakepoll.h 5 May 2004 01:01:34 -0000 1.9
@@ -19,15 +19,11 @@
* select. On Mac OS 10.3, this wrapper is kinda flaky, and we should
* use our own.
*/
-#if (defined(HAVE_POLL_H)||defined(HAVE_SYS_POLL_H)) && !defined(_POLL_EMUL_H_)
-#define tor_poll poll
-#else
+#if !(defined(HAVE_POLL_H)||defined(HAVE_SYS_POLL_H))&&!defined(_POLL_EMUL_H_)
#define USE_FAKE_POLL
#endif
-#ifdef USE_FAKE_POLL
-
-#ifndef _POLL_EMUL_H_
+#if defined USE_FAKE_POLL && !defined(_POLL_EMUL_H_)
struct pollfd {
int fd;
short events;
@@ -43,7 +39,6 @@
#endif
int tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout);
-#endif
#endif