@@ -283,6 +283,19 @@ static bool php_open_listen_sock(php_socket *sock, unsigned short port, int back
283283
284284static  bool  php_accept_connect (php_socket  * in_sock , php_socket  * out_sock , struct  sockaddr  * la , socklen_t  * la_len ) /* {{{ */ 
285285{
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 
286299	out_sock -> bsd_socket  =  accept (in_sock -> bsd_socket , la , la_len );
287300
288301	if  (IS_INVALID_SOCKET (out_sock )) {
@@ -292,7 +305,7 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
292305
293306#if  !defined(PHP_WIN32 )
294307	/** 
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,  
296309	 * win32, not having any concept of child process, has no need to address it. 
297310	 */ 
298311	int  mode ;
@@ -310,6 +323,7 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
310323			return  0 ;
311324		}
312325	}
326+ #endif 
313327#endif 
314328
315329	out_sock -> error  =  0 ;
0 commit comments