Author: gonzalo
Date: 2005-04-06 15:02:14 -0400 (Wed, 06 Apr 2005)
New Revision: 42616
Added:
trunk/mono/mono/utils/mono-poll.c
trunk/mono/mono/utils/mono-poll.h
Modified:
trunk/mono/mono/utils/ChangeLog
trunk/mono/mono/utils/Makefile.am
Log:
2005-04-06 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* mono-poll.[ch]: mono_poll uses poll() when available, otherwise
implement it in terms of select().
* Makefile.am: added new files.
Modified: trunk/mono/mono/utils/ChangeLog
===================================================================
--- trunk/mono/mono/utils/ChangeLog 2005-04-06 17:16:38 UTC (rev 42615)
+++ trunk/mono/mono/utils/ChangeLog 2005-04-06 19:02:14 UTC (rev 42616)
@@ -1,3 +1,9 @@
+2005-04-06 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * mono-poll.[ch]: mono_poll uses poll() when available, otherwise
+ implement it in terms of select().
+ * Makefile.am: added new files.
+
2005-03-29 Sebastien Pouliot <[EMAIL PROTECTED]>
* mono-compiler.h: Added defines to make it easier to compile mono and
Modified: trunk/mono/mono/utils/Makefile.am
===================================================================
--- trunk/mono/mono/utils/Makefile.am 2005-04-06 17:16:38 UTC (rev 42615)
+++ trunk/mono/mono/utils/Makefile.am 2005-04-06 19:02:14 UTC (rev 42616)
@@ -15,7 +15,8 @@
strtod.c \
strenc.h \
strenc.c \
- mono-uri.c
+ mono-uri.c \
+ mono-poll.c
libmonoutilsincludedir = $(includedir)/mono/utils
@@ -24,9 +25,10 @@
mono-codeman.h \
mono-digest.h \
mono-logger.h \
- mono-hash.h \
+ mono-hash.h \
mono-math.h \
- mono-uri.h
+ mono-uri.h \
+ mono-poll.h
EXTRA_DIST = ChangeLog
Added: trunk/mono/mono/utils/mono-poll.c
===================================================================
--- trunk/mono/mono/utils/mono-poll.c 2005-04-06 17:16:38 UTC (rev 42615)
+++ trunk/mono/mono/utils/mono-poll.c 2005-04-06 19:02:14 UTC (rev 42616)
@@ -0,0 +1,98 @@
+#include "mono-poll.h"
+
+#ifdef HAVE_POLL
+int
+mono_poll (mono_pollfd *ufds, unsigned int nfds, int timeout)
+{
+ return poll (ufds, nfds, timeout);
+}
+#else
+
+int
+mono_poll (mono_pollfd *ufds, unsigned int nfds, int timeout)
+{
+ struct timeval tv, *tvptr;
+ int i, fd, events, affected, count;
+ fd_set rfds, wfds, efds;
+ int nexc = 0;
+ int maxfd = 0;
+
+ if (timeout < 0) {
+ tvptr = NULL;
+ } else {
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ tvptr = &tv;
+ }
+
+ FD_ZERO (&rfds);
+ FD_ZERO (&wfds);
+ FD_ZERO (&efds);
+
+ for (i = 0; i < nfds; i++) {
+ ufds [i].revents = 0;
+ fd = ufds [i].fd;
+ if (fd < 0)
+ continue;
+
+#ifdef PLATFORM_WIN32
+ if (nexc >= FD_SETSIZE) {
+ ufds [i].revents = MONO_POLLNVAL;
+ return 1;
+ }
+#else
+ if (fd > FD_SETSIZE) {
+ ufds [i].revents = MONO_POLLNVAL;
+ return 1;
+ }
+#endif
+
+ events = ufds [i].events;
+ if ((events & MONO_POLLIN) != 0)
+ FD_SET (fd, &rfds);
+
+ if ((events & MONO_POLLOUT) != 0)
+ FD_SET (fd, &wfds);
+
+ FD_SET (fd, &efds);
+ nexc++;
+ if (fd > maxfd)
+ maxfd = fd;
+
+ }
+
+ affected = select (maxfd + 1, &rfds, &wfds, &efds, tvptr);
+ if (affected == -1) /* EBADF should be translated to POLLNVAL */
+ return -1;
+
+ count = 0;
+ for (i = 0; i < nfds && affected > 0; i++) {
+ fd = ufds [i].fd;
+ if (fd < 0)
+ continue;
+
+ events = ufds [i].events;
+ if ((events & MONO_POLLIN) != 0 && FD_ISSET (fd, &rfds)) {
+ ufds [i].revents |= MONO_POLLIN;
+ affected--;
+ }
+
+ if ((events & MONO_POLLOUT) != 0 && FD_ISSET (fd, &wfds)) {
+ ufds [i].revents |= MONO_POLLOUT;
+ affected--;
+ }
+
+ if (FD_ISSET (fd, &efds)) {
+ ufds [i].revents |= MONO_POLLERR;
+ affected--;
+ }
+
+ if (ufds [i].revents != 0)
+ count++;
+ }
+
+ return count;
+}
+
+#endif
+
Added: trunk/mono/mono/utils/mono-poll.h
===================================================================
--- trunk/mono/mono/utils/mono-poll.h 2005-04-06 17:16:38 UTC (rev 42615)
+++ trunk/mono/mono/utils/mono-poll.h 2005-04-06 19:02:14 UTC (rev 42616)
@@ -0,0 +1,46 @@
+#ifndef MONO_POLL_H
+#define MONO_POLL_H
+
+#include <config.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef HAVE_POLL
+#include <sys/poll.h>
+
+#define MONO_POLLIN POLLIN
+#define MONO_POLLPRI POLLPRI
+#define MONO_POLLOUT POLLOUT
+#define MONO_POLLERR POLLERR
+#define MONO_POLLHUP POLLHUP
+#define MONO_POLLNVAL POLLNVAL
+
+typedef struct pollfd mono_pollfd;
+
+#else
+
+#ifdef PLATFORM_WIN32
+/* The default in cygwin header files is 64 */
+#define FD_SETSIZE 1024
+#include <windows.h>
+#endif
+#define MONO_POLLIN 1
+#define MONO_POLLPRI 2
+#define MONO_POLLOUT 4
+#define MONO_POLLERR 8
+#define MONO_POLLHUP 0x10
+#define MONO_POLLNVAL 0x20
+
+typedef struct {
+ int fd;
+ short events;
+ short revents;
+} mono_pollfd;
+
+#endif
+
+int mono_poll (mono_pollfd *ufds, unsigned int nfds, int timeout);
+
+#endif /* MONO_POLL_H */
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches