mirror of
https://github.com/danog/ipc.git
synced 2024-11-26 20:15:05 +01:00
Catch more errors
This commit is contained in:
parent
470ab94b92
commit
d769b163ca
@ -72,8 +72,13 @@ class IpcServer
|
||||
$errors = [];
|
||||
foreach ($types as $type) {
|
||||
if ($type === self::TYPE_FIFO) {
|
||||
if (!\posix_mkfifo($uri, 0777)) {
|
||||
$errors[$type] = "could not create the FIFO socket";
|
||||
try {
|
||||
if (!\posix_mkfifo($uri, 0777)) {
|
||||
$errors[$type] = "could not create the FIFO socket";
|
||||
continue;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$errors[$type] = "could not create the FIFO socket: $e";
|
||||
continue;
|
||||
}
|
||||
$error = '';
|
||||
@ -98,9 +103,9 @@ class IpcServer
|
||||
}
|
||||
if ($this->server) {
|
||||
if ($type === self::TYPE_TCP) {
|
||||
$name = \stream_socket_get_name($this->server, false);
|
||||
$port = \substr($name, \strrpos($name, ":") + 1);
|
||||
try {
|
||||
$name = \stream_socket_get_name($this->server, false);
|
||||
$port = \substr($name, \strrpos($name, ":") + 1);
|
||||
if (!\file_put_contents($this->uri, "tcp://127.0.0.1:".$port)) {
|
||||
$errors[$type] = 'could not create URI file';
|
||||
$this->server = null;
|
||||
|
@ -58,9 +58,9 @@ function connect(string $uri): Promise
|
||||
}
|
||||
|
||||
$sockets = [
|
||||
$prefix."2",
|
||||
$prefix."1",
|
||||
];
|
||||
$prefix."2",
|
||||
$prefix."1",
|
||||
];
|
||||
|
||||
foreach ($sockets as $k => &$socket) {
|
||||
if (!\posix_mkfifo($socket, 0777)) {
|
||||
@ -83,6 +83,8 @@ function connect(string $uri): Promise
|
||||
\stream_set_write_buffer($tempSocket, 0);
|
||||
|
||||
if (!\fwrite($tempSocket, \pack('v', \strlen($prefix)).$prefix)) {
|
||||
\fclose($tempSocket);
|
||||
$tempSocket = null;
|
||||
throw new \RuntimeException("Failure sending request to FIFO server");
|
||||
}
|
||||
\fclose($tempSocket);
|
||||
|
Loading…
Reference in New Issue
Block a user