23#ifndef _MINIOS_NET_NET_SOCKET_H_
24#define _MINIOS_NET_NET_SOCKET_H_
29#define SOCK_PROTO_UDP 0
30#define SOCK_PROTO_TCP 1
31#define SOCK_PROTO_RAW 2
33#define NET_SOCK_RX_BUF_SIZE 1500
34#define NET_SOCK_POOL_SIZE 4
35#define NET_SOCK_RX_RING_SLOTS 2
net_sock_t * net_sock_alloc(int proto)
Allocate a socket from the static pool.
Definition net_socket.c:49
struct net_sock_rx_entry net_sock_rx_entry_t
One slot in the socket rx ring.
#define NET_SOCK_RX_RING_SLOTS
Definition net_socket.h:35
static int net_sock_has_data(const net_sock_t *s)
Returns non-zero when the socket rx ring has at least one entry ready.
Definition net_socket.h:73
struct net_sock net_sock_t
Kernel socket state.
void net_sock_free(net_sock_t *sock)
Free a socket slot back to the pool. Calls raw_remove/udp_remove/tcp_abort based on sock->proto befor...
Definition net_socket.c:69
int net_sock_close(net_sock_t *sock)
Close socket: remove lwIP PCB and free pool slot.
Definition net_socket.c:162
static int net_sock_ring_full(const net_sock_t *s)
Returns non-zero when the socket rx ring is full (all slots occupied).
Definition net_socket.h:80
int net_sock_send(net_sock_t *sock, const void *buf, size_t len, int flags)
Send data through socket.
Definition net_socket.c:123
int net_sock_recv(net_sock_t *sock, void *buf, size_t len, int flags)
Receive data from socket into buf.
Definition net_socket.c:101
#define NET_SOCK_RX_BUF_SIZE
Definition net_socket.h:33
One slot in the socket rx ring.
Definition net_socket.h:42
uint32_t addr_be
Definition net_socket.h:45
uint16_t _pad
Definition net_socket.h:47
uint8_t buf[NET_SOCK_RX_BUF_SIZE]
Definition net_socket.h:43
size_t len
Definition net_socket.h:44
uint16_t port_be
Definition net_socket.h:46
Kernel socket state.
Definition net_socket.h:57
uint8_t rx_head
Definition net_socket.h:61
uint32_t rcvtimeo_ticks
Definition net_socket.h:64
uint32_t poll_waiter_tid
Definition net_socket.h:67
int in_use
Definition net_socket.h:66
void * pcb
Definition net_socket.h:59
uint8_t _pad2[2]
Definition net_socket.h:63
int connected
Definition net_socket.h:65
net_sock_rx_entry_t rx_ring[NET_SOCK_RX_RING_SLOTS]
Definition net_socket.h:60
uint8_t rx_tail
Definition net_socket.h:62
int proto
Definition net_socket.h:58
unsigned short uint16_t
Definition types.h:31
unsigned int uint32_t
Definition types.h:34
unsigned char uint8_t
Definition types.h:28
uint16_t flags
Definition virtio_net.c:2
uint32_t len
Definition virtio_net.c:1