mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/sockets: using accept4 wheneever possible for php_accept_connect helper (#19268)
Haiku now supports it as well now, so we can simplify the workflow a bit for those platforms.
This commit is contained in:
parent
191290e194
commit
068aaed196
2 changed files with 16 additions and 2 deletions
|
@ -4,7 +4,7 @@ PHP_ARG_ENABLE([sockets],
|
|||
[Enable sockets support])])
|
||||
|
||||
if test "$PHP_SOCKETS" != "no"; then
|
||||
AC_CHECK_FUNCS([hstrerror if_nametoindex if_indextoname sockatmark])
|
||||
AC_CHECK_FUNCS([hstrerror if_nametoindex if_indextoname sockatmark accept4])
|
||||
AC_CHECK_HEADERS([sys/sockio.h linux/filter.h linux/if_packet.h linux/if_ether.h linux/udp.h])
|
||||
AC_DEFINE([HAVE_SOCKETS], [1],
|
||||
[Define to 1 if the PHP extension 'sockets' is available.])
|
||||
|
|
|
@ -283,6 +283,19 @@ static bool php_open_listen_sock(php_socket *sock, unsigned short port, int back
|
|||
|
||||
static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct sockaddr *la, socklen_t *la_len) /* {{{ */
|
||||
{
|
||||
#if defined(HAVE_ACCEPT4)
|
||||
int flags = SOCK_CLOEXEC;
|
||||
if (!in_sock->blocking) {
|
||||
flags |= SOCK_NONBLOCK;
|
||||
}
|
||||
|
||||
out_sock->bsd_socket = accept4(in_sock->bsd_socket, la, la_len, flags);
|
||||
|
||||
if (IS_INVALID_SOCKET(out_sock)) {
|
||||
PHP_SOCKET_ERROR(out_sock, "unable to accept incoming connection", errno);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
out_sock->bsd_socket = accept(in_sock->bsd_socket, la, la_len);
|
||||
|
||||
if (IS_INVALID_SOCKET(out_sock)) {
|
||||
|
@ -292,7 +305,7 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
|
|||
|
||||
#if !defined(PHP_WIN32)
|
||||
/**
|
||||
* accept4 could had been used but not all platforms support it (e.g. Haiku, solaris < 11.4, ...)
|
||||
* for fewer and fewer platforms not supporting accept4 syscall we use fcntl instead,
|
||||
* win32, not having any concept of child process, has no need to address it.
|
||||
*/
|
||||
int mode;
|
||||
|
@ -310,6 +323,7 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
out_sock->error = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue