$search
Provides datagram-oriented socket functionality. More...
#include <basic_datagram_socket.hpp>
Public Types | |
typedef Protocol::endpoint | endpoint_type |
The endpoint type. | |
typedef DatagramSocketService::native_type | native_type |
The native representation of a socket. | |
typedef Protocol | protocol_type |
The protocol type. | |
Public Member Functions | |
template<typename MutableBufferSequence , typename ReadHandler > | |
void | async_receive (const MutableBufferSequence &buffers, socket_base::message_flags flags, ReadHandler handler) |
Start an asynchronous receive on a connected socket. | |
template<typename MutableBufferSequence , typename ReadHandler > | |
void | async_receive (const MutableBufferSequence &buffers, ReadHandler handler) |
Start an asynchronous receive on a connected socket. | |
template<typename MutableBufferSequence , typename ReadHandler > | |
void | async_receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags, ReadHandler handler) |
Start an asynchronous receive. | |
template<typename MutableBufferSequence , typename ReadHandler > | |
void | async_receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, ReadHandler handler) |
Start an asynchronous receive. | |
template<typename ConstBufferSequence , typename WriteHandler > | |
void | async_send (const ConstBufferSequence &buffers, socket_base::message_flags flags, WriteHandler handler) |
Start an asynchronous send on a connected socket. | |
template<typename ConstBufferSequence , typename WriteHandler > | |
void | async_send (const ConstBufferSequence &buffers, WriteHandler handler) |
Start an asynchronous send on a connected socket. | |
template<typename ConstBufferSequence , typename WriteHandler > | |
void | async_send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags, WriteHandler handler) |
Start an asynchronous send. | |
template<typename ConstBufferSequence , typename WriteHandler > | |
void | async_send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, WriteHandler handler) |
Start an asynchronous send. | |
basic_datagram_socket (asio::io_service &io_service, const protocol_type &protocol, const native_type &native_socket) | |
Construct a basic_datagram_socket on an existing native socket. | |
basic_datagram_socket (asio::io_service &io_service, const endpoint_type &endpoint) | |
basic_datagram_socket (asio::io_service &io_service, const protocol_type &protocol) | |
Construct and open a basic_datagram_socket. | |
basic_datagram_socket (asio::io_service &io_service) | |
Construct a basic_datagram_socket without opening it. | |
template<typename MutableBufferSequence > | |
std::size_t | receive (const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec) |
Receive some data on a connected socket. | |
template<typename MutableBufferSequence > | |
std::size_t | receive (const MutableBufferSequence &buffers, socket_base::message_flags flags) |
Receive some data on a connected socket. | |
template<typename MutableBufferSequence > | |
std::size_t | receive (const MutableBufferSequence &buffers) |
Receive some data on a connected socket. | |
template<typename MutableBufferSequence > | |
std::size_t | receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags, asio::error_code &ec) |
Receive a datagram with the endpoint of the sender. | |
template<typename MutableBufferSequence > | |
std::size_t | receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags) |
Receive a datagram with the endpoint of the sender. | |
template<typename MutableBufferSequence > | |
std::size_t | receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint) |
Receive a datagram with the endpoint of the sender. | |
template<typename ConstBufferSequence > | |
std::size_t | send (const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec) |
Send some data on a connected socket. | |
template<typename ConstBufferSequence > | |
std::size_t | send (const ConstBufferSequence &buffers, socket_base::message_flags flags) |
Send some data on a connected socket. | |
template<typename ConstBufferSequence > | |
std::size_t | send (const ConstBufferSequence &buffers) |
Send some data on a connected socket. | |
template<typename ConstBufferSequence > | |
std::size_t | send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags, asio::error_code &ec) |
Send a datagram to the specified endpoint. | |
template<typename ConstBufferSequence > | |
std::size_t | send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags) |
Send a datagram to the specified endpoint. | |
template<typename ConstBufferSequence > | |
std::size_t | send_to (const ConstBufferSequence &buffers, const endpoint_type &destination) |
Send a datagram to the specified endpoint. |
Provides datagram-oriented socket functionality.
The basic_datagram_socket class template provides asynchronous and blocking datagram-oriented socket functionality.
Definition at line 43 of file basic_datagram_socket.hpp.
typedef Protocol::endpoint asio::basic_datagram_socket< Protocol, DatagramSocketService >::endpoint_type |
The endpoint type.
Reimplemented from asio::basic_socket< Protocol, DatagramSocketService >.
Definition at line 54 of file basic_datagram_socket.hpp.
typedef DatagramSocketService::native_type asio::basic_datagram_socket< Protocol, DatagramSocketService >::native_type |
The native representation of a socket.
Reimplemented from asio::basic_socket< Protocol, DatagramSocketService >.
Definition at line 48 of file basic_datagram_socket.hpp.
typedef Protocol asio::basic_datagram_socket< Protocol, DatagramSocketService >::protocol_type |
The protocol type.
Reimplemented from asio::basic_socket< Protocol, DatagramSocketService >.
Definition at line 51 of file basic_datagram_socket.hpp.
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket | ( | asio::io_service & | io_service | ) | [inline, explicit] |
Construct a basic_datagram_socket without opening it.
This constructor creates a datagram socket without opening it. The open() function must be called before data can be sent or received on the socket.
io_service | The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket. |
Definition at line 65 of file basic_datagram_socket.hpp.
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket | ( | asio::io_service & | io_service, | |
const protocol_type & | protocol | |||
) | [inline] |
Construct and open a basic_datagram_socket.
This constructor creates and opens a datagram socket.
io_service | The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket. | |
protocol | An object specifying protocol parameters to be used. |
asio::system_error | Thrown on failure. |
Definition at line 82 of file basic_datagram_socket.hpp.
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket | ( | asio::io_service & | io_service, | |
const endpoint_type & | endpoint | |||
) | [inline] |
Construct a basic_datagram_socket, opening it and binding it to the given local endpoint. This constructor creates a datagram socket and automatically opens it bound to the specified endpoint on the local machine. The protocol used is the protocol associated with the given endpoint.
io_service | The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket. | |
endpoint | An endpoint on the local machine to which the datagram socket will be bound. |
asio::system_error | Thrown on failure. |
Definition at line 104 of file basic_datagram_socket.hpp.
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket | ( | asio::io_service & | io_service, | |
const protocol_type & | protocol, | |||
const native_type & | native_socket | |||
) | [inline] |
Construct a basic_datagram_socket on an existing native socket.
This constructor creates a datagram socket object to hold an existing native socket.
io_service | The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket. | |
protocol | An object specifying protocol parameters to be used. | |
native_socket | The new underlying socket implementation. |
asio::system_error | Thrown on failure. |
Definition at line 125 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive | ( | const MutableBufferSequence & | buffers, | |
socket_base::message_flags | flags, | |||
ReadHandler | handler | |||
) | [inline] |
Start an asynchronous receive on a connected socket.
This function is used to asynchronously receive data from the datagram socket. The function call always returns immediately.
buffers | One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
flags | Flags specifying how the receive call is to be made. | |
handler | The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
Definition at line 621 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive | ( | const MutableBufferSequence & | buffers, | |
ReadHandler | handler | |||
) | [inline] |
Start an asynchronous receive on a connected socket.
This function is used to asynchronously receive data from the datagram socket. The function call always returns immediately.
buffers | One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
handler | The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
socket.async_receive(asio::buffer(data, size), handler);
Definition at line 587 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive_from | ( | const MutableBufferSequence & | buffers, | |
endpoint_type & | sender_endpoint, | |||
socket_base::message_flags | flags, | |||
ReadHandler | handler | |||
) | [inline] |
Start an asynchronous receive.
This function is used to asynchronously receive a datagram. The function call always returns immediately.
buffers | One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
sender_endpoint | An endpoint object that receives the endpoint of the remote sender of the datagram. Ownership of the sender_endpoint object is retained by the caller, which must guarantee that it is valid until the handler is called. | |
flags | Flags specifying how the receive call is to be made. | |
handler | The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
Definition at line 790 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive_from | ( | const MutableBufferSequence & | buffers, | |
endpoint_type & | sender_endpoint, | |||
ReadHandler | handler | |||
) | [inline] |
Start an asynchronous receive.
This function is used to asynchronously receive a datagram. The function call always returns immediately.
buffers | One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
sender_endpoint | An endpoint object that receives the endpoint of the remote sender of the datagram. Ownership of the sender_endpoint object is retained by the caller, which must guarantee that it is valid until the handler is called. | |
handler | The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
socket.async_receive_from( asio::buffer(data, size), 0, sender_endpoint, handler);
Definition at line 753 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send | ( | const ConstBufferSequence & | buffers, | |
socket_base::message_flags | flags, | |||
WriteHandler | handler | |||
) | [inline] |
Start an asynchronous send on a connected socket.
This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.
buffers | One or more data buffers to be sent on the socket. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
flags | Flags specifying how the send call is to be made. | |
handler | The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
Definition at line 287 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send | ( | const ConstBufferSequence & | buffers, | |
WriteHandler | handler | |||
) | [inline] |
Start an asynchronous send on a connected socket.
This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.
buffers | One or more data buffers to be sent on the socket. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
handler | The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
socket.async_send(asio::buffer(data, size), handler);
Definition at line 252 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send_to | ( | const ConstBufferSequence & | buffers, | |
const endpoint_type & | destination, | |||
socket_base::message_flags | flags, | |||
WriteHandler | handler | |||
) | [inline] |
Start an asynchronous send.
This function is used to asynchronously send a datagram to the specified remote endpoint. The function call always returns immediately.
buffers | One or more data buffers to be sent to the remote endpoint. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
flags | Flags specifying how the send call is to be made. | |
destination | The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required. | |
handler | The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
Definition at line 454 of file basic_datagram_socket.hpp.
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send_to | ( | const ConstBufferSequence & | buffers, | |
const endpoint_type & | destination, | |||
WriteHandler | handler | |||
) | [inline] |
Start an asynchronous send.
This function is used to asynchronously send a datagram to the specified remote endpoint. The function call always returns immediately.
buffers | One or more data buffers to be sent to the remote endpoint. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. | |
destination | The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required. | |
handler | The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const asio::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. ); Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post(). |
asio::ip::udp::endpoint destination( asio::ip::address::from_string("1.2.3.4"), 12345); socket.async_send_to( asio::buffer(data, size), destination, handler);
Definition at line 419 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive | ( | const MutableBufferSequence & | buffers, | |
socket_base::message_flags | flags, | |||
asio::error_code & | ec | |||
) | [inline] |
Receive some data on a connected socket.
This function is used to receive data on the datagram socket. The function call will block until data has been received successfully or an error occurs.
buffers | One or more buffers into which the data will be received. | |
flags | Flags specifying how the receive call is to be made. | |
ec | Set to indicate what error occurred, if any. |
Definition at line 544 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive | ( | const MutableBufferSequence & | buffers, | |
socket_base::message_flags | flags | |||
) | [inline] |
Receive some data on a connected socket.
This function is used to receive data on the datagram socket. The function call will block until data has been received successfully or an error occurs.
buffers | One or more buffers into which the data will be received. | |
flags | Flags specifying how the receive call is to be made. |
asio::system_error | Thrown on failure. |
Definition at line 515 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive | ( | const MutableBufferSequence & | buffers | ) | [inline] |
Receive some data on a connected socket.
This function is used to receive data on the datagram socket. The function call will block until data has been received successfully or an error occurs.
buffers | One or more buffers into which the data will be received. |
asio::system_error | Thrown on failure. |
socket.receive(asio::buffer(data, size));
Definition at line 487 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive_from | ( | const MutableBufferSequence & | buffers, | |
endpoint_type & | sender_endpoint, | |||
socket_base::message_flags | flags, | |||
asio::error_code & | ec | |||
) | [inline] |
Receive a datagram with the endpoint of the sender.
This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.
buffers | One or more buffers into which the data will be received. | |
sender_endpoint | An endpoint object that receives the endpoint of the remote sender of the datagram. | |
flags | Flags specifying how the receive call is to be made. | |
ec | Set to indicate what error occurred, if any. |
Definition at line 708 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive_from | ( | const MutableBufferSequence & | buffers, | |
endpoint_type & | sender_endpoint, | |||
socket_base::message_flags | flags | |||
) | [inline] |
Receive a datagram with the endpoint of the sender.
This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.
buffers | One or more buffers into which the data will be received. | |
sender_endpoint | An endpoint object that receives the endpoint of the remote sender of the datagram. | |
flags | Flags specifying how the receive call is to be made. |
asio::system_error | Thrown on failure. |
Definition at line 681 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive_from | ( | const MutableBufferSequence & | buffers, | |
endpoint_type & | sender_endpoint | |||
) | [inline] |
Receive a datagram with the endpoint of the sender.
This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.
buffers | One or more buffers into which the data will be received. | |
sender_endpoint | An endpoint object that receives the endpoint of the remote sender of the datagram. |
asio::system_error | Thrown on failure. |
asio::ip::udp::endpoint sender_endpoint; socket.receive_from( asio::buffer(data, size), sender_endpoint);
Definition at line 654 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send | ( | const ConstBufferSequence & | buffers, | |
socket_base::message_flags | flags, | |||
asio::error_code & | ec | |||
) | [inline] |
Send some data on a connected socket.
This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.
buffers | One or more data buffers to be sent on the socket. | |
flags | Flags specifying how the send call is to be made. | |
ec | Set to indicate what error occurred, if any. |
Definition at line 209 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send | ( | const ConstBufferSequence & | buffers, | |
socket_base::message_flags | flags | |||
) | [inline] |
Send some data on a connected socket.
This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.
buffers | One ore more data buffers to be sent on the socket. | |
flags | Flags specifying how the send call is to be made. |
asio::system_error | Thrown on failure. |
Definition at line 181 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send | ( | const ConstBufferSequence & | buffers | ) | [inline] |
Send some data on a connected socket.
This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.
buffers | One ore more data buffers to be sent on the socket. |
asio::system_error | Thrown on failure. |
socket.send(asio::buffer(data, size));
Definition at line 155 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send_to | ( | const ConstBufferSequence & | buffers, | |
const endpoint_type & | destination, | |||
socket_base::message_flags | flags, | |||
asio::error_code & | ec | |||
) | [inline] |
Send a datagram to the specified endpoint.
This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.
buffers | One or more data buffers to be sent to the remote endpoint. | |
destination | The remote endpoint to which the data will be sent. | |
flags | Flags specifying how the send call is to be made. | |
ec | Set to indicate what error occurred, if any. |
Definition at line 373 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send_to | ( | const ConstBufferSequence & | buffers, | |
const endpoint_type & | destination, | |||
socket_base::message_flags | flags | |||
) | [inline] |
Send a datagram to the specified endpoint.
This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.
buffers | One or more data buffers to be sent to the remote endpoint. | |
destination | The remote endpoint to which the data will be sent. | |
flags | Flags specifying how the send call is to be made. |
asio::system_error | Thrown on failure. |
Definition at line 346 of file basic_datagram_socket.hpp.
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send_to | ( | const ConstBufferSequence & | buffers, | |
const endpoint_type & | destination | |||
) | [inline] |
Send a datagram to the specified endpoint.
This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.
buffers | One or more data buffers to be sent to the remote endpoint. | |
destination | The remote endpoint to which the data will be sent. |
asio::system_error | Thrown on failure. |
asio::ip::udp::endpoint destination( asio::ip::address::from_string("1.2.3.4"), 12345); socket.send_to(asio::buffer(data, size), destination);
Definition at line 319 of file basic_datagram_socket.hpp.