libcoap  4.2.0
coap_io.c File Reference
#include "coap_config.h"
#include <errno.h>
#include "libcoap.h"
#include "coap_debug.h"
#include "mem.h"
#include "net.h"
#include "coap_io.h"
#include "pdu.h"
#include "utlist.h"
#include "resource.h"
+ Include dependency graph for coap_io.c:

Go to the source code of this file.

Data Structures

struct  in6_pktinfo
 
struct  in_pktinfo
 

Macros

#define SOL_IP   IPPROTO_IP
 
#define UNUSED_PARAM
 
#define iov_len_t   size_t
 
#define SIN6(A)   ((struct sockaddr_in6 *)(A))
 

Functions

void coap_free_endpoint (coap_endpoint_t *ep)
 
static const char * coap_socket_format_errno (int error)
 
struct coap_endpoint_tcoap_malloc_endpoint (void)
 
void coap_mfree_endpoint (struct coap_endpoint_t *ep)
 
int coap_socket_bind_udp (coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
 
int coap_socket_connect_tcp1 (coap_socket_t *sock, const coap_address_t *local_if, const coap_address_t *server, int default_port, coap_address_t *local_addr, coap_address_t *remote_addr)
 
int coap_socket_connect_tcp2 (coap_socket_t *sock, coap_address_t *local_addr, coap_address_t *remote_addr)
 
int coap_socket_bind_tcp (coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
 
int coap_socket_accept_tcp (coap_socket_t *server, coap_socket_t *new_client, coap_address_t *local_addr, coap_address_t *remote_addr)
 
int coap_socket_connect_udp (coap_socket_t *sock, const coap_address_t *local_if, const coap_address_t *server, int default_port, coap_address_t *local_addr, coap_address_t *remote_addr)
 
void coap_socket_close (coap_socket_t *sock)
 
ssize_t coap_socket_write (coap_socket_t *sock, const uint8_t *data, size_t data_len)
 
ssize_t coap_socket_read (coap_socket_t *sock, uint8_t *data, size_t data_len)
 
ssize_t coap_network_send (coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen)
 
void coap_packet_get_memmapped (coap_packet_t *packet, unsigned char **address, size_t *length)
 Given a packet, set msg and msg_len to an address and length of the packet's data in memory. More...
 
void coap_packet_set_addr (coap_packet_t *packet, const coap_address_t *src, const coap_address_t *dst)
 
ssize_t coap_network_read (coap_socket_t *sock, coap_packet_t *packet)
 Function interface for reading data. More...
 
unsigned int coap_write (coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
 For applications with their own message loop, send all pending retransmits and return the list of sockets with events to wait for and the next timeout The application should call coap_read, then coap_write again when any condition below is true: More...
 
int coap_run_once (coap_context_t *ctx, unsigned timeout_ms)
 
const char * coap_socket_strerror (void)
 
ssize_t coap_socket_send (coap_socket_t *sock, coap_session_t *session, const uint8_t *data, size_t data_len)
 

Macro Definition Documentation

◆ iov_len_t

#define iov_len_t   size_t

Definition at line 754 of file coap_io.c.

◆ SIN6

#define SIN6 (   A)    ((struct sockaddr_in6 *)(A))

Definition at line 909 of file coap_io.c.

◆ SOL_IP

#define SOL_IP   IPPROTO_IP

Definition at line 726 of file coap_io.c.

◆ UNUSED_PARAM

#define UNUSED_PARAM

Definition at line 732 of file coap_io.c.

Function Documentation

◆ coap_free_endpoint()

void coap_free_endpoint ( coap_endpoint_t ep)

Definition at line 901 of file coap_session.c.

◆ coap_malloc_endpoint()

struct coap_endpoint_t* coap_malloc_endpoint ( void  )

Definition at line 181 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_mfree_endpoint()

void coap_mfree_endpoint ( struct coap_endpoint_t ep)

Definition at line 186 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_network_read()

ssize_t coap_network_read ( coap_socket_t sock,
struct coap_packet_t packet 
)

Function interface for reading data.

This function returns the number of bytes that have been read, or a value less than zero on error. In case of an error, *packet is set to NULL.

Parameters
sockSocket to read data from
packetReceived packet metadata and payload. src and dst should be preset.
Returns
The number of bytes received on success, or a value less than zero on error.

Definition at line 923 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_network_send()

ssize_t coap_network_send ( coap_socket_t sock,
const coap_session_t session,
const uint8_t data,
size_t  datalen 
)

Definition at line 758 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_packet_get_memmapped()

void coap_packet_get_memmapped ( coap_packet_t packet,
unsigned char **  address,
size_t *  length 
)

Given a packet, set msg and msg_len to an address and length of the packet's data in memory.

Definition at line 912 of file coap_io.c.

+ Here is the caller graph for this function:

◆ coap_packet_set_addr()

void coap_packet_set_addr ( coap_packet_t packet,
const coap_address_t src,
const coap_address_t dst 
)

Definition at line 917 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_run_once()

int coap_run_once ( coap_context_t ctx,
unsigned  timeout_ms 
)

Definition at line 1285 of file coap_io.c.

+ Here is the call graph for this function:

◆ coap_socket_accept_tcp()

int coap_socket_accept_tcp ( coap_socket_t server,
coap_socket_t new_client,
coap_address_t local_addr,
coap_address_t remote_addr 
)

Definition at line 490 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_bind_tcp()

int coap_socket_bind_tcp ( coap_socket_t sock,
const coap_address_t listen_addr,
coap_address_t bound_addr 
)

Definition at line 413 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_bind_udp()

int coap_socket_bind_udp ( coap_socket_t sock,
const coap_address_t listen_addr,
coap_address_t bound_addr 
)

Definition at line 192 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_close()

void coap_socket_close ( coap_socket_t sock)

Definition at line 626 of file coap_io.c.

+ Here is the caller graph for this function:

◆ coap_socket_connect_tcp1()

int coap_socket_connect_tcp1 ( coap_socket_t sock,
const coap_address_t local_if,
const coap_address_t server,
int  default_port,
coap_address_t local_addr,
coap_address_t remote_addr 
)

Definition at line 268 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_connect_tcp2()

int coap_socket_connect_tcp2 ( coap_socket_t sock,
coap_address_t local_addr,
coap_address_t remote_addr 
)

Definition at line 373 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_connect_udp()

int coap_socket_connect_udp ( coap_socket_t sock,
const coap_address_t local_if,
const coap_address_t server,
int  default_port,
coap_address_t local_addr,
coap_address_t remote_addr 
)

Definition at line 527 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_format_errno()

static const char * coap_socket_format_errno ( int  error)
static

Definition at line 1385 of file coap_io.c.

+ Here is the caller graph for this function:

◆ coap_socket_read()

ssize_t coap_socket_read ( coap_socket_t sock,
uint8_t data,
size_t  data_len 
)

Definition at line 665 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_socket_send()

ssize_t coap_socket_send ( coap_socket_t sock,
coap_session_t session,
const uint8_t data,
size_t  data_len 
)

Definition at line 1396 of file coap_io.c.

+ Here is the caller graph for this function:

◆ coap_socket_strerror()

const char* coap_socket_strerror ( void  )

Definition at line 1390 of file coap_io.c.

+ Here is the caller graph for this function:

◆ coap_socket_write()

ssize_t coap_socket_write ( coap_socket_t sock,
const uint8_t data,
size_t  data_len 
)

Definition at line 635 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_write()

unsigned int coap_write ( coap_context_t ctx,
coap_socket_t sockets[],
unsigned int  max_sockets,
unsigned int *  num_sockets,
coap_tick_t  now 
)

For applications with their own message loop, send all pending retransmits and return the list of sockets with events to wait for and the next timeout The application should call coap_read, then coap_write again when any condition below is true:

  • data is available on any of the sockets with the COAP_SOCKET_WANT_READ
  • an incoming connection is pending in the listen queue and the COAP_SOCKET_WANT_ACCEPT flag is set
  • at least some data can be written without blocking on any of the sockets with the COAP_SOCKET_WANT_WRITE flag set
  • a connection event occured (success or failure) and the COAP_SOCKET_WANT_CONNECT flag is set
  • the timeout has expired Before calling coap_read or coap_write again, the application should position COAP_SOCKET_CAN_READ and COAP_SOCKET_CAN_WRITE flags as applicable.
Parameters
ctxThe CoAP context
socketsarray of socket descriptors, filled on output
max_socketssize of socket array.
num_socketspointer to the number of valid entries in the socket arrays on output
nowCurrent time.
Returns
timeout as maxmimum number of milliseconds that the application should wait for network events or 0 if the application should wait forever.

Definition at line 1117 of file coap_io.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: