Use different error condition in socket test

The previously used error does not occur on FreeBSD and instead
causes the operation to time out.

Also clean up the test a bit. And make sure it actually tests
something -- the point is that socket_last_error() should be 0
after socket_clear_error(). It's kind of pointless if the test
uses a wildcard for the final result instead.
This commit is contained in:
Nikita Popov 2021-05-18 15:43:44 +02:00
parent 2fabe2751c
commit b9fbbcc867

View File

@ -7,25 +7,19 @@ marcosptf - <marcosptf@yahoo.com.br> - #phparty7 - @phpsp - novatec/2015 - sao p
if (!extension_loaded('sockets')) {
die('SKIP sockets extension not available.');
}
if(substr(PHP_OS, 0, 3) == 'WIN' ) {
die('skip windows only test');
if (substr(PHP_OS, 0, 3) == 'WIN' ) {
die('skip non-windows only test');
}
?>
--FILE--
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$socketConn = socket_connect($socket, "127.0.0.1", 21248);
socket_set_option($socket, -1, -1, -1);
var_dump(socket_last_error($socket));
socket_clear_error($socket);
var_dump(socket_last_error($socket));
?>
--CLEAN--
<?php
socket_close($socket);
unset($socket);
unset($socketConn);
?>
--EXPECTF--
Warning: socket_connect(): unable to connect [%d]: Connection refused in %s on line %d
int(%d)
Warning: socket_set_option(): Unable to set socket option [%s]: %s in %s on line %d
int(%d)
int(0)