Skip to content

Commit 4c4e72f

Browse files
committed
socket add socket_atmark support.
checks whether the socket belongs to the out-of-band mark, thus allows to be processed accordingly (using the MSG_OOB flag on send/recv). Closes #9846.
1 parent fd6d2cc commit 4c4e72f

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ PHP NEWS
5252
. Added SO_ATTACH_REUSEPORT_CBPF socket option, to give tighter control
5353
over socket binding for a cpu core. (David Carlier)
5454
. Added SKF_AD_QUEUE for cbpf filters. (David Carlier)
55+
. Added socket_atmark if send/recv needs using MSG_OOB. (David Carlier)
5556

5657
- Streams:
5758
. Fixed bug #51056: blocking fread() will block even if data is available.

UPGRADING

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ PHP 8.3 UPGRADE NOTES
5858
- Posix:
5959
. Added posix_sysconf call to get runtime informations.
6060

61+
- Sockets:
62+
. Added socket_atmark to checks if the socket is OOB marked.
63+
6164
========================================
6265
7. New Classes and Interfaces
6366
========================================

ext/sockets/config.m4

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP_ARG_ENABLE([sockets],
55

66
if test "$PHP_SOCKETS" != "no"; then
77
AC_CHECK_FUNCS([hstrerror if_nametoindex if_indextoname])
8+
AC_CHECK_FUNCS(sockatmark)
89
AC_CHECK_HEADERS([netinet/tcp.h sys/un.h sys/sockio.h linux/filter.h])
910
AC_DEFINE([HAVE_SOCKETS], 1, [ ])
1011

ext/sockets/sockets.c

+26
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,32 @@ PHP_FUNCTION(socket_shutdown)
21092109
/* }}} */
21102110
#endif
21112111

2112+
#ifdef HAVE_SOCKATMARK
2113+
PHP_FUNCTION(socket_atmark)
2114+
{
2115+
zval *arg1;
2116+
php_socket *php_sock;
2117+
int r;
2118+
2119+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &arg1, socket_ce) == FAILURE) {
2120+
RETURN_THROWS();
2121+
}
2122+
2123+
php_sock = Z_SOCKET_P(arg1);
2124+
ENSURE_SOCKET_VALID(php_sock);
2125+
2126+
r = sockatmark(php_sock->bsd_socket);
2127+
if (r < 0) {
2128+
PHP_SOCKET_ERROR(php_sock, "Unable to apply sockmark", errno);
2129+
RETURN_FALSE;
2130+
} else if (r == 0) {
2131+
RETURN_FALSE;
2132+
} else {
2133+
RETURN_TRUE;
2134+
}
2135+
}
2136+
#endif
2137+
21122138
/* {{{ Returns the last socket error (either the last used or the provided socket resource) */
21132139
PHP_FUNCTION(socket_last_error)
21142140
{

ext/sockets/sockets.stub.php

+4
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,10 @@ function socket_create_pair(int $domain, int $type, int $protocol, &$pair): bool
17981798
function socket_shutdown(Socket $socket, int $mode = 2): bool {}
17991799
#endif
18001800

1801+
#ifdef HAVE_SOCKATMARK
1802+
function socket_atmark(Socket $socket): bool {}
1803+
#endif
1804+
18011805
function socket_last_error(?Socket $socket = null): int {}
18021806

18031807
function socket_clear_error(?Socket $socket = null): void {}

ext/sockets/sockets_arginfo.h

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)