VLCB SDK
An opinionated SDK for VLCB protocol
Loading...
Searching...
No Matches
socket.c
Go to the documentation of this file.
1#include "vlcb/net/socket.h"
2
3#include <assert.h>
4#include <stdbool.h>
5
7 size_t size) {
8 assert(list != NULL);
9
10 return (VlcbNetSocketList){
11 .capacity = size,
12 .buf = list,
13 .len = 0,
14 };
15}
16
19 assert(list != NULL);
20
21 if (list->len < list->capacity - 1) {
22 return 1;
23 }
24
25 list->buf[list->len++] = sock;
26 return 0;
27}
28
31 assert(list != NULL);
32 return (VlcbNetSocketListIter){
33 .list = list,
34 .pointer = 0,
35 };
36}
37
39 assert(iter != NULL);
40 iter->pointer = 0;
41}
42
44 assert(iter != NULL);
45
46 return iter->pointer < (iter->list->len - 1);
47}
48
51 assert(iter != NULL && vlcb_net_sock_list_iter_HasNext(iter));
52
53 return iter->list->buf[iter->pointer++];
54}
55
58
59 switch (err) {
61 return "socket rx buffer is full, dropping packet";
62 }
63 assert(false /* unhandled case guard */);
64}
const char *const vlcb_error
Definition error.h:3
int vlcb_net_sock_list_Insert(VlcbNetSocketList *const list, VlcbNetSocketHandle sock)
Definition socket.c:17
bool vlcb_net_sock_list_iter_HasNext(VlcbNetSocketListIter *const iter)
Definition socket.c:43
VlcbNetSocketList vlcb_net_sock_list_New(VlcbNetSocketHandle *const list, size_t size)
Definition socket.c:6
VlcbNetSocketHandle vlcb_net_sock_list_iter_Next(VlcbNetSocketListIter *const iter)
Definition socket.c:50
vlcb_error vlcb_net_sock_ProcessErrToStr(VlcbNetSocketProcessErr err)
Definition socket.c:56
VlcbNetSocketListIter vlcb_net_sock_list_GetIterator(const VlcbNetSocketList *const list)
Definition socket.c:30
void vlcb_net_sock_list_iter_Reset(VlcbNetSocketListIter *const iter)
Definition socket.c:38
VlcbNetSocketProcessErr
Definition socket.h:10
@ VLCB_NET_SOCK_PROC_ERR_RX_BUF_FULL
Definition socket.h:13
@ VLCB_NET_SOCK_PROC_ERR_OK
Definition socket.h:11
@ VLCB_NET_SOCK_PROC_ERR_COUNT
Definition socket.h:17
IVlcbNetSocket * VlcbNetSocketHandle
Definition socket.h:41
const VlcbNetSocketList *const list
Definition socket.h:61
size_t capacity
Definition socket.h:44
VlcbNetSocketHandle *const buf
Definition socket.h:46