Skip to content
Browse files

more defensive when a connection is shutting down

  • Loading branch information...
1 parent 188fe1f commit 80d4be5bc0153b3a39f5bd7d28e36796dff1dd4a @RJ committed Jul 18, 2009
Showing with 16 additions and 5 deletions.
  1. +1 −1 CMakeLists.txt
  2. +12 −1 src/connection.cpp
  3. +3 −3 src/router.cpp
View
2 CMakeLists.txt
@@ -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)
View
13 src/connection.cpp
@@ -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() );
@@ -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);
@@ -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 ) );
}
View
6 src/router.cpp
@@ -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
@@ -111,7 +111,7 @@ Router::register_connection( connection_ptr conn )
}
}
m_connections.push_back( conn );
- cout << connections_str() << endl;
+ //cout << connections_str() << endl;
}
void
@@ -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

0 comments on commit 80d4be5

Please sign in to comment.
Something went wrong with that request. Please try again.