Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/bitcoin/network/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ namespace network {
std::forward<Args>(args)...)
#define BIND_THIS(method, args) \
std::bind(std::forward<Method>(method), static_cast<Derived*>(this), \
std::forward<Args>(args)...)
std::forward<Args>(args)...)
#define BIND(method, ...) \
bind<CLASS>(&CLASS::method, __VA_ARGS__)
#define POST(method, ...) \
post<CLASS>(&CLASS::method, __VA_ARGS__)
#define PARALLEL(method, ...) \
parallel<CLASS>(&CLASS::method, __VA_ARGS__)

} // namespace network
} // namespace libbitcoin
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/network/net/proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class BCT_API proxy
/// The channel strand.
asio::strand& strand() NOEXCEPT;

/// Get the network threadpool iocontext.
asio::io_context& service() const NOEXCEPT;

/// The strand is running in this thread.
bool stranded() const NOEXCEPT;

Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/network/net/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class BCT_API socket
/// Get the strand of the socket.
virtual asio::strand& strand() NOEXCEPT;

/// Get the network threadpool iocontext.
virtual asio::io_context& service() const NOEXCEPT;

protected:
/// The socket was upgraded to a websocket (requires strand).
virtual bool websocket() const NOEXCEPT;
Expand Down Expand Up @@ -204,6 +207,7 @@ class BCT_API socket
protected:
// These are thread safe.
asio::strand strand_;
asio::io_context& service_;
std::atomic_bool stopped_{};

// These are protected by strand (see also handle_accept).
Expand Down
12 changes: 10 additions & 2 deletions include/bitcoin/network/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,29 @@ class BCT_API protocol
/// Messaging.
/// -----------------------------------------------------------------------

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

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

/// Post base or derived class method to network threadpool (use PARALLEL).
template <class Derived, typename Method, typename... Args>
inline auto parallel(Method&& method, Args&&... args) NOEXCEPT
{
return boost::asio::post(channel_->service(),
BIND_SHARED(method, args));
}

/// Subscribe to messages broadcasts by type (use SUBSCRIBE_BROADCAST).
/// Method is invoked with error::subscriber_stopped if already stopped.
template <class Derived, class Message, typename Method, typename... Args>
Expand Down
5 changes: 5 additions & 0 deletions src/net/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ asio::strand& proxy::strand() NOEXCEPT
return socket_->strand();
}

asio::io_context& proxy::service() const NOEXCEPT
{
return socket_->service();
}

bool proxy::stranded() const NOEXCEPT
{
return socket_->stranded();
Expand Down
6 changes: 6 additions & 0 deletions src/net/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ socket::socket(const logger& log, asio::io_context& service,
const config::address& address) NOEXCEPT
: strand_(service.get_executor()),
socket_(strand_),
service_(service),
address_(address),
reporter(log),
tracker<socket>(log)
Expand Down Expand Up @@ -664,6 +665,11 @@ asio::strand& socket::strand() NOEXCEPT
return strand_;
}

asio::io_context& socket::service() const NOEXCEPT
{
return service_;
}

// Websocket properties.
// ----------------------------------------------------------------------------

Expand Down
Loading