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