<?php namespace React\Socket; use React\EventLoop\LoopInterface; use React\Promise\Timer; use React\Promise\Timer\TimeoutException; final class TimeoutConnector implements ConnectorInterface { private $connector; private $timeout; private $loop; public function __construct(ConnectorInterface $connector, $timeout, LoopInterface $loop) { $this->connector = $connector; $this->timeout = $timeout; $this->loop = $loop; } public function connect($uri) { return Timer\timeout($this->connector->connect($uri), $this->timeout, $this->loop)->then(null, self::handler($uri)); } /** * Creates a static rejection handler that reports a proper error message in case of a timeout. * * This uses a private static helper method to ensure this closure is not * bound to this instance and the exception trace does not include a * reference to this instance and its connector stack as a result. * * @param string $uri * @return callable */ private static function handler($uri) { return function (\Exception $e) use ($uri) { if ($e instanceof TimeoutException) { throw new \RuntimeException( 'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 0 ); } throw $e; }; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Connection.php | File | 5.42 KB | 0644 |
|
ConnectionInterface.php | File | 4.32 KB | 0644 |
|
Connector.php | File | 4.21 KB | 0644 |
|
ConnectorInterface.php | File | 2.02 KB | 0644 |
|
DnsConnector.php | File | 4.42 KB | 0644 |
|
FixedUriConnector.php | File | 1.05 KB | 0644 |
|
LimitingServer.php | File | 6.47 KB | 0644 |
|
SecureConnector.php | File | 2.99 KB | 0644 |
|
SecureServer.php | File | 6.91 KB | 0644 |
|
Server.php | File | 1.83 KB | 0644 |
|
ServerInterface.php | File | 5.15 KB | 0644 |
|
StreamEncryption.php | File | 4.91 KB | 0644 |
|
TcpConnector.php | File | 4.27 KB | 0644 |
|
TcpServer.php | File | 7.55 KB | 0644 |
|
TimeoutConnector.php | File | 1.45 KB | 0644 |
|
UnixConnector.php | File | 1.12 KB | 0644 |
|
UnixServer.php | File | 4.15 KB | 0644 |
|