VLCB SDK
An opinionated SDK for VLCB protocol
Loading...
Searching...
No Matches
socket/datagram.c
Go to the documentation of this file.
2
3#include <assert.h>
4#include <stdbool.h>
5#include <stddef.h>
6
7#include "vlcb/net/addr.h"
10#include "vlcb/net/socket.h"
13
15 return proto == VLCB_NET_PROTO_DATAGRAM;
16}
17
19 const VlcbNetPacket *const packet) {
20 assert(self != NULL && packet != NULL &&
21 packet->proto == VLCB_NET_PROTO_DATAGRAM && self->rxBuf != NULL);
22
23 VlcbNetPacketDatagram dgramPacket;
25 packet->opc, packet->payload_len, &packet->payload, &dgramPacket);
27 switch (err) {
30 default:
32 }
33 }
34
35 int res = vlcb_net_packetbuf_Push(self->rxBuf, &dgramPacket);
36 if (res == -1) {
38 }
39
41}
42
44 VlcbNetPacket *const packet) {
45 assert(self != NULL && packet != NULL && self->txBuf != NULL);
46
47 VlcbNetPacketDatagram dgramPacket;
48 int res = vlcb_net_packetbuf_Pop(self->txBuf, &dgramPacket);
49 if (res == -1) {
51 }
52
54 dgramPacket.payload_len, &dgramPacket.payload,
55 packet);
56
58}
59
61 IVlcbNetSocket,
66 _INTERFACE_SELF_PTR_MUT(IVlcbNetSocket),
67 const VlcbNetPacket *const),
70 _INTERFACE_SELF_PTR_MUT(IVlcbNetSocket),
71 VlcbNetPacket *const));
72
74 VlcbPacketBuf *const txBuf) {
75 assert(rxBuf != NULL && txBuf != NULL);
76 return (VlcbNetSocketDatagram){_INTERFACE_ASSIGN_VTABLE(IVlcbNetSocket),
77 .rxBuf = rxBuf, .txBuf = txBuf};
78}
79
82 const VlcbNetPacketDatagram *const packet) {
83 assert(sock != NULL && packet != NULL && sock->txBuf != NULL);
84
85 int res = vlcb_net_packetbuf_Push(sock->txBuf, packet);
86 if (res == -1) {
88 }
90}
91
94 VlcbNetPacketDatagram *const packet) {
95 assert(sock != NULL && packet != NULL && sock->rxBuf != NULL);
96 int res = vlcb_net_packetbuf_Pop(sock->rxBuf, packet);
97 if (res == -1) {
99 }
101}
102
105 assert(sock != NULL && sock->rxBuf != NULL && sock->txBuf != NULL);
106
110 }
111
115 }
116}
#define _INTERFACE_ASSIGN_VTABLE(T)
Definition interface.h:24
#define _INTERFACE_VTABLE_METHOD(m, ptr, retT,...)
Definition interface.h:21
#define _INTERFACE_SELF_PTR_MUT(T)
Definition interface.h:16
#define _INTERFACE_VTABLE_DEFINE(T,...)
Definition interface.h:20
VlcbNetPacketDatagramConstructErr vlcb_net_pkt_dgram_New(VlcbOpCode opc, uint8_t payload_len, const VlcbNetDatagramPayload *const payload, VlcbNetPacketDatagram *const packet)
VlcbNetPacketDatagramConstructErr
@ VLCB_DGRAM_PKT_CONSTRUCT_ERR_PAYLOAD_TOO_LARGE
@ VLCB_DGRAM_PKT_CONSTRUCT_ERR_OK
int vlcb_net_packetbuf_Pop(VlcbPacketBuf *const c, void *data)
Definition packet_buf.c:82
void vlcb_net_packetbuf_Reset(VlcbPacketBuf *const c)
Definition packet_buf.c:16
int vlcb_net_packetbuf_Push(VlcbPacketBuf *const c, const void *data)
Definition packet_buf.c:62
VlcbNetSocketDgramRecvErr vlcb_net_sock_dgram_Recv(VlcbNetSocketDatagram *const sock, VlcbNetPacketDatagram *const packet)
VlcbNetSocketDispatchErr DispatchPacket(const VlcbNetSocketDatagram *const self, VlcbNetPacket *const packet)
VlcbNetSocketDatagram vlcb_net_sock_dgram_New(VlcbPacketBuf *const rxBuf, VlcbPacketBuf *const txBuf)
VlcbNetSocketProcessErr ProcessPacket(const VlcbNetSocketDatagram *const self, const VlcbNetPacket *const packet)
VlcbNetSocketDgramSendErr vlcb_net_sock_dgram_Send(VlcbNetSocketDatagram *const sock, const VlcbNetPacketDatagram *const packet)
bool SupportsProtocol(VlcbNetProtocol proto)
void vlcb_net_sock_dgram_Flush(VlcbNetSocketDatagram *const sock, const VlcbNetSockDgramFlushMode mode)
VlcbNetSocketDgramSendErr
@ VLCB_NET_SOCK_DGRAM_SEND_ERR_OK
@ VLCB_NET_SOCK_DGRAM_SEND_ERR_BUF_FULL
VlcbNetSocketDgramRecvErr
@ VLCB_NET_SOCK_DGRAM_RECV_ERR_WOULD_BLOCK
@ VLCB_NET_SOCK_DGRAM_RECV_ERR_OK
VlcbNetSockDgramFlushMode
@ VLCB_NET_SOCK_DGRAM_FLUSH_RX
@ VLCB_NET_SOCK_DGRAM_FLUSH_TX
@ VLCB_NET_SOCK_DGRAM_FLUSH_BOTH
VlcbNetSocketProcessErr
Definition socket.h:10
@ VLCB_NET_SOCK_PROC_ERR_RX_BUF_FULL
Definition socket.h:13
@ VLCB_NET_SOCK_PROC_ERR_PAYLOAD_TOO_LARGE
Definition socket.h:14
@ VLCB_NET_SOCK_PROC_ERR_OK
Definition socket.h:11
@ VLCB_NET_SOCK_PROC_ERR_UNKNOWN
Definition socket.h:15
VlcbNetSocketDispatchErr
Definition socket.h:21
@ VLCB_NET_SOCK_DISP_ERR_OK
Definition socket.h:22
@ VLCB_NET_SOCK_DISP_ERR_WOULD_BLOCK
Definition socket.h:24
VlcbNetDatagramPayload payload
VlcbNetProtocol proto
Definition vlcb.h:34
VlcbOpCode opc
Definition vlcb.h:35
VlcbNetPayload payload
Definition vlcb.h:37
uint8_t payload_len
Definition vlcb.h:36
VlcbPacketBuf *const txBuf
VlcbPacketBuf *const rxBuf
void vlcb_net_pkt_NewUnchecked(VlcbNetProtocol proto, VlcbOpCode opc, uint8_t payload_len, const VlcbNetPayload *const payload, VlcbNetPacket *const packet)
Definition vlcb.c:28
VlcbNetProtocol
Definition vlcb.h:26
@ VLCB_NET_PROTO_DATAGRAM
Definition vlcb.h:27