Skip to content

Commit 03bf0ee

Browse files
committed
Add socket_atmark unit test
1 parent 3660bc3 commit 03bf0ee

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

ext/sockets/tests/socket_atmark.phpt

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

0 commit comments

Comments
 (0)