| Home | Libraries | People | FAQ | More

# boost::asio::basic_strand< Service > Class Template Reference

Inherits boost::asio::basic_io_object< Service >< Service >.

Inheritance diagram for boost::asio::basic_strand< Service >:

List of all members.

## Detailed Description

### template<typename Service = strand_service>
class boost::asio::basic_strand< Service >

Provides serialised handler execution.

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

Most applications will use the boost::asio::strand typedef.

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

Concepts:
  Dispatcher.

## Public Types

typedef Service | service_type
| The type of the service that will be used to provide I/O operations.
typedef service_type::implementation_type | implementation_type
| The underlying implementation type of I/O object.

## Public Member Functions

| basic_strand (boost::asio::io_service &io_service)
| Constructor.
template<typename Handler>
void | dispatch (Handler handler)
| Request the strand to invoke the given handler.
template<typename Handler>
void | post (Handler handler)
| Request the strand to invoke the given handler and return immediately.
template<typename Handler>
unspecified | wrap (Handler handler)
| Create a new handler that automatically dispatches the wrapped handler on the strand.
boost::asio::io_service & | io_service ()
| Get the io_service associated with the object.

## Member Typedef Documentation

template<typename Service>

typedef Service boost::asio::basic_io_object< Service >::service_type `[inherited]`

The type of the service that will be used to provide I/O operations.

template<typename Service>

typedef service_type::implementation_type boost::asio::basic_io_object< Service >::implementation_type `[inherited]`

The underlying implementation type of I/O object.

## Constructor & Destructor Documentation

template<typename Service = strand_service>

boost::asio::basic_strand< Service >::basic_strand | ( | boost::asio::io_service & | io_service | ) | `[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.

## Member Function Documentation

template<typename Service = strand_service>
template<typename Handler>

void boost::asio::basic_strand< Service >::dispatch | ( | Handler | handler | ) |

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 only one handler executed through this strand will be invoked at a time. The handler may be executed inside this function if the guarantee can be met.

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();

template<typename Service = strand_service>
template<typename Handler>

void boost::asio::basic_strand< Service >::post | ( | Handler | handler | ) |

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 only one handler executed through this strand will be invoked at a time. 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();

template<typename Service = strand_service>
template<typename Handler>

unspecified boost::asio::basic_strand< Service >::wrap | ( | Handler | handler | ) |

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));

template<typename Service>

boost::asio::io_service& boost::asio::basic_io_object< Service >::io_service | ( |  | ) | `[inherited]`

Get the io_service associated with the object.

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

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

| Copyright © 2003 - 2006 Christopher M. Kohlhoff