Skip to content

Commit

Permalink
more defensive when a connection is shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
RJ committed Jul 18, 2009
1 parent 188fe1f commit 80d4be5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ENDIF(WIN32)

IF(NOT WIN32)
# removes operators like "and", "or" and "not"
ADD_DEFINITIONS(-Wall) # -ggdb
ADD_DEFINITIONS(-Wall -ggdb)
ADD_DEFINITIONS(-g )
ADD_DEFINITIONS(-fno-operator-names)
ADD_DEFINITIONS(-fPIC)
Expand Down
13 changes: 12 additions & 1 deletion src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ Connection::~Connection()
void
Connection::close()
{
m_ready = false;
socket().close();
}

void
Connection::fin()
{
if( m_shuttingdown ) return;
m_shuttingdown = true;
std::cout << "FIN connection " << str() << std::endl;
m_router->connection_terminated( shared_from_this() );
Expand Down Expand Up @@ -151,6 +153,14 @@ Connection::str() const
void
Connection::do_async_write(const boost::system::error_code& e, message_ptr finished_msg)
{
if( m_shuttingdown ) return;
if( e )
{
cerr << "Error in libf2f::do_async_write, terminating connection"
<< endl;
fin();
return;
}
message_ptr msgp;
{ // mutex scope
boost::mutex::scoped_lock lk(m_mutex);
Expand All @@ -175,7 +185,8 @@ Connection::do_async_write(const boost::system::error_code& e, message_ptr finis
} // mutex scope

boost::asio::async_write( socket(), msgp->to_buffers(),
boost::bind( &Connection::do_async_write, this,
boost::bind( &Connection::do_async_write,
shared_from_this(),
boost::asio::placeholders::error,
msgp ) );
}
Expand Down
6 changes: 3 additions & 3 deletions src/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ Router::stop()
{
while( m_connections.size() )
{
// this removes the connection from m_connections:
m_connections.front()->fin();
}
//m_acceptor->get_io_service().stop();
}

void
Expand Down Expand Up @@ -111,7 +111,7 @@ Router::register_connection( connection_ptr conn )
}
}
m_connections.push_back( conn );
cout << connections_str() << endl;
//cout << connections_str() << endl;
}

void
Expand All @@ -127,7 +127,7 @@ Router::unregister_connection( connection_ptr conn )
//cout << "Router::unregistered " << conn->str() << endl;
}
}
cout << connections_str() << endl;
//cout << connections_str() << endl;
}

connection_ptr
Expand Down

0 comments on commit 80d4be5

Please sign in to comment.