connection initialization errors are properly logged and propogated

This commit is contained in:
Peter Thorson
2013-05-04 11:52:52 -05:00
parent 6561a9be20
commit c559e0a623
6 changed files with 53 additions and 17 deletions

View File

@@ -46,7 +46,6 @@ endpoint<connection,config>::create_connection() {
connection_weak_ptr w(con);
// Create a weak pointer on the heap using that shared_ptr.
// Cast that weak pointer to void* and manage it using another shared_ptr
// connection_hdl hdl(reinterpret_cast<void*>(new connection_weak_ptr(con)));
@@ -75,15 +74,18 @@ endpoint<connection,config>::create_connection() {
lib::placeholders::_1
)
);
transport_type::init(con);
lib::error_code ec;
ec = transport_type::init(con);
if (ec) {
m_elog.write(log::elevel::fatal,ec.message());
return connection_ptr();
}
scoped_lock_type lock(m_mutex);
m_connections.insert(con);
//m_alog->at(log::alevel::DEVEL) << "Connection created: count is now: "
// << m_connections.size() << log::endl;
return con;
}

View File

@@ -102,14 +102,19 @@ public:
* TODO: this method is not protected because the endpoint needs to call it.
* need to figure out if there is a way to friend the endpoint safely across
* different compilers.
*
* @param io_service A pointer to the io_service to register with this
* connection
*
* @return Status code for the success or failure of the initialization
*/
void init_asio (io_service_ptr io_service) {
lib::error_code init_asio (io_service_ptr io_service) {
// 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));
socket_con_type::init_asio(io_service, m_is_server);
return socket_con_type::init_asio(io_service, m_is_server);
}
void set_tcp_init_handler(tcp_init_handler h) {

View File

@@ -462,16 +462,24 @@ protected:
* constructor.
*
* @param tcon A pointer to the transport portion of the connection.
*
* @return A status code indicating the success or failure of the operation
*/
void init(transport_con_ptr tcon) {
lib::error_code init(transport_con_ptr tcon) {
m_alog->write(log::alevel::devel, "transport::asio::init");
// Initialize the connection socket component
socket_type::init(lib::static_pointer_cast<socket_con_type,
transport_con_type>(tcon));
tcon->init_asio(m_io_service);
lib::error_code ec;
ec = tcon->init_asio(m_io_service);
if (ec) {return ec;}
tcon->set_tcp_init_handler(m_tcp_init_handler);
return lib::error_code();
}
private:
enum state {

View File

@@ -242,15 +242,19 @@ public:
void set_socket_init_handler(socket_init_handler h) {
m_socket_init_handler = h;
}
protected:
/// Initialize a connection
/**
* Called by the transport after a new connection is created to initialize
* the socket component of the connection.
*
* @param scon Pointer to the socket component of the connection
*
* @return Error code (empty on success)
*/
void init(socket_con_ptr scon) {
lib::error_code init(socket_con_ptr scon) {
scon->set_socket_init_handler(m_socket_init_handler);
return lib::error_code();
}
private:
socket_init_handler m_socket_init_handler;

View File

@@ -352,10 +352,15 @@ protected:
/**
* Called by the transport after a new connection is created to initialize
* the socket component of the connection.
*
* @param scon Pointer to the socket component of the connection
*
* @return Error code (empty on success)
*/
void init(socket_con_ptr scon) {
lib::error_code init(socket_con_ptr scon) {
scon->set_socket_init_handler(m_socket_init_handler);
scon->set_tls_init_handler(m_tls_init_handler);
return lib::error_code();
}
private:

View File

@@ -108,8 +108,20 @@ protected:
cb(tcon->get_handle(),lib::error_code());
}
void init(transport_con_ptr tcon) {
tcon->register_ostream(output_stream);
/// Initialize a connection
/**
* 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.
*
* @return A status code indicating the success or failure of the operation
*/
lib::error_code init(transport_con_ptr tcon) {
tcon->register_ostream(m_output_stream);
return lib::error_code();
}
private:
std::ostream* m_output_stream;