/** * 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); }
/** * Determine the connection timeout to used based on the connection options * and PHP settings. */ private function connectionTimeout(ConnectionOptions $options) : float { $connectionTimeout = $options->advancedConnectionOptions()->connectionTimeout(); if ($connectionTimeout !== null) { return $connectionTimeout; } $connectionTimeout = ini_get('default_socket_timeout'); if ($connectionTimeout !== false) { return (double) $connectionTimeout; } return self::DEFAULT_CONNECTION_TIMEOUT; }
/** * Perform the "open" phase of the handshake. * * @recoil-coroutine * * @param DuplexChannel $frames A channel over which frames are sent * and received. * @param ConnectionOptions $options The options used when establishing * the connection. */ private function open(DuplexChannel $frames, ConnectionOptions $options) : Generator { (yield $frames->write(ConnectionOpenFrame::create($options->vhost()))); try { $frame = (yield $frames->read()); } catch (ChannelClosedException $e) { throw SingleConnectionException::authorizationFailed($options, $e); } if ($frame instanceof ConnectionCloseFrame) { if ($frame->replyCode === Constants::NOT_ALLOWED && $frame->classId === ConnectionOpenFrame::METHOD_ID >> 16 && $frame->methodId === (ConnectionOpenFrame::METHOD_ID & 0xff)) { throw SingleConnectionException::authorizationFailed($options); } throw SingleConnectionException::closedUnexpectedly($options); } elseif (!$frame instanceof ConnectionOpenOkFrame) { throw ProtocolException::unexpectedFrame($frame, 'expected ' . ConnectionOpenOkFrame::class); } }