otp_socket.h

Include dependency graph for otp_socket.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "7" [label="stdbool.h" tooltip="stdbool.h"]
    "4" [label="atom.h" tooltip="atom.h"]
    "10" [label="assert.h" tooltip="assert.h"]
    "15" [label="synclist.h" tooltip="synclist.h"]
    "3" [label="stdint.h" tooltip="stdint.h"]
    "5" [label="stdlib.h" tooltip="stdlib.h"]
    "29" [label="exportedfunction.h" tooltip="exportedfunction.h"]
    "28" [label="context.h" tooltip="context.h"]
    "21" [label="utils.h" tooltip="utils.h"]
    "13" [label="ets.h" tooltip="ets.h"]
    "6" [label="atom_table.h" tooltip="atom_table.h"]
    "9" [label="term_typedef.h" tooltip="term_typedef.h"]
    "22" [label="stddef.h" tooltip="stddef.h"]
    "11" [label="limits.h" tooltip="limits.h"]
    "30" [label="otp_socket_platform.h" tooltip="otp_socket_platform.h"]
    "23" [label="refc_binary.h" tooltip="refc_binary.h"]
    "19" [label="string.h" tooltip="string.h"]
    "25" [label="mailbox.h" tooltip="mailbox.h"]
    "18" [label="term.h" tooltip="term.h"]
    "8" [label="erl_nif.h" tooltip="erl_nif.h"]
    "24" [label="resources.h" tooltip="resources.h"]
    "17" [label="smp.h" tooltip="smp.h"]
    "27" [label="nifs.h" tooltip="nifs.h"]
    "2" [label="globalcontext.h" tooltip="globalcontext.h"]
    "20" [label="memory.h" tooltip="memory.h"]
    "16" [label="stdio.h" tooltip="stdio.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" fillcolor="#BFBFBF"]
    "26" [label="timer_list.h" tooltip="timer_list.h"]
    "14" [label="list.h" tooltip="list.h"]
    "12" [label="inttypes.h" tooltip="inttypes.h"]
    "4" -> "3" [dir=forward tooltip="include"]
    "4" -> "5" [dir=forward tooltip="include"]
    "15" -> "16" [dir=forward tooltip="include"]
    "15" -> "14" [dir=forward tooltip="include"]
    "15" -> "17" [dir=forward tooltip="include"]
    "29" -> "18" [dir=forward tooltip="include"]
    "28" -> "2" [dir=forward tooltip="include"]
    "28" -> "14" [dir=forward tooltip="include"]
    "28" -> "25" [dir=forward tooltip="include"]
    "28" -> "17" [dir=forward tooltip="include"]
    "28" -> "18" [dir=forward tooltip="include"]
    "28" -> "26" [dir=forward tooltip="include"]
    "21" -> "22" [dir=forward tooltip="include"]
    "21" -> "16" [dir=forward tooltip="include"]
    "21" -> "5" [dir=forward tooltip="include"]
    "13" -> "14" [dir=forward tooltip="include"]
    "13" -> "15" [dir=forward tooltip="include"]
    "13" -> "18" [dir=forward tooltip="include"]
    "6" -> "7" [dir=forward tooltip="include"]
    "6" -> "4" [dir=forward tooltip="include"]
    "9" -> "10" [dir=forward tooltip="include"]
    "9" -> "11" [dir=forward tooltip="include"]
    "9" -> "12" [dir=forward tooltip="include"]
    "9" -> "3" [dir=forward tooltip="include"]
    "23" -> "7" [dir=forward tooltip="include"]
    "23" -> "5" [dir=forward tooltip="include"]
    "23" -> "14" [dir=forward tooltip="include"]
    "23" -> "24" [dir=forward tooltip="include"]
    "25" -> "7" [dir=forward tooltip="include"]
    "25" -> "14" [dir=forward tooltip="include"]
    "25" -> "9" [dir=forward tooltip="include"]
    "25" -> "21" [dir=forward tooltip="include"]
    "18" -> "7" [dir=forward tooltip="include"]
    "18" -> "3" [dir=forward tooltip="include"]
    "18" -> "16" [dir=forward tooltip="include"]
    "18" -> "5" [dir=forward tooltip="include"]
    "18" -> "19" [dir=forward tooltip="include"]
    "18" -> "20" [dir=forward tooltip="include"]
    "18" -> "23" [dir=forward tooltip="include"]
    "18" -> "21" [dir=forward tooltip="include"]
    "18" -> "9" [dir=forward tooltip="include"]
    "8" -> "9" [dir=forward tooltip="include"]
    "24" -> "5" [dir=forward tooltip="include"]
    "24" -> "8" [dir=forward tooltip="include"]
    "24" -> "14" [dir=forward tooltip="include"]
    "24" -> "20" [dir=forward tooltip="include"]
    "17" -> "7" [dir=forward tooltip="include"]
    "27" -> "4" [dir=forward tooltip="include"]
    "27" -> "28" [dir=forward tooltip="include"]
    "27" -> "29" [dir=forward tooltip="include"]
    "2" -> "3" [dir=forward tooltip="include"]
    "2" -> "4" [dir=forward tooltip="include"]
    "2" -> "6" [dir=forward tooltip="include"]
    "2" -> "8" [dir=forward tooltip="include"]
    "2" -> "13" [dir=forward tooltip="include"]
    "2" -> "14" [dir=forward tooltip="include"]
    "2" -> "25" [dir=forward tooltip="include"]
    "2" -> "17" [dir=forward tooltip="include"]
    "2" -> "15" [dir=forward tooltip="include"]
    "2" -> "18" [dir=forward tooltip="include"]
    "2" -> "26" [dir=forward tooltip="include"]
    "20" -> "3" [dir=forward tooltip="include"]
    "20" -> "5" [dir=forward tooltip="include"]
    "20" -> "8" [dir=forward tooltip="include"]
    "20" -> "9" [dir=forward tooltip="include"]
    "20" -> "21" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "27" [dir=forward tooltip="include"]
    "1" -> "30" [dir=forward tooltip="include"]
    "26" -> "7" [dir=forward tooltip="include"]
    "26" -> "3" [dir=forward tooltip="include"]
    "26" -> "14" [dir=forward tooltip="include"]
    "14" -> "7" [dir=forward tooltip="include"]
}

