When I wrote the “native” picoos-net socket API I focused mostly on simplicity and efficiency to avoid adding too much weight to uIP. Although this layer has worked well for me, it is incompatible with BSD socket API available on many platforms. Incompatibility makes re-using code from other environments like lwIP or unix/linux (or even Texas Instruments CC3000 chip) difficult. Because I wanted to use some of my Pico]OS stuff with lwIP or CC3000 also, I decided to add a simple BSD socket layer to picoos-net library.
It contains currently following functions:
int net_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int net_bind(int s, const struct sockaddr *name, socklen_t namelen);
int net_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
int net_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
int net_close(int s);
int net_connect(int s, const struct sockaddr *name, socklen_t namelen);
int net_listen(int s, int backlog);
int net_recv(int s, void *mem, size_t len, int flags);
int net_send(int s, const void *dataptr, size_t size, int flags);
int net_socket(int domain, int type, int protocol);
int net_read(int s, void *mem, size_t len);
int net_write(int s, const void *dataptr, size_t size);
Library includes similar compatibility system like lwIP has for standard BSD socket api:
- if NETCFG_COMPAT_SOCKETS is defined as 1 then defines for standard BSD socket functions are added to translate calls to net_* -functions, ie. accept() is defined as net_accept.
- If NETCFG_POSIX_SOCKETS_IO_NAMES is defined as 1 then defines for read, write and close functions are also added.
setsockopt options are mostly ignored, however SO_RCVTIMEO can be used to set read timeout.