asio 0.1.5 Main Page | Class Index | Member Index | Tutorial

basic_demuxer Class Template Reference

The basic_demuxer class template provides the core event demultiplexing functionality for users of the asynchronous I/O objects, such as stream_socket, and also to developers of custom asynchronous services. Most applications will use the demuxer typedef. More...

List of all members.

Public Types

typedef Demuxer_Service service_type
 The type of the service that will be used to provide demuxer operations.


Public Member Functions

 basic_demuxer ()
 Default constructor.

void run ()
 Run the demuxer's event processing loop.

void interrupt ()
 Interrupt the demuxer's event processing loop.

void reset ()
 Reset the demuxer in preparation for a subsequent run invocation.

void operation_started ()
 Notify the demuxer that an operation has started.

template<typename Handler> void operation_completed (Handler handler)
 Notify the demuxer that an operation has completed.

template<typename Handler, typename Completion_Context> void operation_completed (Handler handler, Completion_Context context)
 Notify the demuxer that an operation has completed.

template<typename Handler, typename Completion_Context> void operation_completed (Handler handler, Completion_Context context, bool allow_nested_delivery)
 Notify the demuxer that an operation has completed.

template<typename Handler> void operation_immediate (Handler handler)
 Notify the demuxer of an operation that started and finished immediately.

template<typename Handler, typename Completion_Context> void operation_immediate (Handler handler, Completion_Context context)
 Notify the demuxer of an operation that started and finished immediately.

template<typename Handler, typename Completion_Context> void operation_immediate (Handler handler, Completion_Context context, bool allow_nested_delivery)
 Notify the demuxer of an operation that started and finished immediately.

template<typename Service> Service & get_service (service_factory< Service > factory)
 Obtain the service interface corresponding to the given type.


Private Attributes

detail::service_registry<
basic_demuxer< Demuxer_Service > > 
service_registry_
 The service registry.

Demuxer_Service & service_
 The underlying demuxer service implementation.


Detailed Description

template<typename Demuxer_Service>
class asio::basic_demuxer< Demuxer_Service >

The basic_demuxer class template provides the core event demultiplexing functionality for users of the asynchronous I/O objects, such as stream_socket, and also to developers of custom asynchronous services. Most applications will use the demuxer typedef.


Member Typedef Documentation

typedef Demuxer_Service service_type
 

The type of the service that will be used to provide demuxer operations.


Constructor & Destructor Documentation

basic_demuxer  ) 
 

Default constructor.


Member Function Documentation

void run  ) 
 

Run the demuxer's event processing loop.

The run function blocks until all operations have completed and there are no more completions to be delivered, or until the demuxer has been interrupted. The run function may be safely called again once it has completed to execute any new operations or deliver new completions.

Multiple threads may call the run function to set up a pool of threads from which the demuxer may dispatch the completion notifications.

void interrupt  ) 
 

Interrupt the demuxer's event processing loop.

This function does not block, but instead simply signals to the demuxer that all invocations of its run member function should return as soon as possible.

Note that if the run function is interrupted and is not called again later then its operations may not have finished and completions not delivered. In this case a demuxer implementation is not required to make any guarantee that any resources associated with those operations would be cleaned up.

void reset  ) 
 

Reset the demuxer in preparation for a subsequent run invocation.

This function must be called prior to any second or later set of invocations of the run function. It allows the demuxer to reset any internal state, such as an interrupt flag.

This function must not be called while there are any unfinished calls to the run function.

void operation_started  ) 
 

Notify the demuxer that an operation has started.

This function is used to inform the demuxer that a new operation has begun. A call to this function must be matched with a later corresponding call to operation_completed.

void operation_completed Handler  handler  ) 
 

Notify the demuxer that an operation has completed.

This function is used to inform the demuxer that an operation has completed and that it should invoke the given completion handler. A call to this function must be matched with an earlier corresponding call to operation_started.

The completion handler is guaranteed to be called only from a thread in which the run member function is being invoked.

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

void operation_completed Handler  handler,
Completion_Context  context
 

