Google Cloud IoT device SDK for embedded C  1.0.2
iotc_bsp_io_net.h File Reference

Go to the source code of this file.

Data Structures

struct  iotc_bsp_socket_events_s
 

Typedefs

typedef enum iotc_bsp_io_net_state_e iotc_bsp_io_net_state_t
 
typedef enum iotc_bsp_socket_type_e iotc_bsp_socket_type_t
 
typedef enum iotc_bsp_protocol_type_e iotc_bsp_protocol_type_t
 
typedef intptr_t iotc_bsp_socket_t
 
typedef struct iotc_bsp_socket_events_s iotc_bsp_socket_events_t
 

Enumerations

enum  iotc_bsp_io_net_state_e {
  IOTC_BSP_IO_NET_STATE_OK = 0, IOTC_BSP_IO_NET_STATE_ERROR = 1, IOTC_BSP_IO_NET_STATE_BUSY = 2, IOTC_BSP_IO_NET_STATE_CONNECTION_RESET = 3,
  IOTC_BSP_IO_NET_STATE_TIMEOUT = 4
}
 
enum  iotc_bsp_socket_type_e { SOCKET_STREAM = 1, SOCKET_DGRAM = 2 }
 
enum  iotc_bsp_protocol_type_e { PROTOCOL_IPV4 = 2, PROTOCOL_IPV6 = 10 }
 

Functions

iotc_bsp_io_net_state_t iotc_bsp_io_net_socket_connect (iotc_bsp_socket_t *iotc_socket, const char *host, uint16_t port, iotc_bsp_socket_type_t socket_type)
 
iotc_bsp_io_net_state_t iotc_bsp_io_net_select (iotc_bsp_socket_events_t *socket_events_array, size_t socket_events_array_size, long timeout_sec)
 
iotc_bsp_io_net_state_t iotc_bsp_io_net_connection_check (iotc_bsp_socket_t iotc_socket, const char *host, uint16_t port)
 
iotc_bsp_io_net_state_t iotc_bsp_io_net_write (iotc_bsp_socket_t iotc_socket_nonblocking, int *out_written_count, const uint8_t *buf, size_t count)
 
iotc_bsp_io_net_state_t iotc_bsp_io_net_read (iotc_bsp_socket_t iotc_socket_nonblocking, int *out_read_count, uint8_t *buf, size_t count)
 
iotc_bsp_io_net_state_t iotc_bsp_io_net_close_socket (iotc_bsp_socket_t *iotc_socket_nonblocking)
 

Detailed Description

Creates and manages asynchronous sockets in the device's native socket library.

A typical networking workflow:

  1. Create a socket.
  2. Connect the socket to a host.
  3. Check the connection status.
  4. Send data to the host or read data from the socket.
  5. Close the socket.

Definition in file iotc_bsp_io_net.h.

Typedef Documentation

◆ iotc_bsp_io_net_state_t

The networking function states.

The TLS function states.

See also
iotc_bsp_io_net_state_e

◆ iotc_bsp_protocol_type_t

The version of the socket protocol.

See also
iotc_bsp_protocol_type_e

◆ iotc_bsp_socket_events_t

◆ iotc_bsp_socket_t

The socket representation.

Definition at line 190 of file iotc_bsp_io_net.h.

◆ iotc_bsp_socket_type_t

The socket protocol.

See also
iotc_bsp_socket_type_e

Enumeration Type Documentation

◆ iotc_bsp_io_net_state_e

Enumerator
IOTC_BSP_IO_NET_STATE_OK 

The networking function succeeded.

IOTC_BSP_IO_NET_STATE_ERROR 

Something went wrong.

IOTC_BSP_IO_NET_STATE_BUSY 

The resource is busy. Invoke function again.

IOTC_BSP_IO_NET_STATE_CONNECTION_RESET 

The connection was lost.

IOTC_BSP_IO_NET_STATE_TIMEOUT 

A timeout occurred.

Definition at line 144 of file iotc_bsp_io_net.h.

◆ iotc_bsp_protocol_type_e

Enumerator
PROTOCOL_IPV4 

IPv4.

PROTOCOL_IPV6 

IPv6.

Definition at line 178 of file iotc_bsp_io_net.h.

◆ iotc_bsp_socket_type_e

Enumerator
SOCKET_STREAM 

TCP socket.

SOCKET_DGRAM 

UDP socket.

Definition at line 164 of file iotc_bsp_io_net.h.

Function Documentation

◆ iotc_bsp_io_net_close_socket()

iotc_bsp_io_net_state_t iotc_bsp_io_net_close_socket ( iotc_bsp_socket_t iotc_socket_nonblocking)

Closes a socket.

Parameters
[in]iotc_socket_nonblockingThe socket to close.

◆ iotc_bsp_io_net_connection_check()

iotc_bsp_io_net_state_t iotc_bsp_io_net_connection_check ( iotc_bsp_socket_t  iotc_socket,
const char *  host,
uint16_t  port 
)

Checks a socket connection status.

The SDK calls the function after iotc_bsp_io_net_connect() to complete the socket connection. If the socket is connected, the SDK initiates a TLS handshake.

Parameters
[in]iotc_socketThe socket on which check the connection.
[in]hostThe null-terminated IP or fully-qualified domain name of the host at which to connect.
[in]portThe port number of the endpoint.

◆ iotc_bsp_io_net_read()

iotc_bsp_io_net_state_t iotc_bsp_io_net_read ( iotc_bsp_socket_t  iotc_socket_nonblocking,
int *  out_read_count,
uint8_t *  buf,
size_t  count 
)

Reads data from a socket.

Parameters
[in]iotc_socket_nonblockingThe socket from which to read data.
[out]out_read_countThe number of bytes read from the socket.
[out]bufA pointer to a buffer with the data read from the socket.
[in]countThe size, in bytes, of the buffer to which the buf parameter points.

◆ iotc_bsp_io_net_select()

iotc_bsp_io_net_state_t iotc_bsp_io_net_select ( iotc_bsp_socket_events_t socket_events_array,
size_t  socket_events_array_size,
long  timeout_sec 
)

Checks a socket for scheduled read or write operations.

Parameters
[in]socket_events_arrayAn array of socket events.
[in]socket_events_array_sizeThe number of elements in socket_events_array.
[in]timeout_secThe number of seconds before timing out.
Returns
A networking function state.

◆ iotc_bsp_io_net_socket_connect()

iotc_bsp_io_net_state_t iotc_bsp_io_net_socket_connect ( iotc_bsp_socket_t iotc_socket,
const char *  host,
uint16_t  port,
iotc_bsp_socket_type_t  socket_type 
)

Creates a socket and connects it to an endpoint.

Parameters
[out]iotc_socketThe platform-specific socket representation This value is passed to all further BSP networking calls.
[in]hostThe null-terminated IP or fully-qualified domain name of the host at which to connect.
[in]portThe port number of the endpoint.
[in]socket_typeThe socket protocol.

◆ iotc_bsp_io_net_write()

iotc_bsp_io_net_state_t iotc_bsp_io_net_write ( iotc_bsp_socket_t  iotc_socket_nonblocking,
int *  out_written_count,
const uint8_t *  buf,
size_t  count 
)

Writes data to a socket.

This function writes data in chunks, so the SDK calls it repeatedly until all chunks are written to the buffer. The SDK writes a new chunk to the socket on each event loop tick.

Parameters
[in]iotc_socket_nonblockingThe socket on which to send data.
[out]out_written_countThe number of bytes written to the socket. If the value is negative, the connection is closed.
[in]bufA pointer to a buffer with the data.
[in]countThe size, in bytes, of the buffer to which the buf parameter points.