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
21$retval_1 = socket_set_option( $socket, SOL_SOCKET, SO_LINGER, array());
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);
30var_dump(socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_2));
31
32var_dump($retval_2);
33var_dump($retval_3["l_linger"] === $options["l_linger"]);
34// value of l_onoff is not always 1, Darwin returns 128
35var_dump((bool)$retval_3["l_onoff"] === (bool)$options["l_onoff"]);
36
37socket_close($socket);
38?>
39
40--EXPECTF--
41Warning: socket_set_option(): no key "l_onoff" passed in optval in %s on line %d
42
43Warning: socket_set_option(): no key "l_linger" passed in optval in %s on line %d
44bool(false)
45bool(true)
46bool(true)
47bool(true)
48--CREDITS--
49Moritz Neuhaeuser, info@xcompile.net
50PHP Testfest Berlin 2009-05-10
51