Added a method to ANA that allows the canceling...
...of all pending asynchronous operations, and in the server you can do this for a particular client as well.
This commit is contained in:
parent
e82e18f816
commit
8778760ea7
5 changed files with 55 additions and 13 deletions
|
@ -479,10 +479,21 @@ namespace ana
|
|||
virtual void set_raw_data_mode( net_id id ) = 0;
|
||||
|
||||
/**
|
||||
* Cancel a network operation.
|
||||
* Does nothing if the operation already completed or is an ivalid operation id.
|
||||
* Cancel all pending network operations.
|
||||
* Every pending operation handler will be invoked with ana::operation_aborted
|
||||
* as the corresponding error_code.
|
||||
*/
|
||||
virtual void cancel( operation_id operation ) = 0;
|
||||
virtual void cancel_pending( ) = 0;
|
||||
|
||||
/**
|
||||
* Cancel all pending network operations for a given client.
|
||||
* Does nothing if the client_id doesn't belong to a connected client.
|
||||
* Every pending operation handler will be invoked with ana::operation_aborted
|
||||
* as the corresponding error_code.
|
||||
*
|
||||
* @param client_id : Network ID of the client.
|
||||
*/
|
||||
virtual void cancel_pending( ana::net_id client_id ) = 0;
|
||||
|
||||
/* Allow external object to call set_raw_data_mode() directly. */
|
||||
/**
|
||||
|
@ -523,6 +534,13 @@ namespace ana
|
|||
/** Standard destructor. */
|
||||
virtual ~client_proxy() {}
|
||||
|
||||
/**
|
||||
* Cancel all pending network operations.
|
||||
* Every pending operation handler will be invoked with ana::operation_aborted
|
||||
* as the corresponding error_code.
|
||||
*/
|
||||
virtual void cancel_pending() = 0;
|
||||
|
||||
/** Returns the string representing the ip address of the connected client. */
|
||||
virtual std::string ip_address() const = 0;
|
||||
|
||||
|
@ -605,10 +623,11 @@ namespace ana
|
|||
send_type type = COPY_BUFFER ) = 0;
|
||||
|
||||
/**
|
||||
* Cancel a network operation.
|
||||
* Does nothing if the operation already completed or is an ivalid operation id.
|
||||
* Cancel all pending network operations.
|
||||
* Every pending operation handler will be invoked with ana::operation_aborted
|
||||
* as the corresponding error_code.
|
||||
*/
|
||||
virtual void cancel( operation_id operation ) = 0;
|
||||
virtual void cancel_pending( ) = 0;
|
||||
|
||||
/** Standard destructor. */
|
||||
virtual ~client() {}
|
||||
|
|
|
@ -203,9 +203,9 @@ const ana::stats* asio_client::get_stats( ana::stat_type type ) const
|
|||
throw std::runtime_error("Logging is disabled. Use start_logging first.");
|
||||
}
|
||||
|
||||
void asio_client::cancel( ana::operation_id /*operation */)
|
||||
void asio_client::cancel_pending()
|
||||
{
|
||||
// TODO: implement
|
||||
socket_.cancel();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,8 @@ class asio_client : public ana::client,
|
|||
|
||||
virtual ana::timer* create_timer() { return new ana::timer( io_service_); }
|
||||
|
||||
virtual void cancel( ana::operation_id operation );
|
||||
virtual void cancel_pending( );
|
||||
|
||||
|
||||
void handle_connect(const boost::system::error_code& ec,
|
||||
tcp::resolver::iterator endpoint_iterator,
|
||||
|
|
|
@ -424,11 +424,24 @@ const ana::stats* asio_server::asio_client_proxy::get_stats( ana::stat_type type
|
|||
throw std::runtime_error("Logging is disabled. Use start_logging first.");
|
||||
}
|
||||
|
||||
void asio_server::cancel( ana::operation_id /*operation */)
|
||||
void asio_server::cancel_pending( )
|
||||
{
|
||||
// TODO: implement
|
||||
std::for_each( client_proxies_.begin(), client_proxies_.end(),
|
||||
boost::bind(&ana::server::client_proxy::cancel_pending, _1 ) );
|
||||
}
|
||||
|
||||
void asio_server::cancel_pending( ana::net_id client_id )
|
||||
{
|
||||
std::list<ana::server::client_proxy*>::const_iterator it;
|
||||
|
||||
it = std::find_if( client_proxies_.begin(), client_proxies_.end(),
|
||||
boost::bind( &client_proxy::id, _1) == client_id );
|
||||
|
||||
if ( it != client_proxies_.end() )
|
||||
(*it)->cancel_pending();
|
||||
}
|
||||
|
||||
|
||||
void asio_server::asio_client_proxy::send(ana::detail::shared_buffer buffer,
|
||||
send_handler* handler,
|
||||
ana::detail::sender* sender,
|
||||
|
@ -439,10 +452,16 @@ void asio_server::asio_client_proxy::send(ana::detail::shared_buffer buffer,
|
|||
|
||||
void asio_server::asio_client_proxy::disconnect_listener()
|
||||
{
|
||||
socket_.cancel();
|
||||
cancel_pending();
|
||||
delete this;
|
||||
}
|
||||
|
||||
void asio_server::asio_client_proxy::cancel_pending()
|
||||
{
|
||||
socket_.cancel();
|
||||
}
|
||||
|
||||
|
||||
std::string asio_server::asio_client_proxy::ip_address() const
|
||||
{
|
||||
return socket_.remote_endpoint().address().to_string();
|
||||
|
|
|
@ -69,6 +69,8 @@ class asio_server : public ana::server,
|
|||
|
||||
virtual void disconnect_listener();
|
||||
|
||||
virtual void cancel_pending();
|
||||
|
||||
virtual void send(ana::detail::shared_buffer,
|
||||
ana::send_handler*,
|
||||
ana::detail::sender*,
|
||||
|
@ -136,7 +138,8 @@ class asio_server : public ana::server,
|
|||
|
||||
virtual const ana::stats* get_stats( ana::stat_type type ) const;
|
||||
|
||||
virtual void cancel( ana::operation_id operation );
|
||||
virtual void cancel_pending( );
|
||||
virtual void cancel_pending( ana::net_id client_id );
|
||||
|
||||
virtual void disconnect( ana::net_id );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue