unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: [PATCH] accept4: add support for SOCK_NONBLOCK when using accept()
Date: Wed, 29 Jul 2020 17:06:26 -0700	[thread overview]
Message-ID: <CA+XASoVd05HcpU35R60e0aWTG=r+AyWcVShFJKo5HFwcOB-Cdg@mail.gmail.com> (raw)


[-- 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


             reply	other threads:[~2020-07-30  0:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30  0:06 Aleix Conchillo Flaqué [this message]
2020-07-30  8:00 ` [PATCH] accept4: add support for SOCK_NONBLOCK when using accept() Aleix Conchillo Flaqué

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+XASoVd05HcpU35R60e0aWTG=r+AyWcVShFJKo5HFwcOB-Cdg@mail.gmail.com' \
    --to=aconchillo@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).