Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

rpc: fix pegasus-186 #169

Merged
merged 2 commits into from
Oct 10, 2018
Merged
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
47 changes: 28 additions & 19 deletions src/core/tools/common/asio_net_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ error_code asio_network_provider::start(rpc_channel channel, int port, bool clie
task_worker::set_name(buffer);

boost::asio::io_service::work work(_io_service);
_io_service.run();
boost::system::error_code ec;
_io_service.run(ec);
dassert(false, "boost::asio::io_service run failed: err(%s)", ec.message().data());
})));
}

Expand Down Expand Up @@ -127,21 +129,26 @@ void asio_network_provider::do_accept()

_acceptor->async_accept(*socket, [this, socket](boost::system::error_code ec) {
if (!ec) {
auto ip = socket->remote_endpoint().address().to_v4().to_ulong();
auto port = socket->remote_endpoint().port();
::dsn::rpc_address client_addr(ip, port);

message_parser_ptr null_parser;
rpc_session_ptr s =
new asio_rpc_session(*this,
client_addr,
(std::shared_ptr<boost::asio::ip::tcp::socket> &)socket,
null_parser,
false);
on_server_session_accepted(s);

// we should start read immediately after the rpc session is completely created.
s->start_read_next();
auto remote = socket->remote_endpoint(ec);
if (ec) {
derror("failed to get the remote endpoint: %s", ec.message().data());
} else {
auto ip = remote.address().to_v4().to_ulong();
auto port = remote.port();
::dsn::rpc_address client_addr(ip, port);

message_parser_ptr null_parser;
rpc_session_ptr s =
new asio_rpc_session(*this,
client_addr,
(std::shared_ptr<boost::asio::ip::tcp::socket> &)socket,
null_parser,
false);
on_server_session_accepted(s);

// we should start read immediately after the rpc session is completely created.
s->start_read_next();
}
}

do_accept();
Expand Down Expand Up @@ -295,8 +302,8 @@ error_code asio_udp_provider::start(rpc_channel channel, int port, bool client_o
// refactored
_address.assign_ipv4(get_local_ipv4(),
std::numeric_limits<uint16_t>::max() -
rand::next_u64(std::numeric_limits<uint64_t>::min(),
std::numeric_limits<uint64_t>::max()) %
rand::next_u64(std::numeric_limits<uint64_t>::min(),
std::numeric_limits<uint64_t>::max()) %
5000);
::boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address_v4::any(),
_address.port());
Expand Down Expand Up @@ -350,7 +357,9 @@ error_code asio_udp_provider::start(rpc_channel channel, int port, bool client_o
task_worker::set_name(buffer);

boost::asio::io_service::work work(_io_service);
_io_service.run();
boost::system::error_code ec;
_io_service.run(ec);
dassert(false, "boost::asio::io_service run failed: err(%s)", ec.message().data());
})));
}

Expand Down