Skip to content

Commit

Permalink
whitespace and don't accept if we know the transport isn't listening …
Browse files Browse the repository at this point in the history
…references #334
  • Loading branch information
zaphoyd committed Mar 4, 2014
1 parent 7eedf25 commit b805689
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
21 changes: 13 additions & 8 deletions websocketpp/roles/server_endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class server : public endpoint<connection<config>,config> {

// 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;
Expand All @@ -104,13 +110,12 @@ class server : public endpoint<connection<config>,config> {
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) {
Expand All @@ -127,7 +132,7 @@ class server : public endpoint<connection<config>,config> {
con->start();
}

// TODO: are there cases where we should terminate this loop?

start_accept();
}
private:
Expand Down
12 changes: 8 additions & 4 deletions websocketpp/transport/asio/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,14 @@ class endpoint : public config::socket_type {
}
}

/// 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();
Expand Down Expand Up @@ -985,10 +993,6 @@ class endpoint : public config::socket_type {
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.
Expand Down

0 comments on commit b805689

Please sign in to comment.