AsyncSocketTransport is a helper template class for AsyncTcpTransport and AsyncUnixTransport to implement common socket communication tasks using Boost's asio io_service. More...
#include <async-socket-transport.hpp>
Public Member Functions | |
AsyncSocketTransport (boost::asio::io_service &ioService) | |
Create an AsyncSocketTransport in the unconnected state. More... | |
void | connect (const typename AsioProtocol::endpoint &endPoint, ElementListener &elementListener, const Transport::OnConnected &onConnected) |
Connect according to the info in connectionInfo, and use elementListener. More... | |
void | send (const uint8_t *data, size_t dataLength) |
Set data to the host. More... | |
bool | getIsConnected () |
void | close () |
Close the connection to the host. | |
AsyncSocketTransport is a helper template class for AsyncTcpTransport and AsyncUnixTransport to implement common socket communication tasks using Boost's asio io_service.
The template class AsioProtocol should be boost::asio::ip::tcp or boost::asio::local::stream_protocol (for a Unix socket). Boost uses template classes instead of base classes with override, so we implement all methods here in the header file.
|
inline |
Create an AsyncSocketTransport in the unconnected state.
This will use the ioService to create the connection and communicate asynchronously.
ioService | The asio io_service. It is the responsibility of the application to start and stop the service. |
|
inline |
Connect according to the info in connectionInfo, and use elementListener.
To be thread-safe, this must be called from a dispatch to the ioService which was given to the constructor, as is done by ThreadsafeFace.
endPoint | The asio endpoint for the protocol containing the connection info. |
elementListener | Not a shared_ptr because we assume that it will remain valid during the life of this object. |
onConnected | This calls onConnected() when the connection is established. |
|
inline |
Set data to the host.
To be thread-safe, this must be called from a dispatch to the ioService which was given to the constructor, as is done by ThreadsafeFace.
data | A pointer to the buffer of data to send. |
dataLength | The number of bytes in data. |