This graph shows which files directly or indirectly include otp_socket.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "3" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"]
    "2" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "3" [dir=back tooltip="include"]
}

Enums

enum SocketErrors

Values:

enumerator SocketClosed = 0
enumerator SocketWouldBlock = -1
enumerator SocketOtherError = -2

Functions

const struct Nif *otp_socket_nif_get_nif(const char *nifname)
void otp_socket_init(GlobalContext *global)
bool term_to_otp_socket(term socket_term, struct SocketResource **otp_socket, Context *ctx)

Get the resource object associated with a socket term.

Parameters:
  • socket_term – the term with the socket

  • otp_socket – on output, the socket resource

  • ctx – the current context

Returns:

true in case of success

bool term_is_otp_socket(term socket_term)

Determine if a term is a socket term.

Parameters:
  • socket_term – the term to test

Returns:

true if it is a term

ssize_t socket_send(struct SocketResource *socket, const uint8_t *buf, size_t len, term dest)

Send data to a socket (without blocking)

Parameters:
  • socket – the socket resource

  • buf – buffer to send

  • len – number of bytes

  • dest – destination address or invalid term for sendto/send

Returns:

the number of written bytes or a value from SocketErrors

ssize_t socket_recv(struct SocketResource *socket, uint8_t *buf, size_t len, int flags, term *from, Heap *heap)

Read data from a socket.

Parameters:
  • socket – the socket resource

  • buf – buffer to store data

  • len – number of bytes

  • flags – flags passed to recvfrom

  • from – filled with origin address using recvfrom (can be NULL)

  • heap – heap to build the origin address term (can be NULL if from is NULL)

Returns:

the number of read bytes or a value from SocketErrors

void otp_socket_lwip_enqueue(struct LWIPEvent *event)

Enqueue an event to be processed in task context.

This function must be implemented in otp_socket_platform.c. Platforms using lwIP implementation may have lwIP callbacks coming from ISR and in such case need to implement a queue mechanism to process them in task context. GlobalContext is not always available in lwIP callbacks so platforms using a queue need a global variable. If lwIP callbacks are not called from ISR, calling handler with the event is sufficient.

Parameters:
  • event – the event to enqueue

struct LWIPEvent
#include <otp_socket.h>

