diff options
| author | Paul Eggert | 2016-05-21 17:04:44 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-05-21 17:05:25 -0700 |
| commit | f2d03334814cff85013135366a46a85f3124f7f0 (patch) | |
| tree | d71374198e8e9f431b9025783a2de326d13be8c6 /src | |
| parent | e5015c5d9632a0bf685c093249ae4a7d3e825b13 (diff) | |
| download | emacs-f2d03334814cff85013135366a46a85f3124f7f0.tar.gz emacs-f2d03334814cff85013135366a46a85f3124f7f0.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/process.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/process.c b/src/process.c index 4bb3f0b9d6d..fbb517d91a7 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -150,6 +150,9 @@ bool inhibit_sentinels; | |||
| 150 | #ifndef SOCK_CLOEXEC | 150 | #ifndef SOCK_CLOEXEC |
| 151 | # define SOCK_CLOEXEC 0 | 151 | # define SOCK_CLOEXEC 0 |
| 152 | #endif | 152 | #endif |
| 153 | #ifndef SOCK_NONBLOCK | ||
| 154 | # define SOCK_NONBLOCk 0 | ||
| 155 | #endif | ||
| 153 | 156 | ||
| 154 | /* True if ERRNUM represents an error where the system call would | 157 | /* True if ERRNUM represents an error where the system call would |
| 155 | block if a blocking variant were used. */ | 158 | block if a blocking variant were used. */ |
| @@ -3141,7 +3144,10 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses, | |||
| 3141 | s = socket_to_use; | 3144 | s = socket_to_use; |
| 3142 | if (s < 0) | 3145 | if (s < 0) |
| 3143 | { | 3146 | { |
| 3144 | s = socket (family, p->socktype | SOCK_CLOEXEC, p->ai_protocol); | 3147 | int socktype = p->socktype | SOCK_CLOEXEC; |
| 3148 | if (p->is_non_blocking_client) | ||
| 3149 | socktype |= SOCK_NONBLOCK; | ||
| 3150 | s = socket (family, socktype, p->ai_protocol); | ||
| 3145 | if (s < 0) | 3151 | if (s < 0) |
| 3146 | { | 3152 | { |
| 3147 | xerrno = errno; | 3153 | xerrno = errno; |
| @@ -3149,12 +3155,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses, | |||
| 3149 | } | 3155 | } |
| 3150 | } | 3156 | } |
| 3151 | 3157 | ||
| 3152 | #ifdef DATAGRAM_SOCKETS | 3158 | if (p->is_non_blocking_client && ! (SOCK_NONBLOCK && socket_to_use < 0)) |
| 3153 | if (!p->is_server && p->socktype == SOCK_DGRAM) | ||
| 3154 | break; | ||
| 3155 | #endif /* DATAGRAM_SOCKETS */ | ||
| 3156 | |||
| 3157 | if (p->is_non_blocking_client) | ||
| 3158 | { | 3159 | { |
| 3159 | ret = fcntl (s, F_SETFL, O_NONBLOCK); | 3160 | ret = fcntl (s, F_SETFL, O_NONBLOCK); |
| 3160 | if (ret < 0) | 3161 | if (ret < 0) |
| @@ -3166,6 +3167,11 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses, | |||
| 3166 | } | 3167 | } |
| 3167 | } | 3168 | } |
| 3168 | 3169 | ||
| 3170 | #ifdef DATAGRAM_SOCKETS | ||
| 3171 | if (!p->is_server && p->socktype == SOCK_DGRAM) | ||
| 3172 | break; | ||
| 3173 | #endif /* DATAGRAM_SOCKETS */ | ||
| 3174 | |||
| 3169 | /* Make us close S if quit. */ | 3175 | /* Make us close S if quit. */ |
| 3170 | record_unwind_protect_int (close_file_unwind, s); | 3176 | record_unwind_protect_int (close_file_unwind, s); |
| 3171 | 3177 | ||