Mistake on this page? Email us
M2MConnectionHandler Class Reference

#include <m2mconnectionhandler.h>

Public Types

enum  ConnectionError {
  ERROR_NONE = 0, ERROR_GENERIC = -1, CONNECTION_ERROR_WANTS_READ = -2, CONNECTION_ERROR_WANTS_WRITE = -3,
  SSL_PEER_CLOSE_NOTIFY = -4, MEMORY_ALLOCATION_FAILED = -5, SSL_CONNECTION_ERROR = -6, SOCKET_READ_ERROR = -7,
  SOCKET_SEND_ERROR = -8, SOCKET_ABORT = -9, DNS_RESOLVING_ERROR = -10, SSL_HANDSHAKE_ERROR = -11,
  FAILED_TO_READ_CREDENTIALS = -12, SOCKET_TIMEOUT = -13
}
 
enum  SocketPriority { DEFAULT_PRIORITY = 0, HIGH_PRIORITY = 10, ALERT_PRIORITY = 46 }
 

Public Member Functions

 M2MConnectionHandler (M2MConnectionObserver &observer, M2MConnectionSecurity *sec, M2MInterface::BindingMode mode, M2MInterface::NetworkStack stack)
 Constructor.
 
 ~M2MConnectionHandler ()
 Destructor.
 
bool bind_connection (const uint16_t listen_port)
 This binds the socket connection. More...
 
bool resolve_server_address (const String &server_address, const uint16_t server_port, M2MConnectionObserver::ServerType server_type, const M2MSecurity *security, bool is_server_ping=false)
 This resolves the server address. The output is returned through a callback. More...
 
bool send_data (uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr)
 Sends data to the connected server. More...
 
bool start_listening_for_data ()
 Listens to the incoming data from a remote server. More...
 
void stop_listening ()
 Stops listening to the incoming data.
 
void force_close ()
 Closes the open connection. More...
 
void handle_connection_error (int error)
 Error handling for DTLS connectivity. More...
 
void set_platform_network_handler (void *handler=NULL)
 Sets the network interface handler that is used by the client to connect to a network over IP. More...
 
void claim_mutex ()
 Claims mutex to prevent thread clashes in multithreaded environment.
 
void release_mutex ()
 Releases mutex to prevent thread clashes in multithreaded environment.
 
void unregister_network_handler ()
 Unregisters the network interface handler that is set in 'set_platform_network_handler'.
 
bool set_socket_priority (M2MConnectionHandler::SocketPriority priority)
 Set socket priority. More...
 
void store_cid ()
 Stores CID persistently for DTLS connections.
 
void remove_cid ()
 Removes CID for DTLS connections.
 
bool is_cid_available ()
 Status of CID availability in client. More...
 
void set_cid_value (const uint8_t *data_ptr, const size_t data_len)
 Internal test function. Set CID for current tls session. More...
 

Friends

class Test_M2MConnectionHandler
 
class Test_M2MConnectionHandler_mbed
 
class Test_M2MConnectionHandler_linux
 
class M2MConnection_TestObserver
 

Detailed Description

This class handles the socket connection for the LWM2M Client.

Member Enumeration Documentation

This enum defines an error that can come from the socket read and write operation.

This enum defines priority for the socket. Used for setting traffic class socket option.

Member Function Documentation

bool M2MConnectionHandler::bind_connection ( const uint16_t  listen_port)

This binds the socket connection.

Parameters
listen_portThe port to be listened to for an incoming connection.
Returns
True if successful, else false.
void M2MConnectionHandler::force_close ( )

Closes the open connection.

Note
This must be called from the same event loop context!
void M2MConnectionHandler::handle_connection_error ( int  error)

Error handling for DTLS connectivity.

Parameters
errorAn error code from the TLS library.
bool M2MConnectionHandler::is_cid_available ( )

Status of CID availability in client.

Returns
true if CID is available else false.
bool M2MConnectionHandler::resolve_server_address ( const String &  server_address,
const uint16_t  server_port,
M2MConnectionObserver::ServerType  server_type,
const M2MSecurity security,
bool  is_server_ping = false 
)

This resolves the server address. The output is returned through a callback.

Parameters
StringThe server address.
uint16_tThe server port.
ServerTypeThe server type to be resolved.
securityThe M2MSecurity object that determines which type of secure connection is used by the socket.
is_server_pingDefines whether the call is for Server ping or not.
Returns
True if the address is valid, else false.
bool M2MConnectionHandler::send_data ( uint8_t *  data_ptr,
uint16_t  data_len,
sn_nsdl_addr_s *  address_ptr 
)

Sends data to the connected server.

Parameters
data_ptrThe data to be sent.
data_lenThe length of data to be sent.
address_ptrThe address structure to which the data needs to be sent.
Returns
True if data is sent successfully, else false.
void M2MConnectionHandler::set_cid_value ( const uint8_t *  data_ptr,
const size_t  data_len 
)

Internal test function. Set CID for current tls session.

Parameters
data_ptrCID
data_lenlength of the CID
void M2MConnectionHandler::set_platform_network_handler ( void *  handler = NULL)

Sets the network interface handler that is used by the client to connect to a network over IP.

Parameters
handlerA network interface handler that is used by the client to connect. This API is optional but it provides a mechanism for different platforms to manage the usage of underlying network interface by client.
bool M2MConnectionHandler::set_socket_priority ( M2MConnectionHandler::SocketPriority  priority)

Set socket priority.

Returns
true if socket option was set correctly.
bool M2MConnectionHandler::start_listening_for_data ( )

Listens to the incoming data from a remote server.

Returns
True if successful, else false.

The documentation for this class was generated from the following file: