* should accept be protected with fport_wait_for_input?
@ 2007-12-03 19:41 dskr
2007-12-04 17:32 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: dskr @ 2007-12-03 19:41 UTC (permalink / raw)
To: guile-user
Hi,
the fport fill input code provides a way to avoid some threaded
deadlocks with fport_wait_for_input. I appreciate this tremendously!
Should this protection be extended to 'accept' in the socket code to
prevent the entire runtime from blocking if a thread blocks on accept?
Cheers,
Dan Ridge
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: should accept be protected with fport_wait_for_input?
@ 2007-12-04 6:55 Marco Maggi
0 siblings, 0 replies; 3+ messages in thread
From: Marco Maggi @ 2007-12-04 6:55 UTC (permalink / raw)
To: guile-user
Ciao,
"dskr" wrote:
>Should this protection be extended to 'accept' in the socket
>code to prevent the entire runtime from blocking if a thread
>blocks on accept?
I am not an expert in networking, but it seems to me that to
avoid blocking you need to make the server socket non-blocking.
I dunno what is you platform, but if you are using the
GNU C Library you can read the "accept" info node:
The `accept' function waits if there are no connections
pending,
unless the socket SOCKET has nonblocking mode set.
(You can use
`select' to wait for a pending connection, with a
nonblocking
socket.) *Note File Status Flags::, for information about
nonblocking mode.
HTH
--
Marco Maggi
"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: should accept be protected with fport_wait_for_input?
2007-12-03 19:41 should accept be protected with fport_wait_for_input? dskr
@ 2007-12-04 17:32 ` Ludovic Courtès
0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2007-12-04 17:32 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 479 bytes --]
Hi,
dskr <dskr@mac.com> writes:
> the fport fill input code provides a way to avoid some threaded
> deadlocks with fport_wait_for_input. I appreciate this tremendously!
>
> Should this protection be extended to 'accept' in the socket code to
> prevent the entire runtime from blocking if a thread blocks on accept?
You're right, we should leave "guile mode" before blocking in
`accept(2)'. I committed the attached patch, let me know if it works
for you.
Thanks!
Ludovic.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: The patch --]
[-- Type: text/x-diff, Size: 1051 bytes --]
--- orig/libguile/socket.c
+++ mod/libguile/socket.c
@@ -36,6 +36,8 @@
#include "libguile/validate.h"
#include "libguile/socket.h"
+#include "libguile/iselect.h"
+
#ifdef __MINGW32__
#include "win32-socket.h"
#endif
@@ -1321,16 +1323,30 @@
"connection and will continue to accept new requests.")
#define FUNC_NAME s_scm_accept
{
- int fd;
+ int fd, selected;
int newfd;
SCM address;
SCM newsock;
+ SELECT_TYPE readfds, exceptfds;
socklen_t addr_size = MAX_ADDR_SIZE;
scm_t_max_sockaddr addr;
sock = SCM_COERCE_OUTPORT (sock);
SCM_VALIDATE_OPFPORT (1, sock);
fd = SCM_FPORT_FDES (sock);
+
+ FD_ZERO (&readfds);
+ FD_ZERO (&exceptfds);
+ FD_SET (fd, &readfds);
+ FD_SET (fd, &exceptfds);
+
+ /* Block until something happens on FD, leaving guile mode while
+ waiting. */
+ selected = scm_std_select (fd + 1, &readfds, NULL, &exceptfds,
+ NULL);
+ if (selected < 0)
+ SCM_SYSERROR;
+
newfd = accept (fd, (struct sockaddr *) &addr, &addr_size);
if (newfd == -1)
SCM_SYSERROR;
[-- Attachment #3: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-12-04 17:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-03 19:41 should accept be protected with fport_wait_for_input? dskr
2007-12-04 17:32 ` Ludovic Courtès
-- strict thread matches above, loose matches on Subject: below --
2007-12-04 6:55 Marco Maggi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).