private function establish() { \Amp\pipe(\Amp\file\get($this->path), 'Amp\\Socket\\connect')->when(function ($e, $sock) { if ($e) { $this->failAll(); return; } $this->sock = $sock; $this->writeWatcher = \Amp\onWritable($sock, $this->writer); }); }
private function establish() { $unix = in_array("unix", \stream_get_transports(), true); if ($unix) { $promise = \Amp\Socket\connect("unix://{$this->path}.sock"); } else { $promise = \Amp\pipe(\Amp\file\get($this->path), 'Amp\\Socket\\connect'); } $promise->when(function ($e, $sock) { if ($e) { $this->failAll(); return; } $this->sock = $sock; $this->writeWatcher = \Amp\onWritable($sock, $this->writer); }); }
private function bindCommandServer(string $config) { $path = CommandClient::socketPath(Bootstrapper::selectConfigFile($config)); if ((yield \Amp\file\exists($path))) { if (is_resource(@stream_socket_client((yield \Amp\file\get($path))))) { throw new \RuntimeException("Aerys is already running, can't start it again"); } } if (!($commandServer = @stream_socket_server("tcp://127.0.0.1:*", $errno, $errstr))) { throw new \RuntimeException(sprintf("Failed binding socket server on tcp://127.0.0.1:*: [%d] %s", $errno, $errstr)); } stream_set_blocking($commandServer, false); \Amp\onReadable($commandServer, function (...$args) { $this->acceptCommand(...$args); }); register_shutdown_function(function () use($path) { @\unlink($path); }); (yield \Amp\file\put($path, stream_socket_get_name($commandServer, $wantPeer = false))); }
private function bindCommandServer(string $config) { $path = CommandClient::socketPath(Bootstrapper::selectConfigFile($config)); $unix = in_array("unix", \stream_get_transports(), true); if ($unix) { $path .= ".sock"; $socketAddress = "unix://{$path}"; } else { $socketAddress = "tcp://127.0.0.1:*"; } if ((yield \Amp\file\exists($path))) { if (is_resource(@stream_socket_client($unix ? $socketAddress : (yield \Amp\file\get($path))))) { throw new \RuntimeException("Aerys is already running, can't start it again"); } elseif ($unix) { (yield \Amp\file\unlink($path)); } } if (!($commandServer = @stream_socket_server($socketAddress, $errno, $errstr))) { throw new \RuntimeException(sprintf("Failed binding socket server on {$socketAddress}: [%d] %s", $errno, $errstr)); } stream_set_blocking($commandServer, false); \Amp\onReadable($commandServer, function (...$args) { $this->acceptCommand(...$args); }); register_shutdown_function(function () use($path) { @\unlink($path); }); if (!$unix) { (yield \Amp\file\put($path, stream_socket_get_name($commandServer, $wantPeer = false))); } }