@@ -283,6 +283,19 @@ static bool php_open_listen_sock(php_socket *sock, unsigned short port, int back
283
283
284
284
static bool php_accept_connect (php_socket * in_sock , php_socket * out_sock , struct sockaddr * la , socklen_t * la_len ) /* {{{ */
285
285
{
286
+ #if defined(HAVE_ACCEPT4 )
287
+ int flags = SOCK_CLOEXEC ;
288
+ if (!in_sock -> blocking ) {
289
+ flags |= SOCK_NONBLOCK ;
290
+ }
291
+
292
+ out_sock -> bsd_socket = accept4 (in_sock -> bsd_socket , la , la_len , flags );
293
+
294
+ if (IS_INVALID_SOCKET (out_sock )) {
295
+ PHP_SOCKET_ERROR (out_sock , "unable to accept incoming connection" , errno );
296
+ return 0 ;
297
+ }
298
+ #else
286
299
out_sock -> bsd_socket = accept (in_sock -> bsd_socket , la , la_len );
287
300
288
301
if (IS_INVALID_SOCKET (out_sock )) {
@@ -292,7 +305,7 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
292
305
293
306
#if !defined(PHP_WIN32 )
294
307
/**
295
- * accept4 could had been used but not all platforms support it (e.g. Haiku, solaris < 11.4, ...)
308
+ * for fewer and fewer platforms not supporting accept4 syscall we use fcntl instead,
296
309
* win32, not having any concept of child process, has no need to address it.
297
310
*/
298
311
int mode ;
@@ -310,6 +323,7 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
310
323
return 0 ;
311
324
}
312
325
}
326
+ #endif
313
327
#endif
314
328
315
329
out_sock -> error = 0 ;
0 commit comments