* [PATCH] accept4: add support for SOCK_NONBLOCK when using accept()
@ 2020-07-30 0:06 Aleix Conchillo Flaqué
2020-07-30 8:00 ` Aleix Conchillo Flaqué
0 siblings, 1 reply; 2+ messages in thread
From: Aleix Conchillo Flaqué @ 2020-07-30 0:06 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1.1: Type: text/plain, Size: 185 bytes --]
SOCK_NONBLOCK was not implemented when accept4() is not available (e.g.
macOS).
I'm currently testing all this with the two new web server implementations
provided with Fibers.
Aleix
[-- Attachment #1.2: Type: text/html, Size: 616 bytes --]
[-- Attachment #2: 0001-accept4-add-support-for-SOCK_NONBLOCK-when-using-acc.patch --]
[-- Type: application/octet-stream, Size: 2044 bytes --]
From c2faa3bd8f94373182f31af55789e965cc64dc07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= <aconchillo@gmail.com>
Date: Wed, 29 Jul 2020 16:59:27 -0700
Subject: [PATCH] accept4: add support for SOCK_NONBLOCK when using accept()
* lib/accept4.c (accept4): if accept4 is not available we default to
accept(). We add support for SOCK_NONBLOCK in this case.
---
lib/accept4.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/lib/accept4.c b/lib/accept4.c
index 9fab9c645..4d8c7995e 100644
--- a/lib/accept4.c
+++ b/lib/accept4.c
@@ -25,7 +25,19 @@
#include "msvc-nothrow.h"
#ifndef SOCK_CLOEXEC
-# define SOCK_CLOEXEC 0
+# if defined __MACH__ && defined __APPLE__
+# define SOCK_CLOEXEC O_CLOEXEC
+# else
+# define SOCK_CLOEXEC 0
+# endif
+#endif
+
+#ifndef SOCK_NONBLOCK
+# if defined __MACH__ && defined __APPLE__
+# define SOCK_NONBLOCK O_NONBLOCK
+# else
+# define SOCK_NONBLOCK 0
+# endif
#endif
int
@@ -54,7 +66,7 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
#endif
/* Check the supported flags. */
- if ((flags & ~(SOCK_CLOEXEC | O_TEXT | O_BINARY)) != 0)
+ if ((flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC | O_TEXT | O_BINARY)) != 0)
{
errno = EINVAL;
return -1;
@@ -117,6 +129,27 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
# endif
#endif
+#if SOCK_NONBLOCK
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# warning SOCK_NONBLOCK not currently supported on WIN32
+# else
+/* Unix API. */
+ if (flags & SOCK_NONBLOCK)
+ {
+ int fcntl_flags;
+
+ if ((fcntl_flags = fcntl (fd, F_GETFL, 0)) < 0
+ || fcntl (fd, F_SETFL, fcntl_flags | O_NONBLOCK) == -1)
+ {
+ int saved_errno = errno;
+ close (fd);
+ errno = saved_errno;
+ return -1;
+ }
+ }
+# endif
+#endif
+
#if O_BINARY
if (flags & O_BINARY)
set_binary_mode (fd, O_BINARY);
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] accept4: add support for SOCK_NONBLOCK when using accept()
2020-07-30 0:06 [PATCH] accept4: add support for SOCK_NONBLOCK when using accept() Aleix Conchillo Flaqué
@ 2020-07-30 8:00 ` Aleix Conchillo Flaqué
0 siblings, 0 replies; 2+ messages in thread
From: Aleix Conchillo Flaqué @ 2020-07-30 8:00 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 428 bytes --]
Fibers work on macOS is being done here.
https://github.com/wingo/fibers/pull/42
This is now working with both web servers.
On Wed, Jul 29, 2020 at 5:06 PM Aleix Conchillo Flaqué <aconchillo@gmail.com>
wrote:
> SOCK_NONBLOCK was not implemented when accept4() is not available (e.g.
> macOS).
>
> I'm currently testing all this with the two new web server implementations
> provided with Fibers.
>
> Aleix
>
[-- Attachment #2: Type: text/html, Size: 1453 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-30 8:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30 0:06 [PATCH] accept4: add support for SOCK_NONBLOCK when using accept() Aleix Conchillo Flaqué
2020-07-30 8:00 ` Aleix Conchillo Flaqué
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).