Collaboration diagram for LWIPEvent:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "23" [label="SpinLock" tooltip="SpinLock"]
    "16" [label="ResourceType" tooltip="ResourceType"]
    "17" [label="Module" tooltip="Module"]
    "3" [label="ListHead" tooltip="ListHead"]
    "12" [label="HeapFragment" tooltip="HeapFragment"]
    "14" [label="RefcBinaryQueueItem" tooltip="RefcBinaryQueueItem"]
    "4" [label="GlobalContext" tooltip="GlobalContext"]
    "19" [label="ModuleFilename" tooltip="ModuleFilename"]
    "5" [label="Ets" tooltip="Ets"]
    "13" [label="HNodeGroup" tooltip="HNodeGroup"]
    "22" [label="TimerList" tooltip="TimerList"]
    "20" [label="LiteralEntry" tooltip="LiteralEntry"]
    "8" [label="MailboxMessage" tooltip="MailboxMessage"]
    "11" [label="Heap" tooltip="Heap"]
    "7" [label="MessageQueueItem" tooltip="MessageQueueItem"]
    "21" [label="AtomsHashTable" tooltip="AtomsHashTable"]
    "15" [label="RefcBinary" tooltip="RefcBinary"]
    "1" [label="LWIPEvent" tooltip="LWIPEvent" fillcolor="#BFBFBF"]
    "2" [label="SocketResource" tooltip="SocketResource"]
    "9" [label="AtomTable" tooltip="AtomTable"]
    "18" [label="ExportedFunction" tooltip="ExportedFunction"]
    "6" [label="SyncList" tooltip="SyncList"]
    "10" [label="HNode" tooltip="HNode"]
    "16" -> "4" [dir=forward tooltip="usage"]
    "16" -> "3" [dir=forward tooltip="usage"]
    "17" -> "18" [dir=forward tooltip="usage"]
    "17" -> "19" [dir=forward tooltip="usage"]
    "17" -> "20" [dir=forward tooltip="usage"]
    "17" -> "3" [dir=forward tooltip="usage"]
    "3" -> "3" [dir=forward tooltip="usage"]
    "12" -> "12" [dir=forward tooltip="usage"]
    "14" -> "15" [dir=forward tooltip="usage"]
    "14" -> "14" [dir=forward tooltip="usage"]
    "4" -> "5" [dir=forward tooltip="usage"]
    "4" -> "7" [dir=forward tooltip="usage"]
    "4" -> "9" [dir=forward tooltip="usage"]
    "4" -> "14" [dir=forward tooltip="usage"]
    "4" -> "6" [dir=forward tooltip="usage"]
    "4" -> "17" [dir=forward tooltip="usage"]
    "4" -> "21" [dir=forward tooltip="usage"]
    "4" -> "22" [dir=forward tooltip="usage"]
    "4" -> "23" [dir=forward tooltip="usage"]
    "4" -> "3" [dir=forward tooltip="usage"]
    "5" -> "6" [dir=forward tooltip="usage"]
    "13" -> "10" [dir=forward tooltip="usage"]
    "13" -> "13" [dir=forward tooltip="usage"]
    "22" -> "3" [dir=forward tooltip="usage"]
    "8" -> "8" [dir=forward tooltip="usage"]
    "11" -> "12" [dir=forward tooltip="usage"]
    "7" -> "8" [dir=forward tooltip="usage"]
    "7" -> "7" [dir=forward tooltip="usage"]
    "21" -> "10" [dir=forward tooltip="usage"]
    "15" -> "16" [dir=forward tooltip="usage"]
    "15" -> "3" [dir=forward tooltip="usage"]
    "1" -> "2" [dir=forward tooltip="usage"]
    "1" -> "4" [dir=forward tooltip="usage"]
    "2" -> "3" [dir=forward tooltip="usage"]
    "9" -> "10" [dir=forward tooltip="usage"]
    "9" -> "13" [dir=forward tooltip="usage"]
    "6" -> "3" [dir=forward tooltip="usage"]
    "10" -> "10" [dir=forward tooltip="usage"]
    "10" -> "11" [dir=forward tooltip="usage"]
}

Public Members

void (*handler)(struct LWIPEvent *event)
struct SocketResource *rsrc_obj
struct tcp_pcb *newpcb
struct LWIPEvent.[anonymous].[anonymous] tcp_accept
struct tcp_pcb *tpcb
struct pbuf *buf
err_t err
struct LWIPEvent.[anonymous].[anonymous] tcp_recv
uint32_t addr
uint16_t port
struct LWIPEvent.[anonymous].[anonymous] udp_recv
GlobalContext *global
int32_t target_pid
struct LWIPEvent.[anonymous].[anonymous] trap_answer_ok
struct LWIPEvent.[anonymous].[anonymous] trap_answer_closed
struct LWIPEvent.[anonymous].[anonymous] finalize_close
void *callback_arg
bool success
struct LWIPEvent.[anonymous].[anonymous] dns_gethostbyname
union LWIPEvent.[anonymous] [anonymous]