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

basic_socket_connector Class Template Reference

The basic_socket_connector class template is used to connect a socket to a remote endpoint. Most applications will use the socket_connector typedef. More...

List of all members.

Public Types

typedef Service service_type
 The type of the service that will be used to provide connect operations.

typedef service_type::impl_type impl_type
 The native implementation type of the socket connector.

typedef service_type::demuxer_type demuxer_type
 The demuxer type for this asynchronous type.


Public Member Functions

 basic_socket_connector (demuxer_type &d)
 Constructor.

template<typename Protocol>  basic_socket_connector (demuxer_type &d, const Protocol &protocol)
 Constructor.

 ~basic_socket_connector ()
 Destructor.

demuxer_typedemuxer ()
 Get the demuxer associated with the asynchronous object.

void open ()
 Open the connector.

template<typename Protocol> void open (const Protocol &protocol)
 Open the connector to use a specified protocol.

void close ()
 Close the connector.

impl_type impl ()
 Get the underlying implementation in the native type.

template<typename Stream, typename Address> void connect (Stream &peer_socket, const Address &peer_address)
 Connect a stream socket to the peer at the specified address.

template<typename Stream, typename Address, typename Error_Handler> void connect (Stream &peer_socket, const Address &peer_address, Error_Handler error_handler)
 Connect a stream socket to the peer at the specified address.

template<typename Stream, typename Address, typename Handler> void async_connect (Stream &peer_socket, const Address &peer_address, Handler handler)
 Start an asynchronous connect.

template<typename Stream, typename Address, typename Handler, typename Completion_Context> void async_connect (Stream &peer_socket, const Address &peer_address, Handler handler, Completion_Context context)
 Start an asynchronous connect.


Private Attributes

service_typeservice_
 The backend service implementation.

impl_type impl_
 The underlying native implementation.


Detailed Description

template<typename Service>
class asio::basic_socket_connector< Service >

The basic_socket_connector class template is used to connect a socket to a remote endpoint. Most applications will use the socket_connector typedef.


Member Typedef Documentation

typedef Service service_type
 

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

typedef service_type::impl_type impl_type
 

The native implementation type of the socket connector.

typedef service_type::demuxer_type demuxer_type
 

The demuxer type for this asynchronous type.


Constructor & Destructor Documentation

basic_socket_connector demuxer_type d  )  [explicit]
 

Constructor.

Constructs the connector and opens it automatically.

Parameters:
d The demuxer object that the connector will use to deliver completions for any asynchronous operations performed on the connector.

basic_socket_connector demuxer_type d,
const Protocol &  protocol
 

Constructor.

This constructor automatically opens the connector so that it will establish connections using the specified protocol.

Parameters:
d The demuxer object that the connector will use to deliver completions for any asynchronous operations performed on the connector.
protocol The protocol to be used for all new connections established using the connector.

~basic_socket_connector  ) 
 

Destructor.


Member Function Documentation

demuxer_type& demuxer  ) 
 

Get the demuxer associated with the asynchronous object.

This function may be used to obtain the demuxer object that the connector uses to deliver completions for asynchronous operations.

Returns:
A reference to the demuxer object that the connector will use to deliver completion notifications. Ownership is not transferred to the caller.

void open  ) 
 

Open the connector.

This function is used to open the connector so that it may be used to perform socket connect operations.

Since the constructor opens the connector by default, you should only need to call this function if there has been a prior call to close().

Exceptions:
socket_error Thrown on failure.

void open const Protocol &  protocol  ) 
 

Open the connector to use a specified protocol.

This function is used to open the connector so that it may be used to perform socket connect operations.

Since the constructor opens the connector by default, you should only need to call this function if there has been a prior call to close().

Parameters:
protocol The protocol to be used for all new connections established using the connector.
Exceptions:
socket_error Thrown on failure.

void close  ) 
 

Close the connector.

This function is used to close the connector. Any asynchronous connect operations will be cancelled immediately.

A subsequent call to open() is required before the connector can again be used to again perform socket connect operations.

impl_type impl  ) 
 

Get the underlying implementation in the native type.

This function may be used to obtain the underlying implementation of the socket connector. This is intended to allow access to native socket functionality that is not otherwise provided.

void connect Stream &  peer_socket,
const Address &  peer_address
 

Connect a stream socket to the peer at the specified address.

This function is used to connect a stream socket to the specified remote address. The function call will block until the connection is successfully made or an error occurs.

Parameters:
peer_socket The stream socket to be connected.
peer_address The remote address of the peer to which the socket will be connected.
Exceptions:
socket_error Thrown on failure.

void connect Stream &  peer_socket,
const Address &  peer_address,
Error_Handler  error_handler
 

Connect a stream socket to the peer at the specified address.

This function is used to connect a stream socket to the specified remote address. The function call will block until the connection is successfully made or an error occurs.

Parameters:
peer_socket The stream socket to be connected.
peer_address The remote address of the peer to which the socket will be connected.
error_handler The handler to be called when an error occurs. Copies will be made of the handler as required. The equivalent function signature of the handler must be:
 void error_handler(
   const asio::socket_error& error // Result of operation
 ); 

void async_connect Stream &  peer_socket,
const Address &  peer_address,
Handler  handler
 

Start an asynchronous connect.

This function is used to asynchronously connect a stream socket to the specified remote address. The function call always returns immediately.

Parameters:
peer_socket The stream socket to be connected. Ownership of the peer_socket object is retained by the caller, which must guarantee that it is valid until the handler is called.
peer_address The remote address of the peer to which the socket will be connected. Copies will be made of the address as required.
handler The completion handler to be called when the connection operation completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be:
 void handler(
   const asio::socket_error& error // Result of operation
 ); 

void async_connect Stream &  peer_socket,
const Address &  peer_address,
Handler  handler,
Completion_Context  context
 

Start an asynchronous connect.

This function is used to asynchronously connect a stream socket to the specified remote address. The function call always returns immediately.

Parameters:
peer_socket The stream socket to be connected. Ownership of the peer_socket object is retained by the caller, which must guarantee that it is valid until the handler is called.
peer_address The remote address of the peer to which the socket will be connected. Copies will be made of the address as required.
handler The completion handler to be called when the connection operation completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be:
 void handler(
   const asio::socket_error& error // Result of operation
 ); 
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.


Member Data Documentation

service_type& service_ [private]
 

The backend service implementation.

impl_type impl_ [private]
 

The underlying native implementation.