[MLton-devel] cvs commit: poll using select

Matthew Fluet fluet@users.sourceforge.net
Fri, 06 Jun 2003 06:40:56 -0700


fluet       03/06/06 06:40:55

  Modified:    runtime/basis/OS/IO poll.c
  Log:
  An implementation of OS.IO.poll using the select system call.  Sources
  are adapted from SML/NJ.  Currently, the select version is commented
  out, but it gives the same result as SML/NJ.

Revision  Changes    Path
1.3       +85 -0     mlton/runtime/basis/OS/IO/poll.c

Index: poll.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/basis/OS/IO/poll.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- poll.c	24 Nov 2002 01:19:45 -0000	1.2
+++ poll.c	6 Jun 2003 13:40:55 -0000	1.3
@@ -16,3 +16,88 @@
 	}
 	return res;
 }
+
+/* Modified from SML/NJ sources by Matthew Fluet 2003-06-06 */
+/* poll.c
+ *
+ * COPYRIGHT (c) 1994 by AT&T Bell Laboratories.
+ *
+ * The run-time code for OS.IO.poll.  Note that this implementation should
+ * satisfy the following two properties:
+ *
+ *   1) the list of return items should be in the same order as the
+ *	corresponding list of arguments.
+ *
+ *   2) return items should contain no more information than was queried for
+ *	(this matters when the same descriptor is covered by multiple items).
+ */
+/*
+#include <stdlib.h>
+#include <sys/poll.h>
+#include <sys/select.h>
+#include "mlton-basis.h"
+#include "mlton-posix.h"
+
+Int OS_IO_poll(Fd *fds, Word *eventss, Int n, Int timeout, Word *reventss) {
+  fd_set	rset, wset, eset;
+  fd_set	*rfds, *wfds, *efds;
+  struct timeval timeoutZ;
+  struct timeval *timeoutZZ;
+  int		maxFD, fd, flag, resFlag;
+  int 		i, res;
+
+  rfds = wfds = efds = NULL;
+  maxFD = 0;
+  for (i = 0; i < n; i++) {
+    fd	= fds[i];
+    flag = eventss[i];
+    if ((flag & POLLIN) != 0) {
+      if (rfds == NULL) {
+	rfds = &rset;
+	FD_ZERO(rfds);
+      }
+      FD_SET (fd, rfds);
+    }
+    if ((flag & POLLOUT) != 0) {
+      if (wfds == NULL) {
+	wfds = &wset;
+	FD_ZERO(wfds);
+      }
+      FD_SET (fd, wfds);
+    }
+    if ((flag & POLLPRI) != 0) {
+      if (efds == NULL) {
+	efds = &eset;
+	FD_ZERO(efds);
+      }
+      FD_SET (fd, efds);
+    }
+    if (fd > maxFD) maxFD = fd;
+  }
+  if (timeout < 0)
+    timeoutZZ = NULL;
+  else {
+    timeoutZZ = &timeoutZ;
+    timeoutZ.tv_sec = timeout / 1000;
+    timeoutZ.tv_usec = (timeout % 1000) * 1000;
+  }
+  res = select (maxFD+1, rfds, wfds, efds, timeoutZZ);
+  if (res < 0)
+    return res;
+  else {
+    for (i = 0; i < n; i++) {
+      fd = fds[i];
+      flag = eventss[i];
+      resFlag = 0;
+      if (((flag & POLLIN) != 0) && FD_ISSET(fd, rfds))
+	resFlag |= POLLIN;
+      if (((flag & POLLOUT) != 0) && FD_ISSET(fd, wfds))
+	resFlag |= POLLOUT;
+      if (((flag & POLLPRI) != 0) && FD_ISSET(fd, efds))
+	resFlag |= POLLPRI;
+      reventss[i] = resFlag;
+    }
+    return res;
+  }
+}
+*/





-------------------------------------------------------
This SF.net email is sponsored by:  Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel