-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathconnect.php
31 lines (25 loc) · 862 Bytes
/
connect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
declare(strict_types=1);
namespace Psl\Unix;
use Psl\DateTime\Duration;
use Psl\Network;
use Psl\OS;
/**
* Connect to a socket.
*
* @param non-empty-string $path
*
* @throws Network\Exception\RuntimeException If failed to connect to client on the given address.
* @throws Network\Exception\TimeoutException If $timeout is non-null, and the operation timed-out.
*/
function connect(string $path, null|Duration $timeout = null): Network\StreamSocketInterface
{
// @codeCoverageIgnoreStart
if (OS\is_windows()) {
throw new Network\Exception\RuntimeException('Unix socket is not supported on Windows platform.');
}
// @codeCoverageIgnoreEnd
$socket = Network\Internal\socket_connect("unix://$path", timeout: $timeout);
/** @psalm-suppress MissingThrowsDocblock */
return new Network\Internal\Socket($socket);
}