Skip to content

Commit 72cac52

Browse files
committed
Add socket_atmark unit test
1 parent 3660bc3 commit 72cac52

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

ext/sockets/tests/socket_atmark.phpt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
ext/sockets - socket_atmark
3+
--EXTENSIONS--
4+
sockets
5+
--SKIPIF--
6+
<?php
7+
8+
if (PHP_OS_FAMILY !== 'Windows') die("skip not for Windows");
9+
--FILE--
10+
<?php
11+
include __DIR__."/mcast_helpers.php.inc";
12+
$path = sys_get_temp_dir() . "/socket_atmark.sock";
13+
14+
@unlink($path);
15+
16+
$string = "no chance of socket_atmark returning true";
17+
$len = strlen($string);
18+
$s_s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("socket_create failed");
19+
socket_set_nonblock($s_s) or die("socket_set_nonblock");
20+
21+
$s_c = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("socket_create failed");
22+
socket_bind($s_c, $path) or die("socket_bind failed");
23+
socket_set_nonblock($s_c) or die("socket_set_nonblock failed");
24+
socket_set_option($s_c, SOL_SOCKET, SO_PASSCRED, 1) or die("could not set SO_PASSCRED");
25+
$s_w = socket_sendto($s_s, $string, $len, 0, $path);
26+
if ($s_w != $len)
27+
die("socket_send failed");
28+
checktimeout($s_c, 500);
29+
$data = [
30+
"name" => [],
31+
"buffer_size" => 2000,
32+
"controllen" => socket_cmsg_space(SOL_SOCKET, SCM_CREDENTIALS)
33+
];
34+
35+
if (socket_atmark($s_c) === FALSE) {
36+
if (!socket_recvmsg($s_c, $data, 0))
37+
die("socket_recvmsg failed");
38+
echo "not OOB";
39+
} else {
40+
$buf = "";
41+
if (!socket_recv($s_c, $buf, 1, MSG_OOB) === FALSE)
42+
die("socket_recv failed");
43+
echo "OOB";
44+
}
45+
socket_close($s_c);
46+
socket_close($s_s);
47+
?>
48+
--CLEAN--
49+
<?php
50+
$path = sys_get_temp_dir() . "/socket_atmark.sock";
51+
@unlink($path);
52+
--EXPECT--
53+
not OOB

0 commit comments

Comments
 (0)