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,10 +72,15 @@ class IpcServer
|
||||
$errors = [];
|
||||
foreach ($types as $type) {
|
||||
if ($type === self::TYPE_FIFO) {
|
||||
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 = '';
|
||||
try {
|
||||
// Open in r+w mode to prevent blocking if there is no reader
|
||||
@ -98,9 +103,9 @@ class IpcServer
|
||||
}
|
||||
if ($this->server) {
|
||||
if ($type === self::TYPE_TCP) {
|
||||
try {
|
||||
$name = \stream_socket_get_name($this->server, false);
|
||||
$port = \substr($name, \strrpos($name, ":") + 1);
|
||||
try {
|
||||
if (!\file_put_contents($this->uri, "tcp://127.0.0.1:".$port)) {
|
||||
$errors[$type] = 'could not create URI file';
|
||||
$this->server = null;
|
||||
|
@ -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