Skip to content

File syn_transport_udp.c

FileList > net > syn_transport_udp.c

Go to the source code of this file

Bridge implementation connecting syn_port_udp_* to native syn_udp stack.

  • #include "syntropic/net/syn_transport_udp.h"
  • #include "port/syn_port_eth.h"
  • #include "syntropic/util/syn_pack.h"
  • #include <string.h>

Public Static Attributes

Type Name
SYN_UDP * g_native_udp = NULL
uint8_t g_udp_tx_buf

Public Functions

Type Name
SYN_WEAK SYN_Socket syn_port_udp_open (uint16_t port)
Open a UDP socket bound to the given port.
SYN_WEAK int syn_port_udp_recvfrom (SYN_Socket sock, void * buf, size_t max_len, SYN_SockAddr * from, uint32_t timeout_ms)
Receive a UDP packet.
SYN_WEAK int syn_port_udp_sendto (SYN_Socket sock, const void * data, size_t len, const SYN_SockAddr * to)
Send a UDP packet to a destination address.
SYN_UDP * syn_transport_udp_get_instance (void)
Get the active native SYN_UDP stack instance.
void syn_transport_udp_set_instance (SYN_UDP * udp)
Bind native syn_udp instance to the syn_port_udp_* socket interface.

Public Static Attributes Documentation

variable g_native_udp

SYN_UDP* g_native_udp;

Global native UDP stack pointer


variable g_udp_tx_buf

uint8_t g_udp_tx_buf[SYN_ETH_MAX_FRAME_LEN];

Internal static transmission buffer


Public Functions Documentation

function syn_port_udp_open

Open a UDP socket bound to the given port.

SYN_WEAK  SYN_Socket syn_port_udp_open (
    uint16_t port
) 

Parameters:

  • port Local port to bind to, or 0 for ephemeral.

Returns:

Socket handle on success, SYN_SOCKET_INVALID on failure.


function syn_port_udp_recvfrom

Receive a UDP packet.

SYN_WEAK int syn_port_udp_recvfrom (
    SYN_Socket sock,
    void * buf,
    size_t max_len,
    SYN_SockAddr * from,
    uint32_t timeout_ms
) 

Parameters:

  • sock Socket handle.
  • buf Receive buffer.
  • max_len Buffer capacity.
  • from [out] Source address.
  • timeout_ms Receive timeout in milliseconds. If 0, must return immediately (non-blocking poll). Cooperative tasks (protothreads) rely on this to avoid blocking the scheduler. Port implementations MUST NOT treat 0 as "block forever."

Returns:

Number of bytes received, 0 if no data available (non-blocking), or -1 on error.


function syn_port_udp_sendto

Send a UDP packet to a destination address.

SYN_WEAK int syn_port_udp_sendto (
    SYN_Socket sock,
    const void * data,
    size_t len,
    const SYN_SockAddr * to
) 

Parameters:

  • sock Socket handle.
  • data Payload to send.
  • len Payload length.
  • to Destination address (IP + port).

Returns:

Number of bytes sent, or -1 on error.


function syn_transport_udp_get_instance

Get the active native SYN_UDP stack instance.

SYN_UDP * syn_transport_udp_get_instance (
    void
) 

Returns:

Pointer to SYN_UDP instance, or NULL.

Get the active native SYN_UDP stack instance.

Returns:

Pointer to global SYN_UDP instance, or NULL if unavailable.


function syn_transport_udp_set_instance

Bind native syn_udp instance to the syn_port_udp_* socket interface.

void syn_transport_udp_set_instance (
    SYN_UDP * udp
) 

Parameters:

  • udp Pointer to native SYN_UDP stack instance.


The documentation for this class was generated from the following file src/syntropic/net/syn_transport_udp.c