Skip to content

Commit

Permalink
Add POST# and post<> protocol helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 11, 2024
1 parent 92e0f28 commit 6c7ee30
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion include/bitcoin/network/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ class BCT_API protocol
/// Messaging.
/// -----------------------------------------------------------------------

/// Bind a method in the base or derived class (use BIND#).
/// Bind a method in base or derived class (use BIND#).
template <class Protocol, typename Method, typename... Args>
auto bind(Method&& method, Args&&... args) NOEXCEPT
{
return BOUND_PROTOCOL(method, args);
}

/// Post a method in base or derived class to channel strand (use POST#).
template <class Protocol, typename Method, typename... Args>
auto post(Method&& method, Args&&... args) NOEXCEPT
{
return boost::asio::post(channel_->strand(),
BOUND_PROTOCOL(method, args));
}

/// Send a message instance to peer (use SEND#).
template <class Protocol, class Message, typename Method, typename... Args>
void send(const Message& message, Method&& method, Args&&... args) NOEXCEPT
Expand Down Expand Up @@ -223,6 +231,13 @@ class BCT_API protocol

// See define.hpp for BIND# macros.

#define POST1(method, p1) \
post<CLASS>(&CLASS::method, p1)
#define POST2(method, p1, p2) \
post<CLASS>(&CLASS::method, p1, p2)
#define POST3(method, p1, p2, p3) \
post<CLASS>(&CLASS::method, p1, p2, p3)

#define SEND1(message, method, p1) \
send<CLASS>(message, &CLASS::method, p1)
#define SEND2(message, method, p1, p2) \
Expand Down

0 comments on commit 6c7ee30

Please sign in to comment.