refactor
This commit is contained in:
@@ -98,7 +98,7 @@ struct non_blocking_guard final {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class op_t, class cancel_t>
|
template <class op_t, class cancel_t>
|
||||||
void run_with_deadline(net::io_context &io_ctx, op_t &&operation,
|
void run_with_deadline(boost::asio::io_context &io_ctx, op_t &&operation,
|
||||||
cancel_t &&cancel_op, std::chrono::milliseconds deadline,
|
cancel_t &&cancel_op, std::chrono::milliseconds deadline,
|
||||||
std::string_view timeout_event_tag,
|
std::string_view timeout_event_tag,
|
||||||
std::string_view op_name,
|
std::string_view op_name,
|
||||||
@@ -108,7 +108,7 @@ void run_with_deadline(net::io_context &io_ctx, op_t &&operation,
|
|||||||
bool done = false;
|
bool done = false;
|
||||||
bool timed_out = false;
|
bool timed_out = false;
|
||||||
|
|
||||||
net::steady_timer timer{io_ctx};
|
boost::asio::steady_timer timer{io_ctx};
|
||||||
timer.expires_after(deadline);
|
timer.expires_after(deadline);
|
||||||
timer.async_wait(
|
timer.async_wait(
|
||||||
[&cancel_op, &done, &timed_out](const boost::system::error_code &err_) {
|
[&cancel_op, &done, &timed_out](const boost::system::error_code &err_) {
|
||||||
@@ -141,7 +141,7 @@ void run_with_deadline(net::io_context &io_ctx, op_t &&operation,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void connect_with_deadline(net::io_context &io_ctx,
|
void connect_with_deadline(boost::asio::io_context &io_ctx,
|
||||||
boost::asio::ip::tcp::socket &sock,
|
boost::asio::ip::tcp::socket &sock,
|
||||||
const auto &endpoints,
|
const auto &endpoints,
|
||||||
std::chrono::milliseconds deadline) {
|
std::chrono::milliseconds deadline) {
|
||||||
@@ -150,14 +150,14 @@ void connect_with_deadline(net::io_context &io_ctx,
|
|||||||
run_with_deadline(
|
run_with_deadline(
|
||||||
io_ctx,
|
io_ctx,
|
||||||
[&sock, &endpoints](auto &&handler) {
|
[&sock, &endpoints](auto &&handler) {
|
||||||
net::async_connect(sock, endpoints,
|
boost::asio::async_connect(
|
||||||
[handler](auto &&err, auto &&) { handler(err); });
|
sock, endpoints, [handler](auto &&err, auto &&) { handler(err); });
|
||||||
},
|
},
|
||||||
[&sock]() { sock.cancel(); }, deadline, "connect", "connect",
|
[&sock]() { sock.cancel(); }, deadline, "connect", "connect",
|
||||||
function_name);
|
function_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_exact_with_deadline(net::io_context &io_ctx,
|
void read_exact_with_deadline(boost::asio::io_context &io_ctx,
|
||||||
boost::asio::ip::tcp::socket &sock,
|
boost::asio::ip::tcp::socket &sock,
|
||||||
boost::asio::mutable_buffer buf,
|
boost::asio::mutable_buffer buf,
|
||||||
std::chrono::milliseconds deadline) {
|
std::chrono::milliseconds deadline) {
|
||||||
@@ -175,7 +175,7 @@ void read_exact_with_deadline(net::io_context &io_ctx,
|
|||||||
io_ctx,
|
io_ctx,
|
||||||
[&](auto &&handler) {
|
[&](auto &&handler) {
|
||||||
sock.async_read_some(
|
sock.async_read_some(
|
||||||
net::buffer(base + offset, total - offset),
|
boost::asio::buffer(base + offset, total - offset),
|
||||||
[&bytes_read, handler](auto &&err, auto &&count) {
|
[&bytes_read, handler](auto &&err, auto &&count) {
|
||||||
bytes_read = count;
|
bytes_read = count;
|
||||||
handler(err);
|
handler(err);
|
||||||
@@ -192,7 +192,7 @@ void read_exact_with_deadline(net::io_context &io_ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_all_with_deadline(net::io_context &io_ctx,
|
void write_all_with_deadline(boost::asio::io_context &io_ctx,
|
||||||
boost::asio::ip::tcp::socket &sock,
|
boost::asio::ip::tcp::socket &sock,
|
||||||
boost::asio::mutable_buffer buf,
|
boost::asio::mutable_buffer buf,
|
||||||
std::chrono::milliseconds deadline) {
|
std::chrono::milliseconds deadline) {
|
||||||
@@ -209,7 +209,7 @@ void write_all_with_deadline(net::io_context &io_ctx,
|
|||||||
io_ctx,
|
io_ctx,
|
||||||
[&](auto &&handler) {
|
[&](auto &&handler) {
|
||||||
sock.async_write_some(
|
sock.async_write_some(
|
||||||
net::buffer(base + offset, total - offset),
|
boost::asio::buffer(base + offset, total - offset),
|
||||||
[&bytes_written, handler](auto &&err, auto &&count) {
|
[&bytes_written, handler](auto &&err, auto &&count) {
|
||||||
bytes_written = count;
|
bytes_written = count;
|
||||||
handler(err);
|
handler(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user