Fix bugs when issuing certain /query messages to the server.
Even though this fixes the hang ups some functionality remains unimplemented still, such as the pending statistics (see the TODO in network_ana.cpp:113 about this.)
This commit is contained in:
parent
5e140f2272
commit
b6dbe2fc75
2 changed files with 32 additions and 7 deletions
|
@ -92,9 +92,12 @@ namespace network {
|
|||
{
|
||||
const ana::stats* stats = ana_manager.get_stats( connection_num );
|
||||
|
||||
return connection_stats( stats->bytes_out(),
|
||||
stats->bytes_in(),
|
||||
stats->uptime() ); //TODO: is uptime ok?
|
||||
if ( stats == NULL )
|
||||
throw std::runtime_error("Invalid connection ID to get stats from.");
|
||||
else
|
||||
return connection_stats( stats->bytes_out(),
|
||||
stats->bytes_in(),
|
||||
stats->uptime() );
|
||||
}
|
||||
|
||||
error::error(const std::string& msg, connection sock) : game::error(msg), socket(sock)
|
||||
|
@ -107,7 +110,13 @@ namespace network {
|
|||
|
||||
pending_statistics get_pending_stats()
|
||||
{
|
||||
throw std::runtime_error("TODO:Not implemented get_pending_stats");
|
||||
//TODO: implement this feature, this is only to avoid segfaults when /query netstats is sent
|
||||
pending_statistics result;
|
||||
|
||||
result.npending_sends = 0;
|
||||
result.nbytes_pending_sends = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
manager::manager(size_t /*min_threads*/, size_t /*max_threads*/) : free_(true)
|
||||
|
@ -246,7 +255,6 @@ namespace network {
|
|||
|
||||
const ana::stats* stats = ana_manager.get_stats( );
|
||||
|
||||
|
||||
std::stringstream ss;
|
||||
ss << " " << std::setw(field_width) << packet_type << "| "
|
||||
<< std::setw(packet_width)<< stats->packets_out()<< "| "
|
||||
|
|
|
@ -696,6 +696,8 @@ network::connection ana_network_manager::new_connection_id( )
|
|||
// No new connection
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const ana::stats* ana_network_manager::get_stats( network::connection connection_num,
|
||||
ana::stat_type type)
|
||||
{
|
||||
|
@ -704,7 +706,7 @@ const ana::stats* ana_network_manager::get_stats( network::connection connection
|
|||
|
||||
if ( id == 0 )
|
||||
{
|
||||
if ( components_.size() > 0 )
|
||||
if ( ! components_.empty() )
|
||||
{
|
||||
it = components_.begin();
|
||||
return (*it)->get_stats( type );
|
||||
|
@ -715,10 +717,25 @@ const ana::stats* ana_network_manager::get_stats( network::connection connection
|
|||
else
|
||||
{
|
||||
it = std::find_if( components_.begin(), components_.end(),
|
||||
boost::bind(&ana_component::get_id, _1) == id );
|
||||
boost::bind(std::logical_or<bool>(),
|
||||
(boost::bind(&ana_component::get_wesnoth_id, _1) == connection_num),
|
||||
(boost::bind(&ana_component::get_id, _1) == id ) ));
|
||||
//Make a broad attempt at finding it, test for both ANA's id and the assigned one.
|
||||
|
||||
if ( it != components_.end())
|
||||
return (*it)->get_stats( type );
|
||||
else
|
||||
{
|
||||
for ( it = components_.begin() ; it != components_.end(); ++it)
|
||||
{
|
||||
if ( (*it)->is_server() )
|
||||
{
|
||||
const ana::stats* res = (*it)->server()->get_client_stats(id,ana::ACCUMULATED);
|
||||
if ( res != NULL )
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue