asio::io_service::strand Class Reference

Provides serialised handler execution. More...

#include <strand.hpp>

List of all members.

Public Member Functions

 strand (asio::io_service &io_service)
 Constructor.
 ~strand ()
 Destructor.
asio::io_serviceio_service ()
 Get the io_service associated with the strand.
template<typename Handler>
void dispatch (Handler handler)
 Request the strand to invoke the given handler.
template<typename Handler>
void post (Handler handler)
template<typename Handler>
detail::wrapped_handler
< strand, Handler > 
wrap (Handler handler)

Private Attributes

asio::detail::strand_serviceservice_
asio::detail::strand_service::implementation_type impl_


Detailed Description

Provides serialised handler execution.

The io_service::strand class provides the ability to post and dispatch handlers with the guarantee that none of those handlers will execute concurrently.

Thread Safety
Distinct objects: Safe.
Shared objects: Safe.
Concepts:
Dispatcher.

Definition at line 39 of file strand.hpp.


Constructor & Destructor Documentation

asio::io_service::strand::strand ( asio::io_service io_service  )  [inline, explicit]

Constructor.

Constructs the strand.

Parameters:
io_service The io_service object that the strand will use to dispatch handlers that are ready to be run.

Definition at line 49 of file strand.hpp.

References asio::detail::strand_service::construct(), impl_, and service_.

asio::io_service::strand::~strand (  )  [inline]

Destructor.

Definition at line 57 of file strand.hpp.

References asio::detail::strand_service::destroy(), impl_, and service_.


Member Function Documentation

asio::io_service& asio::io_service::strand::io_service (  )  [inline]

Get the io_service associated with the strand.

This function may be used to obtain the io_service object that the strand uses to dispatch handlers for asynchronous operations.

Returns:
A reference to the io_service object that the strand will use to dispatch handlers. Ownership is not transferred to the caller.

Definition at line 70 of file strand.hpp.

References asio::io_service::service::io_service(), and service_.

template<typename Handler>
void asio::io_service::strand::dispatch ( Handler  handler  )  [inline]

Request the strand to invoke the given handler.

This function is used to ask the strand to execute the given handler.

The strand object guarantees that handlers posted or dispatched through the strand will not be executed concurrently. The handler may be executed inside this function if the guarantee can be met. If this function is called from within a handler that was posted or dispatched through the same strand, then the new handler will be executed immediately.

The strand's guarantee is in addition to the guarantee provided by the underlying io_service. The io_service guarantees that the handler will only be called in a thread in which the io_service's run member function is currently being invoked.

Parameters:
handler The handler to be called. The strand will make a copy of the handler object as required. The function signature of the handler must be:
 void handler(); 

Definition at line 95 of file strand.hpp.

References asio::detail::strand_service::dispatch(), impl_, and service_.

template<typename Handler>
void asio::io_service::strand::post ( Handler  handler  )  [inline]

Request the strand to invoke the given handler and return immediately. This function is used to ask the strand to execute the given handler, but without allowing the strand to call the handler from inside this function.

The strand object guarantees that handlers posted or dispatched through the strand will not be executed concurrently. The strand's guarantee is in addition to the guarantee provided by the underlying io_service. The io_service guarantees that the handler will only be called in a thread in which the io_service's run member function is currently being invoked.

Parameters:
handler The handler to be called. The strand will make a copy of the handler object as required. The function signature of the handler must be:
 void handler(); 

Definition at line 117 of file strand.hpp.

References impl_, asio::detail::strand_service::post(), and service_.

template<typename Handler>
detail::wrapped_handler<strand, Handler> asio::io_service::strand::wrap ( Handler  handler  )  [inline]

Create a new handler that automatically dispatches the wrapped handler on the strand. This function is used to create a new handler function object that, when invoked, will automatically pass the wrapped handler to the strand's dispatch function.

Parameters:
handler The handler to be wrapped. The strand will make a copy of the handler object as required. The function signature of the handler must be:
 void handler(A1 a1, ... An an); 
Returns:
A function object that, when invoked, passes the wrapped handler to the strand's dispatch function. Given a function object with the signature:
 R f(A1 a1, ... An an); 
If this function object is passed to the wrap function like so:
 strand.wrap(f); 
then the return value is a function object with the signature
 void g(A1 a1, ... An an); 
that, when invoked, executes code equivalent to:
 strand.dispatch(boost::bind(f, a1, ... an)); 

Definition at line 149 of file strand.hpp.

Referenced by libtorrent::dht::dht_tracker::add_node(), libtorrent::dht::dht_tracker::add_router_node(), libtorrent::torrent::connect_to_url_seed(), libtorrent::dht::dht_tracker::connection_timeout(), libtorrent::dht::dht_tracker::dht_tracker(), libtorrent::http_tracker_connection::http_tracker_connection(), libtorrent::torrent::on_dht_announce(), libtorrent::torrent::on_proxy_name_lookup(), libtorrent::dht::dht_tracker::on_receive(), libtorrent::aux::session_impl::operator()(), libtorrent::dht::dht_tracker::refresh_timeout(), libtorrent::torrent::resolve_peer_country(), libtorrent::aux::session_impl::second_tick(), libtorrent::aux::session_impl::session_impl(), libtorrent::timeout_handler::set_timeout(), libtorrent::dht::dht_tracker::tick(), libtorrent::timeout_handler::timeout_callback(), libtorrent::torrent::torrent(), libtorrent::torrent::tracker_response(), libtorrent::torrent::try_next_tracker(), and libtorrent::udp_tracker_connection::udp_tracker_connection().


Member Data Documentation

Definition at line 155 of file strand.hpp.

Referenced by dispatch(), io_service(), post(), strand(), and ~strand().

Definition at line 156 of file strand.hpp.

Referenced by dispatch(), post(), strand(), and ~strand().


The documentation for this class was generated from the following file:

Generated on Sun May 25 00:21:29 2008 by  doxygen 1.5.6