mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Updates asio transport components to new styles
This commit is contained in:
@@ -47,20 +47,34 @@ namespace asio {
|
||||
|
||||
typedef lib::function<void(connection_hdl)> tcp_init_handler;
|
||||
|
||||
template <typename security>
|
||||
class connection : public security {
|
||||
/// Boost Asio based connection transport component
|
||||
/**
|
||||
* transport::asio::connection impliments a connection transport component using
|
||||
* Boost ASIO that works with the transport::asio::endpoint endpoint transport
|
||||
* component.
|
||||
*/
|
||||
template <typename socket>
|
||||
class connection : public socket {
|
||||
public:
|
||||
typedef connection<security> type;
|
||||
typedef security security_type;
|
||||
|
||||
/// Type of this connection transport component
|
||||
typedef connection<socket> type;
|
||||
/// Type of a shared pointer to this connection transport component
|
||||
typedef lib::shared_ptr<type> ptr;
|
||||
|
||||
class handler_interface : public security_type::handler_interface {
|
||||
/// Type of the socket connection component
|
||||
typedef socket socket_con_type;
|
||||
/// Type of a shared pointer to the socket connection component
|
||||
typedef typename socket_con_type::ptr socket_con_ptr;
|
||||
|
||||
/// Type of a pointer to the ASIO io_service being used
|
||||
typedef boost::asio::io_service* io_service_ptr;
|
||||
|
||||
// TODO: clean up the rest of these types
|
||||
class handler_interface : public socket_con_type::handler_interface {
|
||||
public:
|
||||
};
|
||||
|
||||
typedef lib::shared_ptr<handler_interface> handler_ptr;
|
||||
typedef boost::asio::io_service* io_service_ptr;
|
||||
|
||||
// generate and manage our own io_service
|
||||
explicit connection(bool is_server)
|
||||
@@ -70,7 +84,7 @@ public:
|
||||
}
|
||||
|
||||
bool is_secure() const {
|
||||
return security::is_secure();
|
||||
return socket_con_type::is_secure();
|
||||
}
|
||||
|
||||
/// Finish constructing the transport
|
||||
@@ -88,7 +102,7 @@ public:
|
||||
|
||||
//m_strand.reset(new boost::asio::strand(*io_service));
|
||||
|
||||
security::init_asio(io_service, m_is_server);
|
||||
socket_con_type::init_asio(io_service, m_is_server);
|
||||
}
|
||||
|
||||
void set_tcp_init_handler(tcp_init_handler h) {
|
||||
@@ -108,7 +122,7 @@ protected:
|
||||
void init(init_handler callback) {
|
||||
std::cout << "asio connection init" << std::endl;
|
||||
|
||||
security_type::init(
|
||||
socket_con_type::init(
|
||||
lib::bind(
|
||||
&type::handle_init,
|
||||
this,
|
||||
@@ -144,7 +158,7 @@ protected:
|
||||
}
|
||||
|
||||
boost::asio::async_read(
|
||||
security_type::get_socket(),
|
||||
socket_con_type::get_socket(),
|
||||
boost::asio::buffer(buf,len),
|
||||
boost::asio::transfer_at_least(num_bytes),
|
||||
lib::bind(
|
||||
@@ -177,7 +191,7 @@ protected:
|
||||
m_bufs.push_back(boost::asio::buffer(buf,len));
|
||||
|
||||
boost::asio::async_write(
|
||||
security_type::get_socket(),
|
||||
socket_con_type::get_socket(),
|
||||
m_bufs,
|
||||
lib::bind(
|
||||
&type::handle_async_write,
|
||||
@@ -196,7 +210,7 @@ protected:
|
||||
}
|
||||
|
||||
boost::asio::async_write(
|
||||
security_type::get_socket(),
|
||||
socket_con_type::get_socket(),
|
||||
m_bufs,
|
||||
lib::bind(
|
||||
&type::handle_async_write,
|
||||
@@ -222,7 +236,7 @@ protected:
|
||||
void set_handler(handler_ptr new_handler) {
|
||||
m_handler = new_handler;
|
||||
|
||||
security::set_handler(m_handler);
|
||||
socket_con_type::set_handler(m_handler);
|
||||
}
|
||||
|
||||
/// Set Connection Handle
|
||||
@@ -260,7 +274,7 @@ protected:
|
||||
|
||||
/// close and clean up the underlying socket
|
||||
void shutdown() {
|
||||
security_type::shutdown();
|
||||
socket_con_type::shutdown();
|
||||
}
|
||||
private:
|
||||
// static settings
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Peter Thorson. All rights reserved.
|
||||
* Copyright (c) 2013, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -43,30 +43,35 @@ namespace websocketpp {
|
||||
namespace transport {
|
||||
namespace asio {
|
||||
|
||||
/// Boost Asio based endpoint transport component
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
From Endpoint
|
||||
- get new connection
|
||||
|
||||
|
||||
*/
|
||||
|
||||
template <typename concurrency, typename security>
|
||||
class endpoint : public security {
|
||||
* transport::asio::endpoint impliments an endpoint transport component using
|
||||
* Boost ASIO.
|
||||
*/
|
||||
template <typename concurrency, typename socket>
|
||||
class endpoint : public socket {
|
||||
public:
|
||||
typedef endpoint<concurrency,security> type;
|
||||
|
||||
typedef asio::connection<security> con_policy;
|
||||
|
||||
//typedef lib::shared_ptr<boost::asio::io_service> io_service_ptr;
|
||||
/// Type of this endpoint transport component
|
||||
typedef endpoint<concurrency,socket> type;
|
||||
|
||||
/// Type of the socket endpoint component
|
||||
typedef socket socket_type;
|
||||
/// Type of the socket connection component
|
||||
typedef typename socket_type::socket_con_type socket_con_type;
|
||||
/// Type of a shared pointer to the socket connection component
|
||||
typedef typename socket_con_type::ptr socket_con_ptr;
|
||||
|
||||
/// Type of the connection transport component associated with this
|
||||
/// endpoint transport component
|
||||
typedef asio::connection<socket_con_type> transport_con_type;
|
||||
/// Type of a shared pointer to the connection transport component
|
||||
/// associated with this endpoint transport component
|
||||
typedef typename transport_con_type::ptr transport_con_ptr;
|
||||
|
||||
/// Type of a pointer to the ASIO io_service being used
|
||||
typedef boost::asio::io_service* io_service_ptr;
|
||||
/// Type of a shared pointer to the acceptor being used
|
||||
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()
|
||||
@@ -191,10 +196,11 @@ public:
|
||||
|
||||
// Accept the next connection attempt via m_acceptor and assign it to con.
|
||||
// callback is called
|
||||
void async_accept(trans_connection_ptr tcon, accept_handler callback) {
|
||||
void async_accept(transport_con_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;
|
||||
std::cout << "asio::async_accept called from the wrong state"
|
||||
<< std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -274,16 +280,19 @@ protected:
|
||||
|
||||
/// Initialize a connection
|
||||
/**
|
||||
* init(connection_ptr) is called by an endpoint once for each newly created
|
||||
* connection. It's purpose is to give the transport policy the chance to
|
||||
* perform any transport specific initialization that couldn't be done via
|
||||
* the default constructor.
|
||||
* init is called by an endpoint once for each newly created connection. It's
|
||||
* purpose is to give the transport policy the chance to perform any transport
|
||||
* specific initialization that couldn't be done via the default constructor.
|
||||
*
|
||||
* @param tcon A pointer to the transport portion of the connection.
|
||||
*/
|
||||
template <typename connection_ptr>
|
||||
void init(connection_ptr con) {
|
||||
// init tls?
|
||||
con->init_asio(m_io_service);
|
||||
con->set_tcp_init_handler(m_tcp_init_handler);
|
||||
void init(transport_con_ptr tcon) {
|
||||
tcon->init_asio(m_io_service);
|
||||
tcon->set_tcp_init_handler(m_tcp_init_handler);
|
||||
|
||||
// Initialize the connection socket component
|
||||
socket_type::init(lib::static_pointer_cast<socket_con_type,
|
||||
transport_con_type>(tcon));
|
||||
}
|
||||
private:
|
||||
enum state {
|
||||
|
||||
Reference in New Issue
Block a user