1--TEST--
2Test if socket_set_option() works, option:SO_SEOLINGER
3--DESCRIPTION--
4-wrong params
5-set/get params comparison
6-l_linger not given
7--EXTENSIONS--
8sockets
9--FILE--
10<?php
11$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
12
13if (!$socket) {
14        die('Unable to create AF_INET socket [socket]');
15}
16// wrong params
17try {
18    $retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_LINGER, []);
19} catch (\ValueError $e) {
20    echo $e->getMessage() . \PHP_EOL;
21}
22
23// set/get comparison
24$options = array("l_onoff" => 1, "l_linger" => 1);
25$retval_2 = socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options);
26$retval_3 = socket_get_option( $socket, SOL_SOCKET, SO_LINGER);
27
28//l_linger not given
29$options_2 = array("l_onoff" => 1);
30try {
31    var_dump(socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_2));
32} catch (\ValueError $e) {
33    echo $e->getMessage() . \PHP_EOL;
34}
35
36var_dump($retval_2);
37var_dump($retval_3["l_linger"] === $options["l_linger"]);
38// value of l_onoff is not always 1, Darwin returns 128
39var_dump((bool)$retval_3["l_onoff"] === (bool)$options["l_onoff"]);
40
41socket_close($socket);
42?>
43--EXPECT--
44socket_set_option(): Argument #4 ($value) must have key "l_onoff"
45socket_set_option(): Argument #4 ($value) must have key "l_linger"
46bool(true)
47bool(true)
48bool(true)
49