Removed the nowait option from the public interface, because the deferred would never be called and implemented a queue to wait for synchronous methods to complete before sending the next frame
This commit is contained in:
parent
e0b709fa63
commit
a9570277b7
|
|
@ -174,42 +174,30 @@ public:
|
|||
/**
|
||||
* Bind two exchanges to each other
|
||||
*
|
||||
* The following flags can be used for the exchange
|
||||
*
|
||||
* - nowait do not wait on response
|
||||
*
|
||||
* @param source the source exchange
|
||||
* @param target the target exchange
|
||||
* @param routingkey the routing key
|
||||
* @param flags optional flags
|
||||
* @param arguments additional bind arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments) { return _implementation.bindExchange(source, target, routingkey, flags, arguments); }
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments) { return _implementation.bindExchange(source, target, routingkey, 0, arguments); }
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags = 0) { return _implementation.bindExchange(source, target, routingkey, flags, Table()); }
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments) { return _implementation.bindExchange(source, target, routingkey, arguments); }
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey) { return _implementation.bindExchange(source, target, routingkey, Table()); }
|
||||
|
||||
/**
|
||||
* Unbind two exchanges from one another
|
||||
*
|
||||
* The following flags can be used for the exchange
|
||||
*
|
||||
* - nowait do not wait on response
|
||||
*
|
||||
* @param target the target exchange
|
||||
* @param source the source exchange
|
||||
* @param routingkey the routing key
|
||||
* @param flags optional flags
|
||||
* @param arguments additional unbind arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, int flags, const Table &arguments) { return _implementation.unbindExchange(target, source, routingkey, flags, arguments); }
|
||||
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, const Table &arguments) { return _implementation.unbindExchange(target, source, routingkey, 0, arguments); }
|
||||
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, int flags = 0) { return _implementation.unbindExchange(target, source, routingkey, flags, Table()); }
|
||||
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey, const Table &arguments) { return _implementation.unbindExchange(target, source, routingkey, arguments); }
|
||||
Deferred &unbindExchange(const std::string &target, const std::string &source, const std::string &routingkey) { return _implementation.unbindExchange(target, source, routingkey, Table()); }
|
||||
|
||||
/**
|
||||
* Declare a queue
|
||||
|
|
@ -250,22 +238,16 @@ public:
|
|||
/**
|
||||
* Bind a queue to an exchange
|
||||
*
|
||||
* The following flags can be used for the exchange
|
||||
*
|
||||
* - nowait do not wait on response
|
||||
*
|
||||
* @param exchange the source exchange
|
||||
* @param queue the target queue
|
||||
* @param routingkey the routing key
|
||||
* @param flags additional flags
|
||||
* @param arguments additional bind arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, int flags, const Table &arguments) { return _implementation.bindQueue(exchange, queue, routingkey, flags, arguments); }
|
||||
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, const Table &arguments) { return _implementation.bindQueue(exchange, queue, routingkey, 0, arguments); }
|
||||
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, int flags = 0) { return _implementation.bindQueue(exchange, queue, routingkey, flags, Table()); }
|
||||
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey, const Table &arguments) { return _implementation.bindQueue(exchange, queue, routingkey, arguments); }
|
||||
Deferred &bindQueue(const std::string &exchange, const std::string &queue, const std::string &routingkey) { return _implementation.bindQueue(exchange, queue, routingkey, Table()); }
|
||||
|
||||
/**
|
||||
* Unbind a queue from an exchange
|
||||
|
|
@ -283,12 +265,7 @@ public:
|
|||
/**
|
||||
* Purge a queue
|
||||
*
|
||||
* The following flags can be used for the exchange
|
||||
*
|
||||
* - nowait do not wait on response
|
||||
*
|
||||
* @param name name of the queue
|
||||
* @param flags additional flags
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
|
|
@ -303,7 +280,7 @@ public:
|
|||
*
|
||||
* });
|
||||
*/
|
||||
DeferredDelete &purgeQueue(const std::string &name, int flags = 0){ return _implementation.purgeQueue(name, flags); }
|
||||
DeferredDelete &purgeQueue(const std::string &name){ return _implementation.purgeQueue(name); }
|
||||
|
||||
/**
|
||||
* Remove a queue
|
||||
|
|
@ -375,11 +352,6 @@ public:
|
|||
* - nolocal if set, messages published on this channel are not also consumed
|
||||
* - noack if set, consumed messages do not have to be acked, this happens automatically
|
||||
* - exclusive request exclusive access, only this consumer can access the queue
|
||||
* - nowait the server does not have to send a response back that consuming is active
|
||||
*
|
||||
* The method Deferred::onSuccess() will be called when the
|
||||
* consumer has started (unless the nowait option was set, in which case
|
||||
* no confirmation method is called)
|
||||
*
|
||||
* @param queue the queue from which you want to consume
|
||||
* @param tag a consumer tag that will be associated with this consume operation
|
||||
|
|
@ -411,16 +383,7 @@ public:
|
|||
*
|
||||
* If you want to stop a running consumer, you can use this method with the consumer tag
|
||||
*
|
||||
* The following flags are supported:
|
||||
*
|
||||
* - nowait the server does not have to send a response back that the consumer has been cancelled
|
||||
*
|
||||
* The method Deferred::onSuccess() will be called when the consumer
|
||||
* was succesfully stopped (unless the nowait option was used, in which case no
|
||||
* confirmation method is called)
|
||||
*
|
||||
* @param tag the consumer tag
|
||||
* @param flags optional additional flags
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
|
|
@ -435,7 +398,7 @@ public:
|
|||
*
|
||||
* });
|
||||
*/
|
||||
DeferredCancel &cancel(const std::string &tag, int flags = 0) { return _implementation.cancel(tag, flags); }
|
||||
DeferredCancel &cancel(const std::string &tag) { return _implementation.cancel(tag); }
|
||||
|
||||
/**
|
||||
* Acknoldge a received message
|
||||
|
|
|
|||
|
|
@ -86,6 +86,19 @@ private:
|
|||
state_closed
|
||||
} _state = state_connected;
|
||||
|
||||
/**
|
||||
* The frames that still need to be send out
|
||||
*
|
||||
* We store the data as well as whether they
|
||||
* should be handled synchronously.
|
||||
*/
|
||||
std::queue<std::pair<bool, OutBuffer>> _queue;
|
||||
|
||||
/**
|
||||
* Are we currently operating in synchronous mode?
|
||||
*/
|
||||
bool _synchronous = false;
|
||||
|
||||
/**
|
||||
* The message that is now being received
|
||||
* @var ConsumedMessage
|
||||
|
|
@ -203,13 +216,12 @@ public:
|
|||
* @param source exchange which binds to target
|
||||
* @param target exchange to bind to
|
||||
* @param routingKey routing key
|
||||
* @param glags additional flags
|
||||
* @param arguments additional arguments for binding
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments);
|
||||
Deferred &bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments);
|
||||
|
||||
/**
|
||||
* unbind two exchanges
|
||||
|
|
@ -217,13 +229,12 @@ public:
|
|||
* @param source the source exchange
|
||||
* @param target the target exchange
|
||||
* @param routingkey the routing key
|
||||
* @param flags optional flags
|
||||
* @param arguments additional unbind arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &unbindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments);
|
||||
Deferred &unbindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments);
|
||||
|
||||
/**
|
||||
* remove an exchange
|
||||
|
|
@ -253,13 +264,12 @@ public:
|
|||
* @param exchangeName name of the exchange to bind to
|
||||
* @param queueName name of the queue
|
||||
* @param routingkey routingkey
|
||||
* @param flags additional flags
|
||||
* @param arguments additional arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &bindQueue(const std::string &exchangeName, const std::string &queueName, const std::string &routingkey, int flags, const Table &arguments);
|
||||
Deferred &bindQueue(const std::string &exchangeName, const std::string &queueName, const std::string &routingkey, const Table &arguments);
|
||||
|
||||
/**
|
||||
* Unbind a queue from an exchange
|
||||
|
|
@ -277,7 +287,6 @@ public:
|
|||
/**
|
||||
* Purge a queue
|
||||
* @param queue queue to purge
|
||||
* @param flags additional flags
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
|
|
@ -292,7 +301,7 @@ public:
|
|||
*
|
||||
* });
|
||||
*/
|
||||
DeferredDelete &purgeQueue(const std::string &name, int flags);
|
||||
DeferredDelete &purgeQueue(const std::string &name);
|
||||
|
||||
/**
|
||||
* Remove a queue
|
||||
|
|
@ -363,7 +372,6 @@ public:
|
|||
/**
|
||||
* Cancel a running consumer
|
||||
* @param tag the consumer tag
|
||||
* @param flags optional flags
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
|
|
@ -378,7 +386,7 @@ public:
|
|||
*
|
||||
* });
|
||||
*/
|
||||
DeferredCancel &cancel(const std::string &tag, int flags);
|
||||
DeferredCancel &cancel(const std::string &tag);
|
||||
|
||||
/**
|
||||
* Acknowledge a message
|
||||
|
|
@ -429,39 +437,61 @@ public:
|
|||
*/
|
||||
bool send(const Frame &frame);
|
||||
|
||||
/**
|
||||
* Signal the channel that a synchronous operation
|
||||
* was completed. After this operation, waiting
|
||||
* frames can be sent out.
|
||||
*/
|
||||
void synchronized();
|
||||
|
||||
/**
|
||||
* Report to the handler that the channel is opened
|
||||
*/
|
||||
void reportReady()
|
||||
{
|
||||
// callbacks could destroy us, so monitor it
|
||||
Monitor monitor(this);
|
||||
|
||||
// inform handler
|
||||
if (_readyCallback) _readyCallback();
|
||||
|
||||
// if the monitor is still valid, we exit synchronous mode now
|
||||
if (monitor.valid()) synchronized();
|
||||
}
|
||||
|
||||
/**
|
||||
* Report to the handler that the channel is closed
|
||||
*
|
||||
* Returns whether the channel object is still valid
|
||||
*/
|
||||
void reportClosed()
|
||||
bool reportClosed()
|
||||
{
|
||||
// change state
|
||||
_state = state_closed;
|
||||
|
||||
// and pass on to the reportSuccess() method which will call the
|
||||
// appropriate deferred object to report the successful operation
|
||||
reportSuccess();
|
||||
return reportSuccess();
|
||||
|
||||
// technically, we should exit synchronous method now
|
||||
// since the synchronous channel close frame has been
|
||||
// acknowledged by the server.
|
||||
//
|
||||
// but since the channel was just closed, there is no
|
||||
// real point in doing this, as we cannot send frames
|
||||
// out anymore.
|
||||
}
|
||||
|
||||
/**
|
||||
* Report success
|
||||
*
|
||||
* This function is called to report success for all
|
||||
* cases where the callback does not receive any parameters
|
||||
* Returns whether the channel object is still valid
|
||||
*/
|
||||
template <typename... Arguments>
|
||||
void reportSuccess(Arguments ...parameters)
|
||||
bool reportSuccess(Arguments ...parameters)
|
||||
{
|
||||
// skip if there is no oldest callback
|
||||
if (!_oldestCallback) return;
|
||||
if (!_oldestCallback) return true;
|
||||
|
||||
// we are going to call callbacks that could destruct the channel
|
||||
Monitor monitor(this);
|
||||
|
|
@ -470,13 +500,16 @@ public:
|
|||
auto *next = _oldestCallback->reportSuccess(std::forward<Arguments>(parameters)...);
|
||||
|
||||
// leap out if channel no longer exists
|
||||
if (!monitor.valid()) return;
|
||||
if (!monitor.valid()) return false;
|
||||
|
||||
// set the oldest callback
|
||||
_oldestCallback.reset(next);
|
||||
|
||||
// if there was no next callback, the newest callback was just used
|
||||
if (!next) _newestCallback = nullptr;
|
||||
|
||||
// we are still valid
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -253,6 +253,13 @@ public:
|
|||
*/
|
||||
bool send(const Frame &frame);
|
||||
|
||||
/**
|
||||
* Send buffered data over the connection
|
||||
*
|
||||
* @param buffer the buffer with data to send
|
||||
*/
|
||||
bool send(OutBuffer &&buffer);
|
||||
|
||||
/**
|
||||
* Get a channel by its identifier
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ extern const int global;
|
|||
extern const int nolocal;
|
||||
extern const int noack;
|
||||
extern const int exclusive;
|
||||
extern const int nowait;
|
||||
extern const int mandatory;
|
||||
extern const int immediate;
|
||||
extern const int redelivered;
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public:
|
|||
* Get access to the internal buffer
|
||||
* @return const char*
|
||||
*/
|
||||
const char *data()
|
||||
const char *data() const
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ public:
|
|||
* Current size of the output buffer
|
||||
* @return size_t
|
||||
*/
|
||||
size_t size()
|
||||
size_t size() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,17 @@ public:
|
|||
*/
|
||||
virtual ~BasicAckFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
virtual bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method ID
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -68,6 +68,18 @@ public:
|
|||
*/
|
||||
virtual ~BasicCancelFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous when the nowait option is not used
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the consumertag, which is specified by the client or provided by the server
|
||||
* @return string
|
||||
|
|
@ -90,7 +102,7 @@ public:
|
|||
* Return whether to wait for a response
|
||||
* @return boolean
|
||||
*/
|
||||
const bool noWait()
|
||||
const bool noWait() const
|
||||
{
|
||||
return _noWait.get(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public:
|
|||
if (!channel) return false;
|
||||
|
||||
// report
|
||||
channel->reportSuccess<const std::string&>(consumerTag());
|
||||
if (channel->reportSuccess<const std::string&>(consumerTag())) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -111,6 +111,18 @@ public:
|
|||
*/
|
||||
virtual ~BasicConsumeFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous when the nowait option is not set
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method ID
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public:
|
|||
if (!channel) return false;
|
||||
|
||||
// report
|
||||
channel->reportSuccess(consumerTag());
|
||||
if (channel->reportSuccess(consumerTag())) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,17 @@ public:
|
|||
return _routingKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
virtual bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method ID
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -94,6 +94,17 @@ public:
|
|||
*/
|
||||
virtual ~BasicPublishFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the exchange to publish to
|
||||
* @return string
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public:
|
|||
if (!channel) return false;
|
||||
|
||||
// report
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,17 @@ public:
|
|||
*/
|
||||
virtual ~BasicRecoverAsyncFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
virtual bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method ID
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -62,6 +62,17 @@ public:
|
|||
*/
|
||||
virtual ~BasicRecoverFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method ID
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -73,6 +73,17 @@ public:
|
|||
*/
|
||||
virtual ~BasicRejectFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method ID
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -92,6 +92,17 @@ public:
|
|||
*/
|
||||
virtual ~BasicReturnFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
virtual bool synchronous() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the exchange to publish to
|
||||
* @return string
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public:
|
|||
if (!channel) return false;
|
||||
|
||||
// report that the channel is closed
|
||||
channel->reportClosed();
|
||||
if (channel->reportClosed()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public:
|
|||
if (!channel) return false;
|
||||
|
||||
// report success for the call
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ Deferred &ChannelImpl::declareExchange(const std::string &name, ExchangeType typ
|
|||
if (type == ExchangeType::headers)exchangeType = "headers";
|
||||
|
||||
// send declare exchange frame
|
||||
return push(ExchangeDeclareFrame(_id, name, exchangeType, flags & passive, flags & durable, flags & nowait, arguments));
|
||||
return push(ExchangeDeclareFrame(_id, name, exchangeType, flags & passive, flags & durable, false, arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -231,16 +231,15 @@ Deferred &ChannelImpl::declareExchange(const std::string &name, ExchangeType typ
|
|||
* @param source exchange which binds to target
|
||||
* @param target exchange to bind to
|
||||
* @param routingKey routing key
|
||||
* @param flags additional flags
|
||||
* @param arguments additional arguments for binding
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &ChannelImpl::bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments)
|
||||
Deferred &ChannelImpl::bindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments)
|
||||
{
|
||||
// send exchange bind frame
|
||||
return push(ExchangeBindFrame(_id, target, source, routingkey, flags & nowait, arguments));
|
||||
return push(ExchangeBindFrame(_id, target, source, routingkey, false, arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -249,16 +248,15 @@ Deferred &ChannelImpl::bindExchange(const std::string &source, const std::string
|
|||
* @param source the source exchange
|
||||
* @param target the target exchange
|
||||
* @param routingkey the routing key
|
||||
* @param flags optional flags
|
||||
* @param arguments additional unbind arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &ChannelImpl::unbindExchange(const std::string &source, const std::string &target, const std::string &routingkey, int flags, const Table &arguments)
|
||||
Deferred &ChannelImpl::unbindExchange(const std::string &source, const std::string &target, const std::string &routingkey, const Table &arguments)
|
||||
{
|
||||
// send exchange unbind frame
|
||||
return push(ExchangeUnbindFrame(_id, target, source, routingkey, flags & nowait, arguments));
|
||||
return push(ExchangeUnbindFrame(_id, target, source, routingkey, false, arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -273,7 +271,7 @@ Deferred &ChannelImpl::unbindExchange(const std::string &source, const std::stri
|
|||
Deferred &ChannelImpl::removeExchange(const std::string &name, int flags)
|
||||
{
|
||||
// send delete exchange frame
|
||||
return push(ExchangeDeleteFrame(_id, name, flags & ifunused, flags & nowait));
|
||||
return push(ExchangeDeleteFrame(_id, name, flags & ifunused, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -288,7 +286,7 @@ Deferred &ChannelImpl::removeExchange(const std::string &name, int flags)
|
|||
DeferredQueue &ChannelImpl::declareQueue(const std::string &name, int flags, const Table &arguments)
|
||||
{
|
||||
// the frame to send
|
||||
QueueDeclareFrame frame(_id, name, flags & passive, flags & durable, flags & exclusive, flags & autodelete, flags & nowait, arguments);
|
||||
QueueDeclareFrame frame(_id, name, flags & passive, flags & durable, flags & exclusive, flags & autodelete, false, arguments);
|
||||
|
||||
// send the queuedeclareframe
|
||||
auto *result = new DeferredQueue(send(frame));
|
||||
|
|
@ -306,16 +304,15 @@ DeferredQueue &ChannelImpl::declareQueue(const std::string &name, int flags, con
|
|||
* @param exchangeName name of the exchange to bind to
|
||||
* @param queueName name of the queue
|
||||
* @param routingkey routingkey
|
||||
* @param flags additional flags
|
||||
* @param arguments additional arguments
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
*/
|
||||
Deferred &ChannelImpl::bindQueue(const std::string &exchangeName, const std::string &queueName, const std::string &routingkey, int flags, const Table &arguments)
|
||||
Deferred &ChannelImpl::bindQueue(const std::string &exchangeName, const std::string &queueName, const std::string &routingkey, const Table &arguments)
|
||||
{
|
||||
// send the bind queue frame
|
||||
return push(QueueBindFrame(_id, queueName, exchangeName, routingkey, flags & nowait, arguments));
|
||||
return push(QueueBindFrame(_id, queueName, exchangeName, routingkey, false, arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -338,7 +335,6 @@ Deferred &ChannelImpl::unbindQueue(const std::string &exchange, const std::strin
|
|||
/**
|
||||
* Purge a queue
|
||||
* @param queue queue to purge
|
||||
* @param flags additional flags
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
|
|
@ -353,10 +349,10 @@ Deferred &ChannelImpl::unbindQueue(const std::string &exchange, const std::strin
|
|||
*
|
||||
* });
|
||||
*/
|
||||
DeferredDelete &ChannelImpl::purgeQueue(const std::string &name, int flags)
|
||||
DeferredDelete &ChannelImpl::purgeQueue(const std::string &name)
|
||||
{
|
||||
// the frame to send
|
||||
QueuePurgeFrame frame(_id, name, flags & nowait);
|
||||
QueuePurgeFrame frame(_id, name, false);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto *deferred = new DeferredDelete(send(frame));
|
||||
|
|
@ -389,7 +385,7 @@ DeferredDelete &ChannelImpl::purgeQueue(const std::string &name, int flags)
|
|||
DeferredDelete &ChannelImpl::removeQueue(const std::string &name, int flags)
|
||||
{
|
||||
// the frame to send
|
||||
QueueDeleteFrame frame(_id, name, flags & ifunused, flags & ifempty, flags & nowait);
|
||||
QueueDeleteFrame frame(_id, name, flags & ifunused, flags & ifempty, false);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto *deferred = new DeferredDelete(send(frame));
|
||||
|
|
@ -495,7 +491,7 @@ Deferred &ChannelImpl::setQos(uint16_t prefetchCount)
|
|||
DeferredConsumer& ChannelImpl::consume(const std::string &queue, const std::string &tag, int flags, const Table &arguments)
|
||||
{
|
||||
// the frame to send
|
||||
BasicConsumeFrame frame(_id, queue, tag, flags & nolocal, flags & noack, flags & exclusive, flags & nowait, arguments);
|
||||
BasicConsumeFrame frame(_id, queue, tag, flags & nolocal, flags & noack, flags & exclusive, false, arguments);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto *deferred = new DeferredConsumer(this, send(frame));
|
||||
|
|
@ -510,7 +506,6 @@ DeferredConsumer& ChannelImpl::consume(const std::string &queue, const std::stri
|
|||
/**
|
||||
* Cancel a running consumer
|
||||
* @param tag the consumer tag
|
||||
* @param flags optional flags
|
||||
*
|
||||
* This function returns a deferred handler. Callbacks can be installed
|
||||
* using onSuccess(), onError() and onFinalize() methods.
|
||||
|
|
@ -525,10 +520,10 @@ DeferredConsumer& ChannelImpl::consume(const std::string &queue, const std::stri
|
|||
*
|
||||
* });
|
||||
*/
|
||||
DeferredCancel &ChannelImpl::cancel(const std::string &tag, int flags)
|
||||
DeferredCancel &ChannelImpl::cancel(const std::string &tag)
|
||||
{
|
||||
// the cancel frame to send
|
||||
BasicCancelFrame frame(_id, tag, flags & nowait);
|
||||
BasicCancelFrame frame(_id, tag, false);
|
||||
|
||||
// send the frame, and create deferred object
|
||||
auto *deferred = new DeferredCancel(this, send(frame));
|
||||
|
|
@ -587,10 +582,56 @@ bool ChannelImpl::send(const Frame &frame)
|
|||
// skip if channel is not connected
|
||||
if (_state != state_connected || !_connection) return false;
|
||||
|
||||
// are we currently in synchronous mode or are there
|
||||
// other frames waiting for their turn to be sent?
|
||||
if (_synchronous || !_queue.empty())
|
||||
{
|
||||
// we need to wait until the synchronous frame has
|
||||
// been processed, so queue the frame until it was
|
||||
_queue.emplace(frame.synchronous(), frame.buffer());
|
||||
|
||||
// it was of course not actually sent but we pretend
|
||||
// that it was, because no error occured
|
||||
return true;
|
||||
}
|
||||
|
||||
// enter synchronous mode if necessary
|
||||
_synchronous = frame.synchronous();
|
||||
|
||||
// send to tcp connection
|
||||
return _connection->send(frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal the channel that a synchronous operation
|
||||
* was completed. After this operation, waiting
|
||||
* frames can be sent out.
|
||||
*/
|
||||
void ChannelImpl::synchronized()
|
||||
{
|
||||
// we are no longer waiting for synchronous operations
|
||||
_synchronous = false;
|
||||
|
||||
// we need to monitor the channel for validity
|
||||
Monitor monitor(this);
|
||||
|
||||
// send all frames while not in synchronous mode
|
||||
while (monitor.valid() && !_synchronous && !_queue.empty())
|
||||
{
|
||||
// retrieve the first buffer and synchronous
|
||||
auto pair = std::move(_queue.front());
|
||||
|
||||
// remove from the list
|
||||
_queue.pop();
|
||||
|
||||
// mark as synchronous if necessary
|
||||
_synchronous = pair.first;
|
||||
|
||||
// send it over the connection
|
||||
_connection->send(std::move(pair.second));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the received message
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -213,9 +213,9 @@ void ConnectionImpl::setConnected()
|
|||
// store connected state
|
||||
_state = state_connected;
|
||||
|
||||
// if the close operation was already called, we do that again now again
|
||||
// so that the actual messages to close down the connection and the channel
|
||||
// are appended to the queue
|
||||
// if the close method was called before, the frame was not
|
||||
// sent. append it to the end of the queue to make sure we
|
||||
// are correctly closed down.
|
||||
if (_closed && !sendClose()) return;
|
||||
|
||||
// we're going to call the handler, which can destruct the connection,
|
||||
|
|
@ -225,11 +225,8 @@ void ConnectionImpl::setConnected()
|
|||
// inform handler
|
||||
_handler->onConnected(_parent);
|
||||
|
||||
// leap out if the connection no longer exists
|
||||
if (!monitor.valid()) return;
|
||||
|
||||
// empty the queue of messages
|
||||
while (!_queue.empty())
|
||||
while (monitor.valid() && !_queue.empty())
|
||||
{
|
||||
// get the next message
|
||||
OutBuffer buffer(std::move(_queue.front()));
|
||||
|
|
@ -239,9 +236,6 @@ void ConnectionImpl::setConnected()
|
|||
|
||||
// send it
|
||||
_handler->onData(_parent, buffer.data(), buffer.size());
|
||||
|
||||
// leap out if the connection was destructed
|
||||
if (!monitor.valid()) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,16 +250,10 @@ bool ConnectionImpl::send(const Frame &frame)
|
|||
if (_state == state_closing || _state == state_closed) return false;
|
||||
|
||||
// we need an output buffer
|
||||
OutBuffer buffer(frame.totalSize());
|
||||
|
||||
// fill the buffer
|
||||
frame.fill(buffer);
|
||||
|
||||
// append an end of frame byte (but not when still negotiating the protocol)
|
||||
if (frame.needsSeparator()) buffer.add((uint8_t)206);
|
||||
OutBuffer buffer(frame.buffer());
|
||||
|
||||
// are we still setting up the connection?
|
||||
if ((_state == state_connected && _queue.size() == 0) || frame.partOfHandshake())
|
||||
if ((_state == state_connected && _queue.empty()) || frame.partOfHandshake())
|
||||
{
|
||||
// send the buffer
|
||||
_handler->onData(_parent, buffer.data(), buffer.size());
|
||||
|
|
@ -280,6 +268,32 @@ bool ConnectionImpl::send(const Frame &frame)
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send buffered data over the connection
|
||||
*
|
||||
* @param buffer the buffer with data to send
|
||||
*/
|
||||
bool ConnectionImpl::send(OutBuffer &&buffer)
|
||||
{
|
||||
// this only works when we are already connected
|
||||
if (_state != state_connected) return false;
|
||||
|
||||
// are we waiting for other frames to be sent before us?
|
||||
if (_queue.empty())
|
||||
{
|
||||
// send it directly
|
||||
_handler->onData(_parent, buffer.data(), buffer.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
// add to the list of waiting buffers
|
||||
_queue.push(std::move(buffer));
|
||||
}
|
||||
|
||||
// done
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* End of namspace
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -103,6 +103,17 @@ public:
|
|||
_arguments(arguments)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous when the nowait option has not been set
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination exchange
|
||||
|
|
@ -153,7 +164,7 @@ public:
|
|||
* Get the nowait bool
|
||||
* @return bool
|
||||
*/
|
||||
bool noWait()
|
||||
bool noWait() const
|
||||
{
|
||||
return _bools.get(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report to handler
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -106,6 +106,18 @@ public:
|
|||
*/
|
||||
virtual ~ExchangeDeclareFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method id
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report exchange declare ok
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -83,6 +83,18 @@ public:
|
|||
*/
|
||||
virtual ~ExchangeDeleteFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the method id
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report to handler
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -103,6 +103,17 @@ public:
|
|||
_arguments(arguments)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination exchange
|
||||
|
|
@ -153,7 +164,7 @@ public:
|
|||
* Get the nowait bool
|
||||
* @return bool
|
||||
*/
|
||||
bool noWait()
|
||||
bool noWait() const
|
||||
{
|
||||
return _bools.get(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report to handler
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
27
src/frame.h
27
src/frame.h
|
|
@ -54,6 +54,33 @@ public:
|
|||
*/
|
||||
virtual bool needsSeparator() const { return true; }
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
virtual bool synchronous() const { return false; }
|
||||
|
||||
/**
|
||||
* Retrieve the buffer in AMQP wire-format for
|
||||
* sending over the socket connection
|
||||
*/
|
||||
OutBuffer buffer() const
|
||||
{
|
||||
// we need an output buffer
|
||||
OutBuffer buffer(totalSize());
|
||||
|
||||
// fill the buffer
|
||||
fill(buffer);
|
||||
|
||||
// append an end of frame byte (but not when still negotiating the protocol)
|
||||
if (needsSeparator()) buffer.add((uint8_t)206);
|
||||
|
||||
// return the created buffer
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the frame
|
||||
* @param connection The connection over which it was received
|
||||
|
|
|
|||
|
|
@ -49,6 +49,14 @@ public:
|
|||
*/
|
||||
virtual ~MethodFrame() {}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override { return true; }
|
||||
|
||||
/**
|
||||
* Get the message type
|
||||
* @return uint8_t
|
||||
|
|
|
|||
|
|
@ -110,6 +110,18 @@ public:
|
|||
_arguments(frame)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the method id
|
||||
* @return uint16_t
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report to handler
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -98,6 +98,18 @@ public:
|
|||
_arguments(frame)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the method id
|
||||
* @return string
|
||||
|
|
@ -156,7 +168,7 @@ public:
|
|||
* returns whether to wait for a response
|
||||
* @return bool
|
||||
*/
|
||||
bool noWait()
|
||||
bool noWait() const
|
||||
{
|
||||
return _bools.get(4);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ public:
|
|||
if (!channel) return false;
|
||||
|
||||
// report success
|
||||
channel->reportSuccess(name(), messageCount(), consumerCount());
|
||||
if (channel->reportSuccess(name(), messageCount(), consumerCount())) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,18 @@ public:
|
|||
_bools(frame)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the method id
|
||||
* @returns uint16_t
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report queue deletion success
|
||||
channel->reportSuccess(this->messageCount());
|
||||
if (channel->reportSuccess(this->messageCount())) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,18 @@ public:
|
|||
_noWait(frame)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Is this a synchronous frame?
|
||||
*
|
||||
* After a synchronous frame no more frames may be
|
||||
* sent until the accompanying -ok frame arrives
|
||||
*/
|
||||
bool synchronous() const override
|
||||
{
|
||||
// we are synchronous without the nowait option
|
||||
return !noWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* The method ID
|
||||
* @return method id
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report queue purge success
|
||||
channel->reportSuccess(this->messageCount());
|
||||
if (channel->reportSuccess(this->messageCount())) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report queue unbind success
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report that the channel is open
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report that the channel is open
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public:
|
|||
if(!channel) return false;
|
||||
|
||||
// report that the channel is open
|
||||
channel->reportSuccess();
|
||||
if (channel->reportSuccess()) channel->synchronized();
|
||||
|
||||
// done
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue