guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: All thread blocked on (accept socket)


From: Christopher Cramer
Subject: Re: All thread blocked on (accept socket)
Date: Mon, 4 Mar 2002 23:04:57 -0600
User-agent: Mutt/1.2.5i

On Mon, Mar 04, 2002 at 05:52:08PM -0600, Christopher Cramer wrote:
> On Mon, Mar 04, 2002 at 01:26:21PM +0100, Lamy Jean-Baptiste wrote:
> > But it looks like, when the first
> > thread is waiting on a blocking "(accept socket)", all other threads are
> > blocked too and cannot treat their request...
> 
> I think I'll go fix this... just need to add a call to
> scm_internal_select() in scm_accept().

Fixed! Yay. I also added a comment about the fact that connect will
block, but I haven't fixed it yet.

Index: libguile/socket.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/socket.c,v
retrieving revision 1.80.2.1
diff -u -r1.80.2.1 socket.c
--- libguile/socket.c   9 Jul 2001 07:31:05 -0000       1.80.2.1
+++ libguile/socket.c   5 Mar 2002 04:54:04 -0000
@@ -43,11 +43,13 @@
 
 
 #include <errno.h>
+#include <fcntl.h>
 
 #include "libguile/_scm.h"
 #include "libguile/unif.h"
 #include "libguile/feature.h"
 #include "libguile/fports.h"
+#include "libguile/iselect.h"
 #include "libguile/strings.h"
 #include "libguile/vectors.h"
 
@@ -809,6 +811,7 @@
            "The return value is unspecified.")
 #define FUNC_NAME s_scm_connect
 {
+  /* this will block coop threads; should be fixed */
   int fd;
   struct sockaddr *soka;
   int size;
@@ -1019,6 +1022,26 @@
   sock = SCM_COERCE_OUTPORT (sock);
   SCM_VALIDATE_OPFPORT (1, sock);
   fd = SCM_FPORT_FDES (sock);
+
+#ifdef GUILE_ISELECT
+  {
+    int n;
+    SELECT_TYPE readfds;
+    int flags = fcntl (fd, F_GETFL);
+
+    if (flags == -1)
+      scm_syserror ("scm_accept");
+    if (!(flags & O_NONBLOCK))
+      do
+       {
+         FD_ZERO (&readfds);
+         FD_SET (fd, &readfds);
+         n = scm_internal_select (fd + 1, &readfds, NULL, NULL, NULL);
+       }
+      while (n == -1 && errno == EINTR);
+  }
+#endif
+
   newfd = accept (fd, addr, &addr_size);
   if (newfd == -1)
     SCM_SYSERROR;

-- 
Christopher Cramer <address@hidden> <http://www.pyro.net/~crayc/>
Quoi que vous fassiez, écrasez l'infâme, et aimez qui vous aime.
        -- Voltaire



reply via email to

[Prev in Thread] Current Thread [Next in Thread]