13typedef struct rte_protocol_udp_state_s
24static rte_status_t udp_adapter_open(
void *storage,
size_t storage_size,
34 if ((storage == NULL) || (config == NULL) || (out_handle == NULL))
47 if ((ops == NULL) || (ops->
open == NULL) || (ops->
close == NULL))
55 state->os_sockets = ops;
56 state->config = *config;
72 (void)ops->
close(sock);
80 if (ops->
bind == NULL)
82 (void)ops->
close(sock);
86 status = ops->
bind(sock, config->
host[0] !=
'\0' ? config->
host : NULL, config->
port);
89 (void)ops->
close(sock);
101 state->is_connected =
true;
106 state->peer_port = config->
port;
107 state->peer_known =
true;
113 state->peer_port = config->
port;
114 state->peer_known = (config->
port > 0U);
127 uint32_t revents = 0U;
130 if ((state == NULL) || (data == NULL) || (size == 0U))
139 ops = state->os_sockets;
145 if (ops->
poll != NULL)
158 if (state->is_connected && (ops->
send != NULL))
160 return ops->
send(state->sock, data, size, &sent);
162 else if (state->peer_known && (ops->
sendto != NULL))
164 return ops->
sendto(state->sock, data, size, state->peer_host, state->peer_port, &sent);
178 uint32_t revents = 0U;
181 if ((state == NULL) || (out_buf == NULL) || (buffer_size == 0U))
190 ops = state->os_sockets;
196 if (ops->
poll != NULL)
209 if (state->is_connected && (ops->
recv != NULL))
211 return ops->
recv(state->sock, out_buf, buffer_size, &recvd);
215 status = ops->
recvfrom(state->sock, out_buf, buffer_size,
216 state->peer_host,
sizeof(state->peer_host),
217 &state->peer_port, &recvd);
220 state->peer_known =
true;
237 if ((state->os_sockets != NULL) && (state->os_sockets->
close != NULL))
239 (void)state->os_sockets->
close(state->sock);
242 state->is_connected =
false;
const rte_os_socket_ops_t * rte_osadapter_get_socket_ops(void)
Retrieves the active OSAdapter's raw socket operations.
intptr_t rte_os_socket_handle_t
Socket handle representation (pointer or file descriptor).
#define RTE_OS_SOCKET_INVALID_HANDLE
Invalid socket handle sentinel.
@ RTE_OS_SOCKET_EVENT_WRITE
@ RTE_OS_SOCKET_EVENT_READ
#define RTE_PROTOCOL_ENDPOINT_STR_MAX
Maximum length of host, topic, or endpoint string.
const rte_protocol_adapter_ops_t * rte_protocol_adapter_get_udp(void)
Returns the built-in raw UDP ProtocolAdapter vtable.
struct rte_protocol_impl_s * rte_protocol_handle_t
Opaque protocol handle pointer.
@ RTE_PROTOCOL_ROLE_CONNECT
@ RTE_PROTOCOL_ROLE_LISTEN
rte_status_t
Common result/status codes.
@ RTE_STATUS_INVALID_STATE
@ RTE_STATUS_INVALID_PARAM
@ RTE_STATUS_NOT_SUPPORTED
@ RTE_STATUS_NOT_INITIALIZED
@ RTE_STATUS_RESOURCE_EXHAUSTED
uint32_t rte_duration_ms_t
Thin, MISRA-visible wrappers over the three raw memory-block primitives (fill/copy/compare) every oth...
static void rte_mem_copy(void *dest, const void *src, size_t count)
Copies count bytes from src to dest - the one sanctioned call site for libc memcpy() in this framewor...
static void rte_mem_set(void *dest, int value, size_t count)
Fills count bytes starting at dest with value - the one sanctioned call site for libc memset() in thi...
Communication Protocol Adapter Interface (UDP, TCP, DDS).
Vtable of low-level OS socket operations implemented by an OSAdapter.
rte_status_t(*) open(rte_os_socket_type_t type, rte_os_socket_handle_t *out_handle)
Creates a raw socket of the specified type, non-blocking from creation (REQ-OAL-SOCKET-001,...
rte_status_t(*) recv(rte_os_socket_handle_t handle, void *buf, size_t len, size_t *out_recv)
Receives data from a connected socket.
rte_status_t(*) sendto(rte_os_socket_handle_t handle, const void *buf, size_t len, const char *host, uint16_t port, size_t *out_sent)
Sends a datagram to a specific remote host and port.
rte_status_t(*) recvfrom(rte_os_socket_handle_t handle, void *buf, size_t len, char *out_host, size_t host_len, uint16_t *out_port, size_t *out_recv)
Receives a datagram and captures sender endpoint.
rte_status_t(*) set_nonblocking(rte_os_socket_handle_t handle, bool nonblocking)
Configures non-blocking mode on socket.
rte_status_t(*) connect(rte_os_socket_handle_t handle, const char *host, uint16_t port)
Connects a socket to a remote host and port.
rte_status_t(*) bind(rte_os_socket_handle_t handle, const char *host, uint16_t port)
Binds a socket to a local host and port.
rte_status_t(*) poll(rte_os_socket_handle_t handle, uint32_t events, rte_duration_ms_t timeout_ms, uint32_t *out_revents)
Polls a socket for I/O readiness with timeout.
rte_status_t(*) send(rte_os_socket_handle_t handle, const void *buf, size_t len, size_t *out_sent)
Sends data on a connected socket.
rte_status_t(*) close(rte_os_socket_handle_t handle)
Closes a socket handle.
Operations vtable implemented by a concrete ProtocolAdapter.
Configuration passed to open a protocol adapter instance.
uint16_t port
Port (UDP/TCP).
char host[RTE_PROTOCOL_ENDPOINT_STR_MAX]
Host address (UDP/TCP) or domain partition.