The Channel constructor now throws an exception if the max number of channels has been reached
This commit is contained in:
parent
45ca61cc43
commit
ee60aeb025
|
|
@ -31,15 +31,14 @@ public:
|
||||||
* Construct a channel object
|
* Construct a channel object
|
||||||
*
|
*
|
||||||
* The passed in connection pointer must remain valid for the
|
* The passed in connection pointer must remain valid for the
|
||||||
* lifetime of the channel.
|
* lifetime of the channel. Watch out: this method throws an error
|
||||||
|
* if the channel could not be constructed (for example because the
|
||||||
|
* max number of AMQP channels has been reached)
|
||||||
*
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
|
* @throws std::runtime_error
|
||||||
*/
|
*/
|
||||||
Channel(Connection *connection) : _implementation(new ChannelImpl())
|
Channel(Connection *connection);
|
||||||
{
|
|
||||||
// attach the connection to the channel
|
|
||||||
_implementation->attach(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy'ing of channel objects is not supported
|
* Copy'ing of channel objects is not supported
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,9 @@ private:
|
||||||
/**
|
/**
|
||||||
* Attach the connection
|
* Attach the connection
|
||||||
* @param connection
|
* @param connection
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
void attach(Connection *connection);
|
bool attach(Connection *connection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a deferred result
|
* Push a deferred result
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,12 @@ public:
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* The passed in connection pointer must remain valid for the
|
* The passed in connection pointer must remain valid for the
|
||||||
* lifetime of the channel.
|
* lifetime of the channel. A constructor is thrown if the channel
|
||||||
|
* cannot be connected (because the connection is already closed or
|
||||||
|
* because max number of channels has been reached)
|
||||||
*
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
|
* @throws std::runtime_error
|
||||||
*/
|
*/
|
||||||
TcpChannel(TcpConnection *connection) :
|
TcpChannel(TcpConnection *connection) :
|
||||||
Channel(&connection->_connection) {}
|
Channel(&connection->_connection) {}
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,9 @@ void ChannelImpl::onError(const ErrorCallback &callback)
|
||||||
/**
|
/**
|
||||||
* Initialize the object with an connection
|
* Initialize the object with an connection
|
||||||
* @param connection
|
* @param connection
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
void ChannelImpl::attach(Connection *connection)
|
bool ChannelImpl::attach(Connection *connection)
|
||||||
{
|
{
|
||||||
// get connection impl
|
// get connection impl
|
||||||
_connection = &connection->_implementation;
|
_connection = &connection->_implementation;
|
||||||
|
|
@ -110,6 +111,9 @@ void ChannelImpl::attach(Connection *connection)
|
||||||
{
|
{
|
||||||
// this is invalid
|
// this is invalid
|
||||||
_state = state_closed;
|
_state = state_closed;
|
||||||
|
|
||||||
|
// failure
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -117,10 +121,13 @@ void ChannelImpl::attach(Connection *connection)
|
||||||
_state = state_connected;
|
_state = state_connected;
|
||||||
|
|
||||||
// send the open frame
|
// send the open frame
|
||||||
if (send(ChannelOpenFrame(_id))) return;
|
if (send(ChannelOpenFrame(_id))) return true;
|
||||||
|
|
||||||
// report an error
|
// this is an error
|
||||||
reportError("Channel could not be initialized", true);
|
_state = state_closed;
|
||||||
|
|
||||||
|
// report failure
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue