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