Added a disconnected ids queue to the ana manager...

...to inform disconnections to the server implementation.
This commit is contained in:
Guillermo Biset 2010-07-19 19:55:33 +00:00
parent 988a6e697b
commit 9e43ae7ff7
4 changed files with 28 additions and 2 deletions

View file

@ -272,6 +272,7 @@ asio_server::asio_client_proxy::asio_client_proxy(boost::asio::io_service& io_se
asio_server::asio_client_proxy::~asio_client_proxy()
{
manager_->deregister_client( this );
socket_.close();
}
tcp::socket& asio_server::asio_client_proxy::socket()

View file

@ -197,6 +197,8 @@ namespace network {
unsigned int timeout,
bandwidth_in_ptr* bandwidth_in)
{
ana_manager.throw_if_pending_disconnection();
//TODO: temporary fix
if ( bandwidth_in != NULL )
*bandwidth_in = global_bandwidth_in_ptr;
@ -222,6 +224,8 @@ namespace network {
connection receive_data(std::vector<char>& buf, bandwidth_in_ptr* bandwidth_in)
{
ana_manager.throw_if_pending_disconnection();
//TODO: temporary fix
if ( bandwidth_in != NULL )
*bandwidth_in = global_bandwidth_in_ptr;
@ -286,7 +290,7 @@ namespace network {
void process_send_queue(connection, size_t)
{
// check_error();
ana_manager.throw_if_pending_disconnection();
}
/** @todo Note the gzipped parameter should be removed later. */

View file

@ -28,6 +28,8 @@
#include "network_manager_ana.hpp"
#include "serialization/binary_or_text.hpp"
#include "gettext.hpp"
// Begin ana_send_handler implementation ---------------------------------------------------------------
ana_send_handler::ana_send_handler( size_t calls ) :
@ -598,7 +600,8 @@ network::connection clients_manager::get_pending_connection_id()
ana_network_manager::ana_network_manager() :
connect_timer_( NULL ),
components_(),
server_manager_()
server_manager_(),
disconnected_ids_()
{
}
@ -739,6 +742,15 @@ void ana_network_manager::close_connections_and_cleanup()
server_manager_.clear();
}
void ana_network_manager::throw_if_pending_disconnection()
{
if ( ! disconnected_ids_.empty() )
{
const ana::net_id id = disconnected_ids_.front();
disconnected_ids_.pop();
throw network::error(_("Client disconnected"),id);
}
}
void ana_network_manager::run_server(ana::net_id id, int port)
{
@ -1228,6 +1240,9 @@ void ana_network_manager::handle_disconnect(ana::error_code /*error_code*/, ana:
for (it = components_.begin(); it != components_.end(); it++ )
if ( (*it)->is_server() )
if ( server_manager_[ (*it)->server() ]->is_a_client( client ) )
{
server_manager_[ (*it)->server() ]->remove( client );
disconnected_ids_.push( client );
}
}
}

View file

@ -400,8 +400,12 @@ class ana_network_manager : public ana::listener_handler,
*/
const ana::stats* get_stats( network::connection connection_num );
/** Close all connections and clean up memory. */
void close_connections_and_cleanup();
/** Throw a Client Disconnected network::error if a disconnection hasn't been informed. */
void throw_if_pending_disconnection();
/**
* Start a server on a given port.
*
@ -500,6 +504,8 @@ class ana_network_manager : public ana::listener_handler,
ana_component_set components_;
std::map< ana::server*, clients_manager* > server_manager_;
std::queue< ana::net_id > disconnected_ids_;
};
#endif