whitespace and don't accept if we know the transport isn't listening references #334

This commit is contained in:
Peter Thorson
2014-03-04 06:45:00 -06:00
parent 7eedf25500
commit b805689f9c
2 changed files with 21 additions and 12 deletions

View File

@@ -82,6 +82,12 @@ public:
// Starts the server's async connection acceptance loop.
void start_accept() {
if (!transport_type::is_listening()) {
endpoint_type::m_elog.write(log::elevel::info,
"Stopping acceptance of new connections because the underlying transport is no longer listening.");
return;
}
connection_ptr con = get_connection();
lib::error_code ec;
@@ -104,13 +110,12 @@ public:
endpoint_type::m_elog.write(log::elevel::rerror,
"start_accept error: "+ec.message());
}
if (ec) {
// Terminate the connection to prevent memory leaks.
lib::error_code con_ec;
con->terminate(con_ec);
}
}
if (ec) {
// Terminate the connection to prevent memory leaks.
con->terminate(lib::error_code());
}
}
void handle_accept(connection_ptr con, lib::error_code const & ec) {
if (ec) {
@@ -127,7 +132,7 @@ public:
con->start();
}
// TODO: are there cases where we should terminate this loop?
start_accept();
}
private:

View File

@@ -539,6 +539,14 @@ public:
}
}
/// Check if the endpoint is listening
/**
* @return Whether or not the endpoint is listening.
*/
bool is_listening() const {
return (m_state == LISTENING);
}
/// wraps the run method of the internal io_service object
std::size_t run() {
return m_io_service->run();
@@ -985,10 +993,6 @@ protected:
callback(lib::error_code());
}
bool is_listening() const {
return (m_state == LISTENING);
}
/// Initialize a connection
/**
* init is called by an endpoint once for each newly created connection.