1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/sockets/tests/socket_set_option_acf.phpt
Gina Peter Banyard 9eb228488a ext/sockets: Additional refactorings to socket_set_option() (#17186)
* ext/socket: Reduce scope of variables

* ext/socket: Throw TypeErrors when not passing a string for options requiring one

* ext/sockets: Throw ValueError when string has null bytes for options not passing string length

* ext/sockets: Throw ValueError when string is too long

And replace calls to strlcpy to memcpy
2024-12-29 12:18:15 +00:00

39 lines
977 B
PHP

--TEST--
Test if socket_set_option() works, option:SO_ACCEPTFILTER
--DESCRIPTION--
-wrong params
-set/get params comparison
--EXTENSIONS--
sockets
--SKIPIF--
<?php
if (!defined("SO_ACCEPTFILTER")) {
die('SKIP on platforms not supporting SO_ACCEPTFILTER');
}
?>
--FILE--
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$socket) {
die('Unable to create AF_INET socket [socket]');
}
try {
var_dump(socket_set_option( $socket, SOL_SOCKET, SO_ACCEPTFILTER, 1));
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
}
socket_listen($socket);
var_dump(socket_set_option( $socket, SOL_SOCKET, SO_ACCEPTFILTER, "httpready"));
var_dump(socket_get_option( $socket, SOL_SOCKET, SO_ACCEPTFILTER));
socket_close($socket);
?>
--EXPECT--
TypeError: socket_set_option(): Argument #4 ($value) must be of type string when argument #3 ($option) is SO_ACCEPTFILTER, int given
bool(true)
array(1) {
["af_name"]=>
string(9) "httpready"
}