On tor, 2004-09-16 at 19:35 +0200, Guilhem Lavaux wrote:
> I fear "poll" is not implemented on darwin6. This was the patch about 
> jthreadedRecvFrom. We must implement a backup code.
> 

Here's a patch that uses select() instead of poll() in
jthreadedRecvFrom. WorksForMe^TM, but on the other hand I don't have
access to any darwin6 systems.

cheers/noa

-- 
And the lions ate the christians and the christians burned the witches,
and even I am out of explanations -- Ola Salo
gpg fingerprint: F3C4 AC90 B885 FE15 344B  4D05 220B 7662 A190 6F09
Index: ChangeLog
===================================================================
RCS file: /cvs/kaffe/kaffe/ChangeLog,v
retrieving revision 1.2732
diff -u -r1.2732 ChangeLog
--- ChangeLog	16 Sep 2004 23:19:23 -0000	1.2732
+++ ChangeLog	17 Sep 2004 06:09:02 -0000
@@ -1,3 +1,8 @@
+2004-09-17  Noa Resare  <[EMAIL PROTECTED]>
+
+	* kaffe/kaffevm/systems/unix-pthreads/syscalls.c:
+	(jthreadedRecvfrom) use select() instead of poll()
+
 2004-09-16  Noa Resare  <[EMAIL PROTECTED]>
 
 	* kaffe/kaffevm/kaffe-gc/gc-mem.c (gc_block_alloc):
Index: kaffe/kaffevm/systems/unix-pthreads/syscalls.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/systems/unix-pthreads/syscalls.c,v
retrieving revision 1.20
diff -u -r1.20 syscalls.c
--- kaffe/kaffevm/systems/unix-pthreads/syscalls.c	10 Sep 2004 00:34:24 -0000	1.20
+++ kaffe/kaffevm/systems/unix-pthreads/syscalls.c	17 Sep 2004 06:09:05 -0000
@@ -19,9 +19,21 @@
 #include "jsyscall.h"
 #include "jsignal.h"
 #include "nets.h"
-#if defined(HAVE_SYS_POLL_H)
-#include <sys/poll.h>
+
+#if defined(HAVE_SYS_SELECT_H)
+#include <sys/select.h>
+#else /* HAVE_SYS_SELECT_H */
+#if defined(HAVE_SYS_TIME_H)
+#include <sys/time.h>
+#endif
+#if defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
 #endif
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#endif /* HAVE_SYS_SELECT_H */
+
 #if defined(HAVE_SYS_WAIT_H)
 #include <sys/wait.h>
 #endif
@@ -609,6 +621,31 @@
 }
 
 /*
+ * Blocks until there is data available to read or the timeout expires. 
+ * Signals causes the function to return, so you can't be certain that
+ * there is data to read, or that a timeout occured upon return.
+ *
+ * @param fd the file descriptor to check for available data
+ * @param timeout the number of milliseconds to wait before a timeout
+ */
+static void
+read_timeout(int fd, int timeout)
+{
+	fd_set set;
+	struct timeval tv;
+
+	assert(timeout > 0);
+
+	FD_ZERO(&set);
+	FD_SET (fd, &set);
+	
+	tv.tv_sec = timeout / 1000;
+	tv.tv_usec = timeout % 1000;
+
+	select(fd, &set, NULL, NULL, &tv);
+}
+
+/*
  * Threaded recvfrom 
  */
 static int 
@@ -617,13 +654,10 @@
 {
 	int r;
 	jlong deadline = 0;
-	int fd_flags;
 	int poll_timeout;
 
-	struct pollfd sp = {fd, POLLIN|POLLPRI, 0};
  
-	fd_flags = fcntl(fd, F_GETFL);
-	fcntl(fd, F_SETFL, fd_flags|O_NONBLOCK);
+	jthread_set_blocking(fd, 0);
 	SET_DEADLINE(deadline, timeout)
 	for (;;) {
 		r = recvfrom(fd, buf, len, flags, from, fromlen);
@@ -634,11 +668,11 @@
 		IGNORE_EINTR(r)
 		poll_timeout = deadline - currentTime();
 		if (poll_timeout > 0) {
-			poll(&sp, 1, poll_timeout);
+			read_timeout(fd, poll_timeout);
 		}
 		BREAK_IF_LATE(deadline, timeout)
 	}
-	fcntl(fd, F_SETFL, fd_flags);
+	jthread_set_blocking(fd, 1);
 	SET_RETURN_OUT(r, out, r)
 	return (r);
 }
_______________________________________________
kaffe mailing list
[EMAIL PROTECTED]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to