Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,25 @@ PHP_FUNCTION(socket_get_option)
}
}
#endif

#ifdef TCP_FUNCTION_BLK
case TCP_FUNCTION_BLK: {

struct tcp_function_set tsf = {0};
optlen = sizeof(tsf);

if (getsockopt(php_sock->bsd_socket, level, optname, &tsf, &optlen) != 0) {
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
RETURN_FALSE;
}

array_init(return_value);

add_assoc_string(return_value, "function_set_name", tsf.function_set_name);
add_assoc_long(return_value, "pcbcnt", tsf.pcbcnt);
return;
}
#endif
}
}

Expand Down Expand Up @@ -1915,6 +1934,27 @@ PHP_FUNCTION(socket_set_option)
RETURN_TRUE;
}
#endif

#ifdef TCP_FUNCTION_BLK
case TCP_FUNCTION_BLK: {
if (Z_TYPE_P(arg4) != IS_STRING) {
php_error_docref(NULL, E_WARNING, "Invalid tcp stack name argument type");
RETURN_FALSE;
}
struct tcp_function_set tfs = {0};
strlcpy(tfs.function_set_name, Z_STRVAL_P(arg4), TCP_FUNCTION_NAME_LEN_MAX);

optlen = sizeof(tfs);
opt_ptr = &tfs;
if (setsockopt(php_sock->bsd_socket, level, optname, opt_ptr, optlen) != 0) {
PHP_SOCKET_ERROR(php_sock, "Unable to set socket option", errno);
RETURN_FALSE;
}

RETURN_TRUE;
}
#endif

}
}

Expand Down
7 changes: 7 additions & 0 deletions ext/sockets/sockets.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,13 @@
*/
const TCP_KEEPCNT = UNKNOWN;
#endif
#ifdef TCP_FUNCTION_BLK
/**
* @var int
* @cvalue TCP_FUNCTION_BLK
*/
const TCP_FUNCTION_BLK = UNKNOWN;
#endif
/**
* @var int
* @cvalue PHP_NORMAL_READ
Expand Down
5 changes: 4 additions & 1 deletion ext/sockets/sockets_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions ext/sockets/tests/socket_set_option_tsf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Test if socket_set_option() works, option:TCP_FUNCTION_BLK
--EXTENSIONS--
sockets
--SKIPIF--
<?php

if (!defined("TCP_FUNCTION_BLK")) {
die('SKIP on platforms not supporting TCP_FUNCTION_BLK');
}
?>
--FILE--
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

if (!$socket) {
die('Unable to create AF_INET socket [socket]');
}
socket_set_option( $socket, SOL_TCP, TCP_FUNCTION_BLK, "nochancetoexist");
// TCP/RACK and other alternate stacks are not present by default, at least `freebsd` is.
var_dump(socket_set_option( $socket, SOL_TCP, TCP_FUNCTION_BLK, "freebsd"));
var_dump(socket_get_option( $socket, SOL_TCP, TCP_FUNCTION_BLK));
socket_close($socket);
?>
--EXPECTF--
Warning: socket_set_option(): Unable to set socket option [2]: No such file or directory in %s on line %d
bool(true)
array(2) {
["function_set_name"]=>
string(7) "freebsd"
["pcbcnt"]=>
int(%d)
}