Notify the demuxer that an operation has completed.

This function is used to inform the demuxer that an operation has completed and that it should invoke the given completion handler. A call to this function must be matched with an earlier corresponding call to operation_started.

The completion handler is guaranteed to be called only from a thread in which the run member function is being invoked.

Parameters:
handler The completion handler to be called. The demuxer will make a copy of the handler object as required. The equivalent function signature of the handler must be:
 void handler(); 
context The completion context which controls the number of concurrent invocations of handlers that may be made. Copies will be made of the context object as required, however all copies are equivalent.

void operation_completed Handler  handler,
Completion_Context  context,
bool  allow_nested_delivery
 

Notify the demuxer that an operation has completed.

This function is used to inform the demuxer that an operation has completed and that it should invoke the given completion handler. A call to this function must be matched with an earlier corresponding call to operation_started.

The completion handler is guaranteed to be called only from a thread in which the run member function is being invoked.

Parameters:
handler The completion handler to be called. The demuxer will make a copy of the handler object as required. The equivalent function signature of the handler must be:
 void handler(); 
context The completion context which controls the number of concurrent invocations of handlers that may be made. Copies will be made of the context object as required, however all copies are equivalent.
allow_nested_delivery If true, this allows the demuxer to run the completion handler before operation_completed returns, as an optimisation. This is at the discretion of the demuxer implementation, but may only be done if it can meet the guarantee that the handler is invoked from a thread executing the run function. If false, the function returns immediately.

void operation_immediate Handler  handler  ) 
 

Notify the demuxer of an operation that started and finished immediately.

This function is used to inform the demuxer that an operation has both started and completed immediately, and that it should invoke the given completion handler. A call to this function must not have either of a corresponding operation_started or operation_completed.

The completion handler is guaranteed to be called only from a thread in which the run member function is being invoked.

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

void operation_immediate Handler  handler,
Completion_Context  context
 

Notify the demuxer of an operation that started and finished immediately.

This function is used to inform the demuxer that an operation has both started and completed immediately, and that it should invoke the given completion handler. A call to this function must not have either of a corresponding operation_started or operation_completed.

The completion handler is guaranteed to be called only from a thread in which the run member function is being invoked.

Parameters:
handler The completion handler to be called. The demuxer will make a copy of the handler object as required. The equivalent function signature of the handler must be:
 void handler(); 
context The completion context which controls the number of concurrent invocations of handlers that may be made. Copies will be made of the context object as required, however all copies are equivalent.

void operation_immediate Handler  handler,
Completion_Context  context,
bool  allow_nested_delivery
 

Notify the demuxer of an operation that started and finished immediately.

This function is used to inform the demuxer that an operation has both started and completed immediately, and that it should invoke the given completion handler. A call to this function must not have either of a corresponding operation_started or operation_completed.

The completion handler is guaranteed to be called only from a thread in which the run member function is being invoked.

Parameters:
handler The completion handler to be called. The demuxer will make a copy of the handler object as required. The equivalent function signature of the handler must be:
 void handler(); 
context The completion context which controls the number of concurrent invocations of handlers that may be made. Copies will be made of the context object as required, however all copies are equivalent.
allow_nested_delivery If true, this allows the demuxer to run the completion handler before operation_immediate returns, as an optimisation. This is at the discretion of the demuxer implementation, but may only be done if it can meet the guarantee that the handler is invoked from a thread executing the run function. If false, the function returns immediately.

Service& get_service service_factory< Service >  factory  ) 
 

Obtain the service interface corresponding to the given type.

This function is used to locate a service interface that corresponds to the given service type. If there is no existing implementation of the service, then the demuxer will use the supplied factory to create a new instance.

Parameters:
factory The factory to use to create the service.
Returns:
The service interface implementing the specified service type. Ownership of the service interface is not transferred to the caller.


Member Data Documentation

detail::service_registry<basic_demuxer<Demuxer_Service> > service_registry_ [private]
 

The service registry.

Demuxer_Service& service_ [private]
 

The underlying demuxer service implementation.