Ejemplo n.º 1
0
 /**
  * @recoil-coroutine
  */
 private function connectSocket(ConnectionOptions $options) : Generator
 {
     $errorCode = null;
     $errorMessage = null;
     $stream = @stream_socket_client(\sprintf('tcp://%s:%s', $options->host(), $options->port()), $errorCode, $errorMessage, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
     if ($stream === false) {
         throw SingleConnectionException::couldNotConnect($options, $errorCode . ': ' . $errorMessage);
     }
     // Wait for the socket to open or fail ...
     stream_set_blocking($stream, false);
     list(, $writable) = (yield Recoil::select([$stream], [$stream]));
     if (empty($writable)) {
         throw SingleConnectionException::couldNotConnect($options, 'connection refused');
     }
     return $stream;
 }
Ejemplo n.º 2
0
 /**
  * Create an exception that indicates an unexpected closure of the
  * connection to the AMQP broker.
  *
  * @param ConnectionOptions $options  The options used when establishing the connection.
  * @param Exception|null    $previous The exception that caused this exception, if any.
  */
 public static function closedUnexpectedly(ConnectionOptions $options, Exception $previous = null) : SingleConnectionException
 {
     return new self($options, \sprintf('The AMQP connection with broker [%s:%d] was closed unexpectedly.', $options->host(), $options->port()), $previous);
 }