mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
updates transport accept loop to use connection_hdl and not be a template function
This commit is contained in:
@@ -256,14 +256,13 @@ void connection<config>::close(const close::status::value code,
|
||||
template <typename config>
|
||||
lib::error_code connection<config>::interrupt() {
|
||||
std::cout << "connection::interrupt" << std::endl;
|
||||
return transport_type::inturrupt(
|
||||
/*return transport_type::inturrupt(
|
||||
lib::bind(
|
||||
&type::handle_inturrupt,
|
||||
type::shared_from_this(),
|
||||
lib::placeholders::_1
|
||||
type::shared_from_this()
|
||||
)
|
||||
);
|
||||
//return lib::error_code();
|
||||
);*/
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +72,9 @@ public:
|
||||
typedef typename base::handler_ptr handler_ptr;
|
||||
|
||||
typedef typename base::connection_ptr connection_ptr;
|
||||
|
||||
typedef typename transport_type::con_policy trans_connection_type;
|
||||
typedef typename transport_type::trans_connection_ptr trans_connection_ptr;
|
||||
|
||||
explicit server(typename base::handler_ptr default_handler)
|
||||
: base(default_handler,true)
|
||||
{
|
||||
@@ -92,20 +94,32 @@ public:
|
||||
void start_accept() {
|
||||
connection_ptr con = get_connection();
|
||||
|
||||
transport_type::template async_accept<connection_ptr>(
|
||||
con,
|
||||
transport_type::async_accept(
|
||||
lib::static_pointer_cast<trans_connection_type>(con),
|
||||
lib::bind(
|
||||
&type::handle_accept,
|
||||
this,
|
||||
lib::placeholders::_1
|
||||
lib::placeholders::_1,
|
||||
lib::placeholders::_2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void handle_accept(const lib::error_code& ec) {
|
||||
if (ec) {
|
||||
std::cout << "handle_accept: error: " << ec << std::endl;
|
||||
}
|
||||
void handle_accept(connection_hdl hdl, const lib::error_code& ec) {
|
||||
connection_ptr con = base::get_con_from_hdl(hdl);
|
||||
|
||||
if (!con) {
|
||||
// TODO: should this be considered a server fatal error?
|
||||
std::cout << "handle_accept got an invalid handle back" << std::endl;
|
||||
} else {
|
||||
if (ec) {
|
||||
con->terminate();
|
||||
|
||||
std::cout << "handle_accept: error: " << ec << std::endl;
|
||||
} else {
|
||||
con->start();
|
||||
}
|
||||
}
|
||||
|
||||
start_accept();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,9 @@ public:
|
||||
//typedef lib::shared_ptr<boost::asio::io_service> io_service_ptr;
|
||||
typedef boost::asio::io_service* io_service_ptr;
|
||||
typedef lib::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor_ptr;
|
||||
|
||||
|
||||
typedef typename con_policy::ptr trans_connection_ptr;
|
||||
|
||||
// generate and manage our own io_service
|
||||
explicit endpoint()
|
||||
: m_external_io_service(false)
|
||||
@@ -186,8 +188,7 @@ public:
|
||||
|
||||
// Accept the next connection attempt via m_acceptor and assign it to con.
|
||||
// callback is called
|
||||
template <typename connection_ptr>
|
||||
void async_accept(connection_ptr con, accept_handler callback) {
|
||||
void async_accept(trans_connection_ptr tcon, accept_handler callback) {
|
||||
if (m_state != LISTENING) {
|
||||
// TODO: throw invalid state
|
||||
std::cout << "asio::async_accept called from the wrong state" << std::endl;
|
||||
@@ -198,11 +199,11 @@ public:
|
||||
|
||||
// TEMP
|
||||
m_acceptor->async_accept(
|
||||
con->get_raw_socket(),
|
||||
tcon->get_raw_socket(),
|
||||
lib::bind(
|
||||
&type::handle_accept<connection_ptr>,
|
||||
&type::handle_accept,
|
||||
this,
|
||||
con,
|
||||
tcon->get_handle(),
|
||||
callback,
|
||||
lib::placeholders::_1
|
||||
)
|
||||
@@ -251,16 +252,17 @@ public:
|
||||
listen(*endpoint_iterator);
|
||||
}
|
||||
protected:
|
||||
template <typename connection_ptr>
|
||||
void handle_accept(connection_ptr con, accept_handler callback, const boost::system::error_code& error) {
|
||||
void handle_accept(connection_hdl hdl, accept_handler callback,
|
||||
const boost::system::error_code& error)
|
||||
{
|
||||
if (error) {
|
||||
con->terminate();
|
||||
//con->terminate();
|
||||
// TODO: Better translation of errors at this point
|
||||
callback(make_error_code(error::pass_through));
|
||||
callback(hdl,make_error_code(error::pass_through));
|
||||
}
|
||||
|
||||
con->start();
|
||||
callback(lib::error_code());
|
||||
//con->start();
|
||||
callback(hdl,lib::error_code());
|
||||
}
|
||||
|
||||
bool is_listening() const {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
#include <websocketpp/common/functional.hpp>
|
||||
#include <websocketpp/common/system_error.hpp>
|
||||
#include <websocketpp/common/connection_hdl.hpp>
|
||||
|
||||
namespace websocketpp {
|
||||
namespace transport {
|
||||
@@ -57,7 +58,7 @@ namespace transport {
|
||||
*/
|
||||
|
||||
// Endpoint callbacks
|
||||
typedef lib::function<void(const lib::error_code&)> accept_handler;
|
||||
typedef lib::function<void(connection_hdl,const lib::error_code&)> accept_handler;
|
||||
|
||||
typedef lib::function<void()> endpoint_lock;
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ template <typename concurrency>
|
||||
class endpoint {
|
||||
public:
|
||||
typedef iostream::connection<concurrency> con_policy;
|
||||
|
||||
typedef typename con_policy::ptr trans_connection_ptr;
|
||||
|
||||
// generate and manage our own io_service
|
||||
explicit endpoint()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user