AWS IoT C++ SDK
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes
awsiotsdk::NetworkConnection Class Referenceabstract

Network Connection Class. More...

#include <NetworkConnection.hpp>

Public Member Functions

virtual bool IsConnected ()=0
 Check if Network layer is still connected. More...
 
virtual bool IsPhysicalLayerConnected ()=0
 Check if Network Physical layer is still connected. More...
 
virtual ResponseCode Connect () final
 Create a Network socket and open the connection. More...
 
virtual ResponseCode Write (const util::String &buf, size_t &size_written_bytes_out) final
 Write bytes to the network socket. More...
 
virtual ResponseCode Read (util::Vector< unsigned char > &buf, size_t buf_read_offset, size_t size_bytes_to_read, size_t &size_read_bytes_out) final
 Read bytes from the network socket. More...
 
virtual ResponseCode Disconnect () final
 Disconnect from network socket. More...
 

Protected Member Functions

virtual ResponseCode ConnectInternal ()=0
 Create a Network socket and open the connection. More...
 
virtual ResponseCode WriteInternal (const util::String &buf, size_t &size_written_bytes_out)=0
 Write bytes to the network socket. More...
 
virtual ResponseCode ReadInternal (util::Vector< unsigned char > &buf, size_t buf_read_offset, size_t size_bytes_to_read, size_t &size_read_bytes_out)=0
 Read bytes from the network socket. More...
 
virtual ResponseCode DisconnectInternal ()=0
 Disconnect from network socket. More...
 

Protected Attributes

std::mutex read_mutex
 Mutex for synchronizing read operations. More...
 
std::mutex write_mutex
 Mutex for synchronizing write operations.
 

Detailed Description

Defines an interface to the Network layer to be used by the MQTT client. Starting point for porting the SDK to the networking layer of a new platform.

This is an abstract class and cannot be instantiated.

Member Function Documentation

◆ Connect()

ResponseCode awsiotsdk::NetworkConnection::Connect ( )
finalvirtual

Calls the internal connect function after obtaining read and write locks

Returns
ResponseCode - successful connection or Network error

◆ ConnectInternal()

virtual ResponseCode awsiotsdk::NetworkConnection::ConnectInternal ( )
protectedpure virtual

Internal implementation of the Connect function to be provided by the derived class

Creates an open socket connection including Network handshake.

Returns
ResponseCode - successful connection or Network error

◆ Disconnect()

ResponseCode awsiotsdk::NetworkConnection::Disconnect ( )
finalvirtual

Calls the internal disconnect function after obtaining read and write locks This will be called by the SDK for both manual and auto-disconnect. It separates the Disconnect logic from destroy, Network stack is NOT destroyed by this API SDK should still be able to reconnect after Disconnect, but not after Destroy

Returns
ResponseCode - successful read or Network error code

◆ DisconnectInternal()

virtual ResponseCode awsiotsdk::NetworkConnection::DisconnectInternal ( )
protectedpure virtual

Internal implementation of the Disconnect function to be provided by the derived class

Returns
ResponseCode - successful read or Network error code

◆ IsConnected()

virtual bool awsiotsdk::NetworkConnection::IsConnected ( )
pure virtual

Called to check if the Network layer is still connected or not.

Returns
ResponseCode - Network error code indicating status of network physical layer connection

◆ IsPhysicalLayerConnected()

virtual bool awsiotsdk::NetworkConnection::IsPhysicalLayerConnected ( )
pure virtual

Called to check if the Network Physical layer is still connected or not.

Returns
bool - indicating status of network physical layer connection

◆ Read()

ResponseCode awsiotsdk::NetworkConnection::Read ( util::Vector< unsigned char > &  buf,
size_t  buf_read_offset,
size_t  size_bytes_to_read,
size_t &  size_read_bytes_out 
)
finalvirtual

Calls the internal read function after obtaining read lock

Parameters
util::String- reference to buffer where read bytes should be copied
size_t- number of bytes to read
size_t- reference to store number of bytes read
Returns
ResponseCode - successful read or Network error code

◆ ReadInternal()

virtual ResponseCode awsiotsdk::NetworkConnection::ReadInternal ( util::Vector< unsigned char > &  buf,
size_t  buf_read_offset,
size_t  size_bytes_to_read,
size_t &  size_read_bytes_out 
)
protectedpure virtual

Internal implementation of the Read function to be provided by the derived class

Parameters
util::String- reference to buffer where read bytes should be copied
size_t- number of bytes to read
size_t- reference to store number of bytes read
Returns
ResponseCode - successful read or Network error code

◆ Write()

ResponseCode awsiotsdk::NetworkConnection::Write ( const util::String &  buf,
size_t &  size_written_bytes_out 
)
finalvirtual

Calls the internal write function after obtaining write lock

Parameters
util::String- const reference to buffer which should be written to socket
Returns
size_t - number of bytes written or Network error
ResponseCode - successful write or Network error code

◆ WriteInternal()

virtual ResponseCode awsiotsdk::NetworkConnection::WriteInternal ( const util::String &  buf,
size_t &  size_written_bytes_out 
)
protectedpure virtual

Internal implementation of the Write function to be provided by the derived class

Parameters
util::String- const reference to buffer which should be written to socket
Returns
size_t - number of bytes written
ResponseCode - successful write or Network error code

Field Documentation

◆ read_mutex

std::mutex awsiotsdk::NetworkConnection::read_mutex
protected

Both the below mutexes must be locked before connect/disconnect