diff --git a/include/bitcoin/network/define.hpp b/include/bitcoin/network/define.hpp index aa5570907..0ae49f5c1 100644 --- a/include/bitcoin/network/define.hpp +++ b/include/bitcoin/network/define.hpp @@ -94,21 +94,16 @@ namespace libbitcoin { namespace network { -// The 'bind' method and 'CLASS' names are conventional. -#define BIND1(method, p1) \ - bind(&CLASS::method, p1) -#define BIND2(method, p1, p2) \ - bind(&CLASS::method, p1, p2) -#define BIND3(method, p1, p2, p3) \ - bind(&CLASS::method, p1, p2, p3) -#define BIND4(method, p1, p2, p3, p4) \ - bind(&CLASS::method, p1, p2, p3, p4) -#define BIND5(method, p1, p2, p3, p4, p5) \ - bind(&CLASS::method, p1, p2, p3, p4, p5) -#define BIND6(method, p1, p2, p3, p4, p5, p6) \ - bind(&CLASS::method, p1, p2, p3, p4, p5, p6) -#define BIND7(method, p1, p2, p3, p4, p5, p6, p7) \ - bind(&CLASS::method, p1, p2, p3, p4, p5, p6, p7) +#define BIND_SHARED(method, args) \ + std::bind(std::forward(method), shared_from_base(), \ + std::forward(args)...) +#define BIND_THIS(method, args) \ + std::bind(std::forward(method), static_cast(this), \ + std::forward(args)...) +#define BIND(method, ...) \ + bind(&CLASS::method, __VA_ARGS__) +#define POST(method, ...) \ + post(&CLASS::method, __VA_ARGS__) } // namespace network } // namespace libbitcoin diff --git a/include/bitcoin/network/protocols/protocol.hpp b/include/bitcoin/network/protocols/protocol.hpp index 439d04284..706b7d0b3 100644 --- a/include/bitcoin/network/protocols/protocol.hpp +++ b/include/bitcoin/network/protocols/protocol.hpp @@ -35,10 +35,6 @@ namespace libbitcoin { namespace network { -#define BOUND_PROTOCOL(method, args) \ - std::bind(std::forward(method), shared_from_base(), \ - std::forward(args)...) - /// This class is thread safe, except for: /// * start/started must be called on strand. /// * setters should only be invoked during handshake. @@ -76,47 +72,46 @@ class BCT_API protocol /// ----------------------------------------------------------------------- /// Bind a method in base or derived class (use BIND#). - template + template auto bind(Method&& method, Args&&... args) NOEXCEPT { - return BOUND_PROTOCOL(method, args); + return BIND_SHARED(method, args); } /// Post a method in base or derived class to channel strand (use POST#). - template + template auto post(Method&& method, Args&&... args) NOEXCEPT { return boost::asio::post(channel_->strand(), - BOUND_PROTOCOL(method, args)); + BIND_SHARED(method, args)); } /// Send a message instance to peer (use SEND#). - template + template void send(const Message& message, Method&& method, Args&&... args) NOEXCEPT { BC_ASSERT_MSG(stranded(), "strand"); - channel_->send(message, BOUND_PROTOCOL(method, args)); + channel_->send(message, BIND_SHARED(method, args)); } /// Subscribe to channel messages by type (use SUBSCRIBE_CHANNEL#). /// Method is invoked with error::subscriber_stopped if already stopped. - template + template void subscribe_channel(Method&& method, Args&&... args) NOEXCEPT { BC_ASSERT_MSG(stranded(), "strand"); - channel_->subscribe(BOUND_PROTOCOL(method, args)); + channel_->subscribe(BIND_SHARED(method, args)); } /// Subscribe to messages broadcasts by type (use SUBSCRIBE_BROADCAST#). /// Method is invoked with error::subscriber_stopped if already stopped. - template + template void subscribe_broadcast(Method&& method, Args&&... args) NOEXCEPT { BC_ASSERT_MSG(stranded(), "strand"); - // handler is a bool function, causes problem with std::bind. - const auto bouncer = - [self = shared_from_this(), handler = BOUND_PROTOCOL(method, args)] + const auto bouncer = [self = shared_from_this(), + handler = BIND_SHARED(method, args)] (const auto& ec, const typename Message::cptr& message, auto id) { return self->handle_broadcast(ec, message, id, handler); @@ -229,42 +224,12 @@ class BCT_API protocol bool started_{}; }; -#undef BOUND_PROTOCOL - -// See define.hpp for BIND# macros. - -#define POST1(method, p1) \ - post(&CLASS::method, p1) -#define POST2(method, p1, p2) \ - post(&CLASS::method, p1, p2) -#define POST3(method, p1, p2, p3) \ - post(&CLASS::method, p1, p2, p3) - -#define SEND1(message, method, p1) \ - send(message, &CLASS::method, p1) -#define SEND2(message, method, p1, p2) \ - send(message, &CLASS::method, p1, p2) -#define SEND3(message, method, p1, p2, p3) \ - send(message, &CLASS::method, p1, p2, p3) - -#define SUBSCRIBE_CHANNEL1(message, method, p1) \ - subscribe_channel(&CLASS::method, p1) -#define SUBSCRIBE_CHANNEL2(message, method, p1, p2) \ - subscribe_channel(&CLASS::method, p1, p2) -#define SUBSCRIBE_CHANNEL3(message, method, p1, p2, p3) \ - subscribe_channel(&CLASS::method, p1, p2, p3) -#define SUBSCRIBE_CHANNEL4(message, method, p1, p2, p3, p4) \ - subscribe_channel(&CLASS::method, p1, p2, p3, p4) - -////#define SUBSCRIBE_BROADCAST1(message, method, p1) \ -//// subscribe_broadcast(&CLASS::method, p1) -////#define SUBSCRIBE_BROADCAST2(message, method, p1, p2) \ -//// subscribe_broadcast(&CLASS::method, p1, p2) -#define SUBSCRIBE_BROADCAST3(message, method, p1, p2, p3) \ - subscribe_broadcast(&CLASS::method, p1, p2, p3) -#define SUBSCRIBE_BROADCAST4(message, method, p1, p2, p3, p4) \ - subscribe_broadcast(&CLASS::method, p1, p2, p3, p4) - +#define SEND(message, method, ...) \ + send(message, &CLASS::method, __VA_ARGS__) +#define SUBSCRIBE_CHANNEL(message, method, ...) \ + subscribe_channel(&CLASS::method, __VA_ARGS__) +#define SUBSCRIBE_BROADCAST(message, method, ...) \ + subscribe_broadcast(&CLASS::method, __VA_ARGS__) #define BROADCAST(message, ptr) broadcast(ptr) } // namespace network diff --git a/include/bitcoin/network/sessions/session.hpp b/include/bitcoin/network/sessions/session.hpp index 192540bf3..093a93f40 100644 --- a/include/bitcoin/network/sessions/session.hpp +++ b/include/bitcoin/network/sessions/session.hpp @@ -47,11 +47,10 @@ class BCT_API session protected: /// Bind a method in the base or derived class (use BIND#). - template + template auto bind(Method&& method, Args&&... args) NOEXCEPT { - return std::bind(std::forward(method), - shared_from_base(), std::forward(args)...); + return BIND_SHARED(method, args); } private: @@ -87,15 +86,11 @@ class BCT_API session template > void subscribe(Handler&& handler, channel_id id) NOEXCEPT { - // Handler is a bool function, causes problem with std::bind. - const auto bouncer = - [self = shared_from_this(), handler = std::move(handler), id]() + const auto bouncer = [self = shared_from_this(), + handler = std::move(handler), id]() { self->do_subscribe(handler, id); }; - - // Subscribe on network strand (protects broadcaster). - boost::asio::post(strand(), bouncer); } template @@ -103,13 +98,13 @@ class BCT_API session channel_id sender) NOEXCEPT { boost::asio::post(strand(), - BIND2(do_broadcast, message, sender)); + BIND(do_broadcast, message, sender)); } virtual void unsubscribe(channel_id subscriber) NOEXCEPT { boost::asio::post(strand(), - BIND1(do_unsubscribe, subscriber)); + BIND(do_unsubscribe, subscriber)); } /// Start/stop. diff --git a/src/protocols/protocol.cpp b/src/protocols/protocol.cpp index 3c42e39b6..61e339e1c 100644 --- a/src/protocols/protocol.cpp +++ b/src/protocols/protocol.cpp @@ -186,7 +186,7 @@ size_t protocol::address_count() const NOEXCEPT void protocol::fetch(address_handler&& handler) NOEXCEPT { session_.fetch( - BIND3(handle_fetch, _1, _2, std::move(handler))); + BIND(handle_fetch, _1, _2, std::move(handler))); } void protocol::handle_fetch(const code& ec, const address_cptr& message, @@ -201,7 +201,7 @@ void protocol::save(const address_cptr& message, count_handler&& handler) NOEXCEPT { session_.save(message, - BIND3(handle_save, _1, _2, std::move(handler))); + BIND(handle_save, _1, _2, std::move(handler))); } void protocol::handle_save(const code& ec, size_t accepted, diff --git a/src/protocols/protocol_address_in_31402.cpp b/src/protocols/protocol_address_in_31402.cpp index 83a6ee282..c1be38c36 100644 --- a/src/protocols/protocol_address_in_31402.cpp +++ b/src/protocols/protocol_address_in_31402.cpp @@ -59,12 +59,12 @@ void protocol_address_in_31402::start() NOEXCEPT return; // Always allow a singleton unrequested address (advertisement). - SUBSCRIBE_CHANNEL2(address, handle_receive_address, _1, _2); + SUBSCRIBE_CHANNEL(address, handle_receive_address, _1, _2); // Do not request addresses from inbound channels. if (outbound_) { - SEND1(get_address{}, handle_send, _1); + SEND(get_address{}, handle_send, _1); } protocol::start(); @@ -147,7 +147,7 @@ bool protocol_address_in_31402::handle_receive_address(const code& ec, // This allows previously-rejected addresses. save(filtered, - BIND4(handle_save_address, _1, _2, end_size, start_size)); + BIND(handle_save_address, _1, _2, end_size, start_size)); return true; } diff --git a/src/protocols/protocol_address_out_31402.cpp b/src/protocols/protocol_address_out_31402.cpp index 4a310ed5f..65e3d2de9 100644 --- a/src/protocols/protocol_address_out_31402.cpp +++ b/src/protocols/protocol_address_out_31402.cpp @@ -58,10 +58,10 @@ void protocol_address_out_31402::start() NOEXCEPT // Advertise self if configured for inbound and with self address(es). if (settings().advertise_enabled()) { - SEND1(selfs(), handle_send, _1); + SEND(selfs(), handle_send, _1); } - SUBSCRIBE_CHANNEL2(get_address, handle_receive_get_address, _1, _2); + SUBSCRIBE_CHANNEL(get_address, handle_receive_get_address, _1, _2); protocol::start(); } @@ -84,11 +84,11 @@ bool protocol_address_out_31402::handle_receive_get_address(const code& ec, return true; } - fetch(BIND2(handle_fetch_address, _1, _2)); + fetch(BIND(handle_fetch_address, _1, _2)); sent_ = true; LOGP("Relay start [" << authority() << "]."); - SUBSCRIBE_BROADCAST3(address, handle_broadcast_address, _1, _2, _3); + SUBSCRIBE_BROADCAST(address, handle_broadcast_address, _1, _2, _3); return true; } @@ -107,7 +107,7 @@ void protocol_address_out_31402::handle_fetch_address(const code& ec, LOGP("Sending (" << message->addresses.size() << ") addresses to " "[" << authority() << "]"); - SEND1(*message, handle_send, _1); + SEND(*message, handle_send, _1); } // ---------------------------------------------------------------------------- @@ -132,7 +132,7 @@ bool protocol_address_out_31402::handle_broadcast_address(const code& ec, LOGP("Relay (" << message->addresses.size() << ") addresses to [" << authority() << "]."); - SEND1(*message, handle_send, _1); + SEND(*message, handle_send, _1); return true; } diff --git a/src/protocols/protocol_alert_31402.cpp b/src/protocols/protocol_alert_31402.cpp index c81c52957..32a1c947a 100644 --- a/src/protocols/protocol_alert_31402.cpp +++ b/src/protocols/protocol_alert_31402.cpp @@ -53,7 +53,7 @@ void protocol_alert_31402::start() NOEXCEPT if (started()) return; - SUBSCRIBE_CHANNEL2(alert, handle_receive_alert, _1, _2); + SUBSCRIBE_CHANNEL(alert, handle_receive_alert, _1, _2); protocol::start(); } diff --git a/src/protocols/protocol_ping_31402.cpp b/src/protocols/protocol_ping_31402.cpp index ac5bf230e..408ee266b 100644 --- a/src/protocols/protocol_ping_31402.cpp +++ b/src/protocols/protocol_ping_31402.cpp @@ -52,7 +52,7 @@ void protocol_ping_31402::start() NOEXCEPT if (started()) return; - SUBSCRIBE_CHANNEL2(ping, handle_receive_ping, _1, _2); + SUBSCRIBE_CHANNEL(ping, handle_receive_ping, _1, _2); send_ping(); protocol::start(); @@ -71,7 +71,7 @@ void protocol_ping_31402::stopping(const code&) NOEXCEPT void protocol_ping_31402::send_ping() NOEXCEPT { - SEND1(ping{}, handle_send_ping, _1); + SEND(ping{}, handle_send_ping, _1); } // Also invoked by protocol_ping_31402. @@ -82,7 +82,7 @@ void protocol_ping_31402::handle_send_ping(const code& ec) NOEXCEPT if (stopped(ec)) return; - timer_->start(BIND1(handle_timer, _1)); + timer_->start(BIND(handle_timer, _1)); protocol::handle_send(ec); } diff --git a/src/protocols/protocol_ping_60001.cpp b/src/protocols/protocol_ping_60001.cpp index 709c2946b..ba119cabc 100644 --- a/src/protocols/protocol_ping_60001.cpp +++ b/src/protocols/protocol_ping_60001.cpp @@ -53,8 +53,8 @@ void protocol_ping_60001::start() NOEXCEPT if (started()) return; - SUBSCRIBE_CHANNEL2(pong, handle_receive_pong, _1, _2); - ////SUBSCRIBE_CHANNEL2(ping, handle_receive_ping, _1, _2); + SUBSCRIBE_CHANNEL(pong, handle_receive_pong, _1, _2); + ////SUBSCRIBE_CHANNEL(ping, handle_receive_ping, _1, _2); ////send_ping(); protocol_ping_31402::start(); @@ -79,7 +79,7 @@ void protocol_ping_60001::send_ping() NOEXCEPT // The ping/pong nonce is arbitrary and distinct from the channel nonce. nonce_ = pseudo_random::next(add1(minimum_nonce), bc::max_int64); - SEND1(ping{ nonce_ }, handle_send, _1); + SEND(ping{ nonce_ }, handle_send, _1); } ////void protocol_ping_31402::handle_send_ping(const code& ec) NOEXCEPT @@ -89,7 +89,7 @@ void protocol_ping_60001::send_ping() NOEXCEPT //// if (stopped(ec)) //// return; //// -//// timer_->start(BIND1(handle_timer, _1)); +//// timer_->start(BIND(handle_timer, _1)); //// protocol::handle_send(ec); ////} @@ -152,7 +152,7 @@ bool protocol_ping_60001::handle_receive_ping(const code& ec, if (stopped(ec)) return false; - SEND1(pong{ message->nonce }, handle_send_pong, _1); + SEND(pong{ message->nonce }, handle_send_pong, _1); return true; } diff --git a/src/protocols/protocol_reject_70002.cpp b/src/protocols/protocol_reject_70002.cpp index f59d03226..e08ac4dcb 100644 --- a/src/protocols/protocol_reject_70002.cpp +++ b/src/protocols/protocol_reject_70002.cpp @@ -53,7 +53,7 @@ void protocol_reject_70002::start() NOEXCEPT if (started()) return; - SUBSCRIBE_CHANNEL2(reject, handle_receive_reject, _1, _2); + SUBSCRIBE_CHANNEL(reject, handle_receive_reject, _1, _2); protocol::start(); } diff --git a/src/protocols/protocol_seed_31402.cpp b/src/protocols/protocol_seed_31402.cpp index 2adb7eac2..f5f1ab1a6 100644 --- a/src/protocols/protocol_seed_31402.cpp +++ b/src/protocols/protocol_seed_31402.cpp @@ -59,9 +59,9 @@ void protocol_seed_31402::start() NOEXCEPT if (started()) return; - SUBSCRIBE_CHANNEL2(address, handle_receive_address, _1, _2); - SUBSCRIBE_CHANNEL2(get_address, handle_receive_get_address, _1, _2); - SEND1(get_address{}, handle_send_get_address, _1); + SUBSCRIBE_CHANNEL(address, handle_receive_address, _1, _2); + SUBSCRIBE_CHANNEL(get_address, handle_receive_get_address, _1, _2); + SEND(get_address{}, handle_send_get_address, _1); protocol::start(); } @@ -107,7 +107,7 @@ void protocol_seed_31402::handle_send_get_address(const code& ec) NOEXCEPT if (stopped(ec)) return; - timer_->start(BIND1(handle_timer, _1)); + timer_->start(BIND(handle_timer, _1)); sent_get_address_ = true; if (complete()) @@ -168,7 +168,7 @@ bool protocol_seed_31402::handle_receive_address(const code& ec, const auto end_size = filtered->addresses.size(); save(filtered, - BIND4(handle_save_addresses, _1, _2, end_size, start_size)); + BIND(handle_save_addresses, _1, _2, end_size, start_size)); return true; } @@ -212,7 +212,7 @@ bool protocol_seed_31402::handle_receive_get_address(const code& ec, // Advertise self if configured for inbound and with self address(es). if (settings().advertise_enabled()) { - SEND1(selfs(), handle_send_address, _1); + SEND(selfs(), handle_send_address, _1); } // handle_send_address has been bypassed, so completion here. diff --git a/src/protocols/protocol_version_31402.cpp b/src/protocols/protocol_version_31402.cpp index 5a30cfdf7..eb78f659e 100644 --- a/src/protocols/protocol_version_31402.cpp +++ b/src/protocols/protocol_version_31402.cpp @@ -166,9 +166,9 @@ void protocol_version_31402::shake(result_handler&& handler) NOEXCEPT return; } - SUBSCRIBE_CHANNEL2(version, handle_receive_version, _1, _2); - SUBSCRIBE_CHANNEL2(version_acknowledge, handle_receive_acknowledge, _1, _2); - SEND1(version_factory(), handle_send_version, _1); + SUBSCRIBE_CHANNEL(version, handle_receive_version, _1, _2); + SUBSCRIBE_CHANNEL(version_acknowledge, handle_receive_acknowledge, _1, _2); + SEND(version_factory(), handle_send_version, _1); protocol::start(); } @@ -235,7 +235,7 @@ void protocol_version_31402::handle_send_version(const code& ec) NOEXCEPT if (stopped(ec)) return; - timer_->start(BIND1(handle_timer, _1)); + timer_->start(BIND(handle_timer, _1)); sent_version_ = true; if (complete()) @@ -332,7 +332,7 @@ bool protocol_version_31402::handle_receive_version(const code& ec, //// << "as {" << config::authority(message->address_sender) << "} " //// << "us {" << config::authority(message->address_receiver) << "}."); - SEND1(version_acknowledge{}, handle_send_acknowledge, _1); + SEND(version_acknowledge{}, handle_send_acknowledge, _1); // Handle in handle_send_acknowledge. received_version_ = true; diff --git a/src/protocols/protocol_version_70002.cpp b/src/protocols/protocol_version_70002.cpp index 5a8591c66..371bc3276 100644 --- a/src/protocols/protocol_version_70002.cpp +++ b/src/protocols/protocol_version_70002.cpp @@ -67,7 +67,7 @@ void protocol_version_70002::shake(result_handler&& handle_event) NOEXCEPT if (started()) return; - SUBSCRIBE_CHANNEL2(reject, handle_receive_reject, _1, _2); + SUBSCRIBE_CHANNEL(reject, handle_receive_reject, _1, _2); protocol_version_70001::shake(std::move(handle_event)); } @@ -82,17 +82,17 @@ void protocol_version_70002::rejection(const code& ec) NOEXCEPT // Handshake completion may result before completion of this send (okay). if (ec == error::peer_insufficient) { - SEND1((reject{ version::command, reject::reason_code::obsolete }), + SEND((reject{ version::command, reject::reason_code::obsolete }), handle_send, _1); } else if (ec == error::peer_unsupported) { - SEND1((reject{ version::command, reject::reason_code::nonstandard }), + SEND((reject{ version::command, reject::reason_code::nonstandard }), handle_send, _1); } else if (ec == error::protocol_violation) { - SEND1((reject{ version::command, reject::reason_code::duplicate }), + SEND((reject{ version::command, reject::reason_code::duplicate }), handle_send, _1); } diff --git a/src/sessions/session.cpp b/src/sessions/session.cpp index 4c35f3393..052269f57 100644 --- a/src/sessions/session.cpp +++ b/src/sessions/session.cpp @@ -119,16 +119,16 @@ void session::start_channel(const channel::ptr& channel, pend(channel); result_handler start = - BIND4(handle_channel_start, _1, channel, std::move(starter), + BIND(handle_channel_start, _1, channel, std::move(starter), std::move(stopper)); result_handler shake = - BIND3(handle_handshake, _1, channel, std::move(start)); + BIND(handle_handshake, _1, channel, std::move(start)); // Switch to channel context. // Channel/network strands share same pool. boost::asio::post(channel->strand(), - BIND2(do_attach_handshake, channel, std::move(shake))); + BIND(do_attach_handshake, channel, std::move(shake))); } void session::do_attach_handshake(const channel::ptr& channel, @@ -179,7 +179,7 @@ void session::handle_handshake(const code& ec, const channel::ptr& channel, // Return to network context. boost::asio::post(network_.strand(), - BIND3(do_handle_handshake, ec, channel, start)); + BIND(do_handle_handshake, ec, channel, start)); } void session::do_handle_handshake(const code& ec, const channel::ptr& channel, @@ -223,8 +223,8 @@ void session::handle_channel_start(const code& ec, const channel::ptr& channel, } channel->subscribe_stop( - BIND3(handle_channel_stopped, _1, channel, stopped), - BIND3(handle_channel_started, _1, channel, started)); + BIND(handle_channel_stopped, _1, channel, stopped), + BIND(handle_channel_started, _1, channel, started)); } void session::handle_channel_started(const code& ec, @@ -234,7 +234,7 @@ void session::handle_channel_started(const code& ec, // Return to network context. boost::asio::post(network_.strand(), - BIND3(do_handle_channel_started, ec, channel, started)); + BIND(do_handle_channel_started, ec, channel, started)); } void session::do_handle_channel_started(const code& ec, @@ -251,7 +251,7 @@ void session::do_handle_channel_started(const code& ec, // Switch to channel context (started is invoked on network strand). boost::asio::post(channel->strand(), - BIND2(do_attach_protocols, channel, started)); + BIND(do_attach_protocols, channel, started)); } void session::do_attach_protocols(const channel::ptr& channel, @@ -317,7 +317,7 @@ void session::handle_channel_stopped(const code& ec, // Return to network context. boost::asio::post(network_.strand(), - BIND3(do_handle_channel_stopped, ec, channel, stopped)); + BIND(do_handle_channel_stopped, ec, channel, stopped)); } // Unnonce in stop vs. handshake to avoid loopback race (in/out same strand). @@ -360,10 +360,10 @@ void session::defer(const steady_clock::duration& timeout, const auto timer = std::make_shared(log, network_.strand()); timer->start( - BIND3(handle_timer, _1, key, std::move(handler)), timeout); + BIND(handle_timer, _1, key, std::move(handler)), timeout); stop_subscriber_.subscribe( - BIND3(handle_defer, _1, key, timer), key); + BIND(handle_defer, _1, key, timer), key); } void session::handle_timer(const code& ec, object_key key, @@ -385,7 +385,7 @@ bool session::handle_defer(const code&, object_key, void session::pend(const channel::ptr& channel) NOEXCEPT { BC_ASSERT_MSG(stranded(), "strand"); - stop_subscriber_.subscribe(BIND2(handle_pend, _1, channel), + stop_subscriber_.subscribe(BIND(handle_pend, _1, channel), channel->identifier()); } diff --git a/src/sessions/session_inbound.cpp b/src/sessions/session_inbound.cpp index e36588e39..1e107cce7 100644 --- a/src/sessions/session_inbound.cpp +++ b/src/sessions/session_inbound.cpp @@ -59,7 +59,7 @@ void session_inbound::start(result_handler&& handler) NOEXCEPT return; } - session::start(BIND2(handle_started, _1, std::move(handler))); + session::start(BIND(handle_started, _1, std::move(handler))); } void session_inbound::handle_started(const code& ec, @@ -117,7 +117,7 @@ void session_inbound::start_accept(const code&, if (stopped()) return; - acceptor->accept(BIND3(handle_accept, _1, _2, acceptor)); + acceptor->accept(BIND(handle_accept, _1, _2, acceptor)); } void session_inbound::handle_accept(const code& ec, @@ -137,7 +137,7 @@ void session_inbound::handle_accept(const code& ec, { BC_ASSERT_MSG(!socket || socket->stopped(), "unexpected socket"); LOGF("Failed to accept inbound connection, " << ec.message()); - defer(BIND2(start_accept, _1, acceptor)); + defer(BIND(start_accept, _1, acceptor)); return; } @@ -174,8 +174,8 @@ void session_inbound::handle_accept(const code& ec, << acceptor->local() << "]."); start_channel(channel, - BIND2(handle_channel_start, _1, channel), - BIND2(handle_channel_stop, _1, channel)); + BIND(handle_channel_start, _1, channel), + BIND(handle_channel_stop, _1, channel)); } bool session_inbound::blacklisted(const config::address& address) const NOEXCEPT diff --git a/src/sessions/session_manual.cpp b/src/sessions/session_manual.cpp index 2fa4bc22b..274831128 100644 --- a/src/sessions/session_manual.cpp +++ b/src/sessions/session_manual.cpp @@ -54,7 +54,7 @@ session_manual::session_manual(p2p& network, uint64_t identifier) NOEXCEPT void session_manual::start(result_handler&& handler) NOEXCEPT { BC_ASSERT_MSG(stranded(), "strand"); - session::start(BIND2(handle_started, _1, std::move(handler))); + session::start(BIND(handle_started, _1, std::move(handler))); } void session_manual::handle_started(const code& ec, @@ -113,7 +113,7 @@ void session_manual::start_connect(const code&, const endpoint& peer, } connector->connect(peer, - BIND5(handle_connect, _1, _2, peer, connector, handler)); + BIND(handle_connect, _1, _2, peer, connector, handler)); } void session_manual::handle_connect(const code& ec, const socket::ptr& socket, @@ -145,7 +145,7 @@ void session_manual::handle_connect(const code& ec, const socket::ptr& socket, } // Avoid tight loop with delay timer. - defer(BIND4(start_connect, _1, peer, connector, handler)); + defer(BIND(start_connect, _1, peer, connector, handler)); return; } @@ -153,8 +153,8 @@ void session_manual::handle_connect(const code& ec, const socket::ptr& socket, // It is possible for start_channel to directly invoke the handlers. start_channel(channel, - BIND4(handle_channel_start, _1, channel, peer, handler), - BIND5(handle_channel_stop, _1, channel, peer, connector, handler)); + BIND(handle_channel_start, _1, channel, peer, handler), + BIND(handle_channel_stop, _1, channel, peer, connector, handler)); } void session_manual::attach_handshake(const channel::ptr& channel, diff --git a/src/sessions/session_outbound.cpp b/src/sessions/session_outbound.cpp index a7a3a2856..c2f73a8bf 100644 --- a/src/sessions/session_outbound.cpp +++ b/src/sessions/session_outbound.cpp @@ -77,7 +77,7 @@ void session_outbound::start(result_handler&& handler) NOEXCEPT LOGN("Address protocol disabled, may cause empty address pool."); } - session::start(BIND2(handle_started, _1, std::move(handler))); + session::start(BIND(handle_started, _1, std::move(handler))); } void session_outbound::handle_started(const code& ec, @@ -134,11 +134,11 @@ void session_outbound::start_connect(const code&) NOEXCEPT BC_POP_WARNING() // Race to first success or last failure. - racer->start(BIND3(handle_connect, _1, _2, key)); + racer->start(BIND(handle_connect, _1, _2, key)); // Attempt to connect with unique address for each connector of batch. for (const auto& connector: *connectors) - take(BIND5(do_one, _1, _2, key, racer, connector)); + take(BIND(do_one, _1, _2, key, racer, connector)); } // Attempt to connect the given peer and invoke handle_one. @@ -159,12 +159,12 @@ void session_outbound::do_one(const code& ec, const config::address& peer, // Guard restartable connector (shutdown delay). if (stopped()) { - restore(peer, BIND1(handle_reclaim, _1)); + restore(peer, BIND(handle_reclaim, _1)); racer->finish(error::service_stopped, nullptr); return; } - connector->connect(peer, BIND4(handle_one, _1, _2, key, racer)); + connector->connect(peer, BIND(handle_one, _1, _2, key, racer)); } // Handle each do_one connection attempt, stopping on first success. @@ -206,7 +206,7 @@ void session_outbound::handle_connect(const code& ec, if (ec == error::address_not_found) { LOGS("Address pool is empty."); - defer(settings().connect_timeout(), BIND1(start_connect, _1)); + defer(settings().connect_timeout(), BIND(start_connect, _1)); return; } @@ -214,15 +214,15 @@ void session_outbound::handle_connect(const code& ec, if (ec) { // Avoid tight loop with delay timer. - defer(BIND1(start_connect, _1)); + defer(BIND(start_connect, _1)); return; } const auto channel = create_channel(socket, false); start_channel(channel, - BIND2(handle_channel_start, _1, channel), - BIND2(handle_channel_stop, _1, channel)); + BIND(handle_channel_start, _1, channel), + BIND(handle_channel_stop, _1, channel)); } void session_outbound::attach_handshake(const channel::ptr& channel, @@ -296,7 +296,7 @@ void session_outbound::reclaim(const code& ec, if (stopped() || always_reclaim(ec) || maybe_reclaim(ec)) { - restore(socket->address(), BIND1(handle_reclaim, _1)); + restore(socket->address(), BIND(handle_reclaim, _1)); } } @@ -312,7 +312,7 @@ void session_outbound::reclaim(const code& ec, if (stopped() || always_reclaim(ec) || maybe_reclaim(ec)) { - restore(channel->get_updated_address(), BIND1(handle_reclaim, _1)); + restore(channel->get_updated_address(), BIND(handle_reclaim, _1)); } } diff --git a/src/sessions/session_seed.cpp b/src/sessions/session_seed.cpp index 29e9eb74b..d63e52c0f 100644 --- a/src/sessions/session_seed.cpp +++ b/src/sessions/session_seed.cpp @@ -91,7 +91,7 @@ void session_seed::start(result_handler&& handler) NOEXCEPT return; } - session::start(BIND2(handle_started, _1, std::move(handler))); + session::start(BIND(handle_started, _1, std::move(handler))); } void session_seed::handle_started(const code& ec, @@ -118,7 +118,7 @@ void session_seed::handle_started(const code& ec, BC_POP_WARNING() // Invoke sufficient on count, invoke complete with all seeds stopped. - racer->start(move_copy(handler), BIND1(stop_seed, _1)); + racer->start(move_copy(handler), BIND(stop_seed, _1)); for (const auto& seed: settings().seeds) { @@ -130,7 +130,7 @@ void session_seed::handle_started(const code& ec, }); start_seed(error::success, seed, connector, - BIND4(handle_connect, _1, _2, seed, racer)); + BIND(handle_connect, _1, _2, seed, racer)); } } @@ -170,8 +170,8 @@ void session_seed::handle_connect(const code& ec, const socket::ptr& socket, const auto channel = create_channel(socket, true); start_channel(channel, - BIND2(handle_channel_start, _1, channel), - BIND3(handle_channel_stop, _1, channel, racer)); + BIND(handle_channel_start, _1, channel), + BIND(handle_channel_stop, _1, channel, racer)); } void session_seed::attach_handshake(const channel::ptr& channel,