Skip to content

Commit a48655d

Browse files
committed
erts: Accept sockets non-blocking with accept4
Passing SOCK_NONBLOCK to accept4() makes the SET_NONBLOCKING call on every accepted socket redundant, saving a syscall per accept on platforms that have accept4().
1 parent 6b6e6da commit a48655d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

erts/emulator/nifs/unix/unix_socket_syncio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@
196196
*/
197197

198198
#ifdef HAS_ACCEPT4
199-
// We have to figure out what the flags are...
200199
#define sock_accept(s, addr, len) \
201-
accept4((s), (addr), (len), (SOCK_CLOEXEC))
200+
accept4((s), (addr), (len), (SOCK_CLOEXEC | SOCK_NONBLOCK))
201+
/* The accepted socket is already non-blocking */
202+
#define ESSIO_ACCEPTED_NONBLOCK 1
202203
#else
203204
#define sock_accept(s, addr, len) accept((s), (addr), (len))
204205
#endif
@@ -2863,7 +2864,9 @@ BOOLEAN_T essio_accept_accepted(ErlNifEnv* env,
28632864
&accDescP->ctrlPid,
28642865
&accDescP->ctrlMon) == 0 );
28652866

2867+
#ifndef ESSIO_ACCEPTED_NONBLOCK
28662868
SET_NONBLOCKING(accDescP->sock);
2869+
#endif
28672870

28682871
accDescP->writeState |= ESOCK_STATE_CONNECTED;
28692872

0 commit comments

Comments
 (0)