Skip to content

Commit

Permalink
Support azmq::message with the azmq::async_receive() function
Browse files Browse the repository at this point in the history
When passing a azmq::message to the azmq::async_receive() function a new azmq::message is created by the receive_buffer_op_base function call instead of using the passed in azmq::buffer. Once the async operation has completed the data does not get stored in the passed in azmq::message since it was stored in the newly created object and lost once the function call has been completed.
Store the reference to the azmq::message to make sure that the correct object is used when receiving the message.
Since the object is valid while calling the async function it should be fine to create the object with a reference to the original object and once the operation has been completed the object will still be valid.
  • Loading branch information
Aidan committed Feb 27, 2024
1 parent 25c9c16 commit e632637
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions azmq/detail/receive_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace detail {
template<typename MutableBufferSequence>
class receive_buffer_op_base : public reactor_op {
public:
receive_buffer_op_base(MutableBufferSequence const& buffers, flags_type flags)
receive_buffer_op_base(MutableBufferSequence& buffers, flags_type flags)
: buffers_(buffers)
, flags_(flags)
{ }
Expand All @@ -51,15 +51,15 @@ class receive_buffer_op_base : public reactor_op {
}

private:
MutableBufferSequence buffers_;
MutableBufferSequence& buffers_;
flags_type flags_;
};

template<typename MutableBufferSequence,
typename Handler>
class receive_buffer_op : public receive_buffer_op_base<MutableBufferSequence> {
public:
receive_buffer_op(MutableBufferSequence const& buffers,
receive_buffer_op(MutableBufferSequence& buffers,
Handler handler,
socket_ops::flags_type flags)
: receive_buffer_op_base<MutableBufferSequence>(buffers, flags)
Expand Down Expand Up @@ -94,7 +94,7 @@ template<typename MutableBufferSequence,
typename Handler>
class receive_more_buffer_op : public receive_buffer_op_base<MutableBufferSequence> {
public:
receive_more_buffer_op(MutableBufferSequence const& buffers,
receive_more_buffer_op(MutableBufferSequence& buffers,
Handler handler,
socket_ops::flags_type flags)
: receive_buffer_op_base<MutableBufferSequence>(buffers, flags)
Expand Down
10 changes: 5 additions & 5 deletions azmq/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class socket :
*/
template<typename MutableBufferSequence,
typename ReadHandler>
void async_receive(MutableBufferSequence const& buffers,
void async_receive(MutableBufferSequence& buffers,
ReadHandler && handler,
flags_type flags = 0) {
using type = detail::receive_buffer_op<MutableBufferSequence, ReadHandler>;
Expand Down Expand Up @@ -539,7 +539,7 @@ class socket :
*/
template<typename MutableBufferSequence,
typename ReadMoreHandler>
void async_receive_more(MutableBufferSequence const& buffers,
void async_receive_more(MutableBufferSequence& buffers,
ReadMoreHandler && handler,
flags_type flags = 0) {
using type = detail::receive_more_buffer_op<MutableBufferSequence, ReadMoreHandler>;
Expand Down Expand Up @@ -712,7 +712,7 @@ struct async_send_initiation {
template<typename MutableBufferSequence>
struct async_receive_initiation {
azmq::socket &socket;
MutableBufferSequence const &buffers;
MutableBufferSequence &buffers;

template<typename CompletionHandler>
void operator()(CompletionHandler &&completion_handler) {
Expand All @@ -726,7 +726,7 @@ struct async_receive_initiation {
template<typename MutableBufferSequence>
struct async_receive_more_initiation {
azmq::socket &socket;
MutableBufferSequence const &buffers;
MutableBufferSequence &buffers;

template<typename CompletionHandler>
void operator()(CompletionHandler &&completion_handler) {
Expand All @@ -748,7 +748,7 @@ auto async_send(azmq::socket &socket, ConstBufferSequence const &buffers,
}

template<class CompletionToken, class MutableBufferSequence>
auto async_receive(azmq::socket &socket, MutableBufferSequence const &buffers,
auto async_receive(azmq::socket &socket, MutableBufferSequence &buffers,
CompletionToken &&token)
-> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
void(boost::system::error_code, size_t)) {
Expand Down

0 comments on commit e632637

Please sign in to comment.