emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master f2d0333: Prefer SOCK_NONBLOCK to O_NONBLOCK


From: Paul Eggert
Subject: [Emacs-diffs] master f2d0333: Prefer SOCK_NONBLOCK to O_NONBLOCK
Date: Sun, 22 May 2016 00:05:29 +0000 (UTC)

branch: master
commit f2d03334814cff85013135366a46a85f3124f7f0
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Prefer SOCK_NONBLOCK to O_NONBLOCK
    
    * src/process.c (SOCK_NONBLOCK): Define to 0 if not already defined.
    (connect_network_socket): Create the socket with SOCK_NONBLOCK, to
    avoid an fcntl with O_NONBLOCK if SOCK_NONBLOCK works.  Put the
    SOCK_DGRAM check a bit later, to keep the logic cleaner, as
    the order does not matter here.
---
 src/process.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/process.c b/src/process.c
index 4bb3f0b..fbb517d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -150,6 +150,9 @@ bool inhibit_sentinels;
 #ifndef SOCK_CLOEXEC
 # define SOCK_CLOEXEC 0
 #endif
+#ifndef SOCK_NONBLOCK
+# define SOCK_NONBLOCk 0
+#endif
 
 /* True if ERRNUM represents an error where the system call would
    block if a blocking variant were used.  */
@@ -3141,7 +3144,10 @@ connect_network_socket (Lisp_Object proc, Lisp_Object 
ip_addresses,
       s = socket_to_use;
       if (s < 0)
        {
-         s = socket (family, p->socktype | SOCK_CLOEXEC, p->ai_protocol);
+         int socktype = p->socktype | SOCK_CLOEXEC;
+         if (p->is_non_blocking_client)
+           socktype |= SOCK_NONBLOCK;
+         s = socket (family, socktype, p->ai_protocol);
          if (s < 0)
            {
              xerrno = errno;
@@ -3149,12 +3155,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object 
ip_addresses,
            }
        }
 
-#ifdef DATAGRAM_SOCKETS
-      if (!p->is_server && p->socktype == SOCK_DGRAM)
-       break;
-#endif /* DATAGRAM_SOCKETS */
-
-      if (p->is_non_blocking_client)
+      if (p->is_non_blocking_client && ! (SOCK_NONBLOCK && socket_to_use < 0))
        {
          ret = fcntl (s, F_SETFL, O_NONBLOCK);
          if (ret < 0)
@@ -3166,6 +3167,11 @@ connect_network_socket (Lisp_Object proc, Lisp_Object 
ip_addresses,
            }
        }
 
+#ifdef DATAGRAM_SOCKETS
+      if (!p->is_server && p->socktype == SOCK_DGRAM)
+       break;
+#endif /* DATAGRAM_SOCKETS */
+
       /* Make us close S if quit.  */
       record_unwind_protect_int (close_file_unwind, s);
 



reply via email to

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