mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
additional support for compile time disabling of multithreading features
This commit is contained in:
@@ -95,6 +95,8 @@ struct config {
|
||||
typedef websocketpp::http::parser::response response_type;
|
||||
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
|
||||
|
||||
static const bool enable_multithreading = true;
|
||||
|
||||
static const long timeout_socket_pre_init = 1000;
|
||||
static const long timeout_proxy = 1000;
|
||||
static const long timeout_socket_post_init = 1000;
|
||||
|
||||
@@ -264,15 +264,21 @@ public:
|
||||
)
|
||||
);
|
||||
|
||||
new_timer->async_wait(
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_timer,
|
||||
get_shared(),
|
||||
if (config::enable_multithreading) {
|
||||
new_timer->async_wait(m_strand->wrap(lib::bind(
|
||||
&type::handle_timer, get_shared(),
|
||||
new_timer,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
)));
|
||||
} else {
|
||||
new_timer->async_wait(lib::bind(
|
||||
&type::handle_timer, get_shared(),
|
||||
new_timer,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
));
|
||||
}
|
||||
|
||||
return new_timer;
|
||||
}
|
||||
@@ -379,9 +385,9 @@ protected:
|
||||
// do we need to store or use the io_service at this level?
|
||||
m_io_service = io_service;
|
||||
|
||||
m_strand.reset(new boost::asio::strand(*io_service));
|
||||
|
||||
if (config::enable_multithreading) {
|
||||
m_strand.reset(new boost::asio::strand(*io_service));
|
||||
|
||||
m_async_read_handler = m_strand->wrap(lib::bind(
|
||||
&type::handle_async_read, get_shared(),
|
||||
lib::placeholders::_1, lib::placeholders::_2
|
||||
@@ -523,16 +529,27 @@ protected:
|
||||
);
|
||||
|
||||
// Send proxy request
|
||||
boost::asio::async_write(
|
||||
socket_con_type::get_next_layer(),
|
||||
m_bufs,
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_proxy_write,
|
||||
get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
if (config::enable_multithreading) {
|
||||
boost::asio::async_write(
|
||||
socket_con_type::get_next_layer(),
|
||||
m_bufs,
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_proxy_write, get_shared(),
|
||||
m_init_handler,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
} else {
|
||||
boost::asio::async_write(
|
||||
socket_con_type::get_next_layer(),
|
||||
m_bufs,
|
||||
lib::bind(
|
||||
&type::handle_proxy_write, get_shared(),
|
||||
m_init_handler,
|
||||
lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_proxy_timeout(init_handler callback, const lib::error_code & ec) {
|
||||
@@ -593,18 +610,29 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
boost::asio::async_read_until(
|
||||
socket_con_type::get_next_layer(),
|
||||
m_proxy_data->read_buf,
|
||||
"\r\n\r\n",
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_proxy_read,
|
||||
get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1,
|
||||
lib::placeholders::_2
|
||||
))
|
||||
);
|
||||
if (config::enable_multithreading) {
|
||||
boost::asio::async_read_until(
|
||||
socket_con_type::get_next_layer(),
|
||||
m_proxy_data->read_buf,
|
||||
"\r\n\r\n",
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_proxy_read, get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1, lib::placeholders::_2
|
||||
))
|
||||
);
|
||||
} else {
|
||||
boost::asio::async_read_until(
|
||||
socket_con_type::get_next_layer(),
|
||||
m_proxy_data->read_buf,
|
||||
"\r\n\r\n",
|
||||
lib::bind(
|
||||
&type::handle_proxy_read, get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1, lib::placeholders::_2
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_proxy_read(init_handler callback, const
|
||||
@@ -807,12 +835,20 @@ protected:
|
||||
* This needs to be thread safe
|
||||
*/
|
||||
lib::error_code interrupt(interrupt_handler handler) {
|
||||
m_io_service->post(m_strand->wrap(handler));
|
||||
if (config::enable_multithreading) {
|
||||
m_io_service->post(m_strand->wrap(handler));
|
||||
} else {
|
||||
m_io_service->post(handler);
|
||||
}
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
lib::error_code dispatch(dispatch_handler handler) {
|
||||
m_io_service->post(m_strand->wrap(handler));
|
||||
if (config::enable_multithreading) {
|
||||
m_io_service->post(m_strand->wrap(handler));
|
||||
} else {
|
||||
m_io_service->post(handler);
|
||||
}
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
|
||||
@@ -572,15 +572,27 @@ public:
|
||||
|
||||
m_alog->write(log::alevel::devel, "asio::async_accept");
|
||||
|
||||
m_acceptor->async_accept(
|
||||
tcon->get_raw_socket(),
|
||||
tcon->get_strand()->wrap(lib::bind(
|
||||
&type::handle_accept,
|
||||
this,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
if (config::enable_multithreading) {
|
||||
m_acceptor->async_accept(
|
||||
tcon->get_raw_socket(),
|
||||
tcon->get_strand()->wrap(lib::bind(
|
||||
&type::handle_accept,
|
||||
this,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
} else {
|
||||
m_acceptor->async_accept(
|
||||
tcon->get_raw_socket(),
|
||||
lib::bind(
|
||||
&type::handle_accept,
|
||||
this,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Accept the next connection attempt and assign it to con.
|
||||
@@ -683,18 +695,33 @@ protected:
|
||||
)
|
||||
);
|
||||
|
||||
m_resolver->async_resolve(
|
||||
query,
|
||||
tcon->get_strand()->wrap(lib::bind(
|
||||
&type::handle_resolve,
|
||||
this,
|
||||
tcon,
|
||||
dns_timer,
|
||||
cb,
|
||||
lib::placeholders::_1,
|
||||
lib::placeholders::_2
|
||||
))
|
||||
);
|
||||
if (config::enable_multithreading) {
|
||||
m_resolver->async_resolve(
|
||||
query,
|
||||
tcon->get_strand()->wrap(lib::bind(
|
||||
&type::handle_resolve,
|
||||
this,
|
||||
tcon,
|
||||
dns_timer,
|
||||
cb,
|
||||
lib::placeholders::_1,
|
||||
lib::placeholders::_2
|
||||
))
|
||||
);
|
||||
} else {
|
||||
m_resolver->async_resolve(
|
||||
query,
|
||||
lib::bind(
|
||||
&type::handle_resolve,
|
||||
this,
|
||||
tcon,
|
||||
dns_timer,
|
||||
cb,
|
||||
lib::placeholders::_1,
|
||||
lib::placeholders::_2
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_resolve_timeout(timer_ptr dns_timer, connect_handler callback,
|
||||
@@ -767,18 +794,33 @@ protected:
|
||||
)
|
||||
);
|
||||
|
||||
boost::asio::async_connect(
|
||||
tcon->get_raw_socket(),
|
||||
iterator,
|
||||
tcon->get_strand()->wrap(lib::bind(
|
||||
&type::handle_connect,
|
||||
this,
|
||||
tcon,
|
||||
con_timer,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
if (config::enable_multithreading) {
|
||||
boost::asio::async_connect(
|
||||
tcon->get_raw_socket(),
|
||||
iterator,
|
||||
tcon->get_strand()->wrap(lib::bind(
|
||||
&type::handle_connect,
|
||||
this,
|
||||
tcon,
|
||||
con_timer,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
} else {
|
||||
boost::asio::async_connect(
|
||||
tcon->get_raw_socket(),
|
||||
iterator,
|
||||
lib::bind(
|
||||
&type::handle_connect,
|
||||
this,
|
||||
tcon,
|
||||
con_timer,
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr con_timer,
|
||||
|
||||
@@ -228,15 +228,25 @@ protected:
|
||||
m_ec = socket::make_error_code(socket::error::tls_handshake_timeout);
|
||||
|
||||
// TLS handshake
|
||||
m_socket->async_handshake(
|
||||
get_handshake_type(),
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_init,
|
||||
get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
if (m_strand) {
|
||||
m_socket->async_handshake(
|
||||
get_handshake_type(),
|
||||
m_strand->wrap(lib::bind(
|
||||
&type::handle_init, get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
))
|
||||
);
|
||||
} else {
|
||||
m_socket->async_handshake(
|
||||
get_handshake_type(),
|
||||
lib::bind(
|
||||
&type::handle_init, get_shared(),
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the connection handle
|
||||
|
||||
Reference in New Issue
Block a user