Skip to content

Commit 47259e6

Browse files
committed
further changes
1 parent 9ecb367 commit 47259e6

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

ext/sockets/sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,13 +2321,13 @@ PHP_FUNCTION(socket_set_option)
23212321

23222322
zval *socket = zend_read_property(socket_so_splice_ce, so_splice_obj, "socket", strlen("socket"), false, &tmpA);
23232323
if (Z_TYPE_P(socket) == IS_NULL) {
2324-
zend_argument_type_error(4, "invalid SocketSoSplice socket member value");
2324+
zend_argument_type_error(4, "socket cannot be null");
23252325
RETURN_THROWS();
23262326
}
23272327
zval *max = zend_read_property(socket_so_splice_ce, so_splice_obj, "max", strlen("max"), false, &tmpB);
23282328
zval *array = zend_read_property(socket_so_splice_ce, so_splice_obj, "time", strlen("time"), false, &tmpC);
23292329
if (Z_TYPE_P(array) == IS_NULL) {
2330-
zend_argument_type_error(4, "invalid SocketSoSplice time member value");
2330+
zend_argument_type_error(4, "time cannot be null");
23312331
RETURN_THROWS();
23322332
}
23332333

ext/sockets/tests/socket_set_option_so_splice.phpt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,64 @@ try {
3838
echo $e->getMessage(), PHP_EOL;
3939
}
4040

41+
42+
try {
43+
$s = new SocketSoSplice();
44+
socket_set_option($socket, SOL_SOCKET, SO_SPLICE, $s);
45+
} catch (Error $e) {
46+
echo $e->getMessage(), PHP_EOL;
47+
}
48+
49+
try {
50+
$s = new SocketSoSplice();
51+
$s->max = 1024;
52+
$s->socket = $todrain;
53+
$s->time = ["invalid" => 0, "usec" => 0];
54+
socket_set_option($socket, SOL_SOCKET, SO_SPLICE, $s);
55+
} catch (Error $e) {
56+
echo $e->getMessage(), PHP_EOL;
57+
}
58+
59+
try {
60+
$s = new SocketSoSplice();
61+
$s->max = 1024;
62+
$s->socket = $todrain;
63+
$s->time = ["sec" => 0, "nosec" => 0];
64+
socket_set_option($socket, SOL_SOCKET, SO_SPLICE, $s);
65+
} catch (Error $e) {
66+
echo $e->getMessage(), PHP_EOL;
67+
}
68+
69+
socket_bind($todrain, '127.0.0.1', 0);
70+
socket_listen($todrain, 1);
71+
72+
socket_getsockname($todrain, $addr, $port);
73+
socket_connect($socket, $addr, $port);
74+
$peer = socket_accept($todrain);
75+
76+
$s1 = new SocketSoSplice();
77+
$s1->max = 5;
78+
$s1->socket = $todrain;
79+
$s1->time = ["sec" => 1, "usec" => 1];
80+
81+
$s2 = new SocketSoSplice();
82+
$s2->max = 5;
83+
$s2->socket = $socket;
84+
$s2->time = ["sec" => 1, "usec" => 1];
85+
var_dump(socket_set_option($socket, SOL_SOCKET, SO_SPLICE, $s1));
86+
var_dump(socket_set_option($todrain, SOL_SOCKET, SO_SPLICE, $s2));
87+
socket_write($socket, "HELLO", 5);
88+
var_dump(socket_read($peer, 5, PHP_NORMAL_READ));
89+
90+
socket_close($peer);
4191
socket_close($todrain);
4292
socket_close($socket);
93+
4394
?>
4495
--EXPECT--
4596
socket_set_option(): Argument #4 ($value) must be of type SocketSoSplice, Socket given
4697
socket_set_option(): Argument #4 ($value) must be of type SocketSoSplice, badClass given
4798
socket_set_option(): Argument #4 ($value) "max" key must be greater than or equal to 0
99+
Typed property SocketSoSplice::$socket must not be accessed before initialization
100+
socket_set_option(): Argument #4 ($value) time must have key "sec"
101+
socket_set_option(): Argument #4 ($value) time must have key "usec"

0 commit comments

Comments
 (0)