Sockets BSD-Like API module.
#include "lwip/opt.h"
#include "lwip/sockets.h"
#include "lwip/api.h"
#include "lwip/sys.h"
#include "lwip/igmp.h"
#include "lwip/inet.h"
#include "lwip/tcp.h"
#include "lwip/raw.h"
#include "lwip/udp.h"
#include "lwip/tcpip.h"
#include "lwip/memp.h"
#include "lwip/pbuf.h"
#include <string.h>
Data Structures | |
struct | lwip_select_cb |
Description for a task waiting in select. More... | |
struct | lwip_sock |
Contains all internal pointers and states used for a socket. More... | |
union | sockaddr_aligned |
A struct sockaddr replacement that has the same alignment as sockaddr_in/ sockaddr_in6 if instantiated. More... | |
Macros | |
#define | DOMAIN_TO_NETCONN_TYPE(domain, type) |
#define | err_to_errno(err) |
#define | ERR_TO_ERRNO_TABLE_SIZE (sizeof(err_to_errno_table)/sizeof(err_to_errno_table[0])) |
#define | IP4ADDR_PORT_TO_SOCKADDR(sin, ipXaddr, port) |
#define | IP6ADDR_PORT_TO_SOCKADDR(sin6, ipXaddr, port) |
#define | IPXADDR_PORT_TO_SOCKADDR(isipv6, sockaddr, ipXaddr, port) |
#define | IS_SOCK_ADDR_ALIGNED(name) ((((mem_ptr_t)(name)) % 4) == 0) |
#define | IS_SOCK_ADDR_LEN_VALID(namelen) |
#define | IS_SOCK_ADDR_TYPE_VALID(name) |
#define | IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC(name) |
#define | LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(name, sock) |
#define | LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(name) API_VAR_DECLARE(struct lwip_setgetsockopt_data, name) |
#define | LWIP_SETGETSOCKOPT_DATA_VAR_FREE(name) API_VAR_FREE(MEMP_SOCKET_SETGETSOCKOPT_DATA, name) |
#define | LWIP_SETGETSOCKOPT_DATA_VAR_REF(name) API_VAR_REF(name) |
#define | LWIP_SO_SNDRCVTIMEO_GET_MS(optval) ((((struct timeval *)(optval))->tv_sec * 1000U) + (((struct timeval *)(optval))->tv_usec / 1000U)) |
#define | LWIP_SO_SNDRCVTIMEO_OPTTYPE struct timeval |
#define | LWIP_SO_SNDRCVTIMEO_SET(optval, val) |
#define | LWIP_SOCKOPT_CHECK_OPTLEN(optlen, opttype) do { if((optlen) < sizeof(opttype)) { return EINVAL; }}while(0) |
#define | LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, opttype) |
#define | LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, opttype) |
#define | LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, opttype, netconntype) |
#define | NUM_SOCKETS MEMP_NUM_NETCONN |
#define | SELECT_SEM_PTR(sem) (&(sem)) |
#define | SELECT_SEM_T sys_sem_t |
#define | SELWAIT_T u8_t |
This is overridable for the rare case where more than 255 threads select on the same socket... More... | |
#define | set_errno(err) do { if (err) { errno = (err); } } while(0) |
#define | SOCK_ADDR_TYPE_MATCH(name, sock) |
#define | SOCK_ADDR_TYPE_MATCH_OR_UNSPEC(name, sock) |
#define | sock_set_errno(sk, e) |
#define | SOCKADDR4_TO_IP4ADDR_PORT(sin, ipXaddr, port) |
#define | SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipXaddr, port) |
#define | SOCKADDR_TO_IPXADDR_PORT(isipv6, sockaddr, ipXaddr, port) |
Functions | |
static int | alloc_socket (struct netconn *newconn, int accepted) |
Allocate a new socket for a given netconn. More... | |
static void | event_callback (struct netconn *conn, enum netconn_evt evt, u16_t len) |
Callback registered in the netconn layer for each socket-netconn. More... | |
static void | free_socket (struct lwip_sock *sock, int is_tcp) |
Free a socket. More... | |
static struct lwip_sock * | get_socket (int s) |
Map a externally used socket index to the internal socket representation. More... | |
int | lwip_accept (int s, struct sockaddr *addr, socklen_t *addrlen) |
int | lwip_bind (int s, const struct sockaddr *name, socklen_t namelen) |
int | lwip_close (int s) |
int | lwip_connect (int s, const struct sockaddr *name, socklen_t namelen) |
int | lwip_fcntl (int s, int cmd, int val) |
A minimal implementation of fcntl. More... | |
static int | lwip_getaddrname (int s, struct sockaddr *name, socklen_t *namelen, u8_t local) |
int | lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen) |
int | lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen) |
int | lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) |
static void | lwip_getsockopt_callback (void *arg) |
lwip_getsockopt_callback: only used without CORE_LOCKING to get into the tcpip_thread More... | |
static u8_t | lwip_getsockopt_impl (int s, int level, int optname, void *optval, socklen_t *optlen) |
lwip_getsockopt_impl: the actual implementation of getsockopt: same argument as lwip_getsockopt, either called directly or through callback More... | |
int | lwip_ioctl (int s, long cmd, void *argp) |
int | lwip_listen (int s, int backlog) |
Set a socket into listen mode. More... | |
int | lwip_read (int s, void *mem, size_t len) |
int | lwip_recv (int s, void *mem, size_t len, int flags) |
int | lwip_recvfrom (int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) |
int | lwip_select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) |
Processing exceptset is not yet implemented. More... | |
static int | lwip_selscan (int maxfdp1, fd_set *readset_in, fd_set *writeset_in, fd_set *exceptset_in, fd_set *readset_out, fd_set *writeset_out, fd_set *exceptset_out) |
Go through the readset and writeset lists and see which socket of the sockets set in the sets has events. More... | |
int | lwip_send (int s, const void *data, size_t size, int flags) |
int | lwip_sendto (int s, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen) |
int | lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) |
static void | lwip_setsockopt_callback (void *arg) |
lwip_setsockopt_callback: only used without CORE_LOCKING to get into the tcpip_thread More... | |
static u8_t | lwip_setsockopt_impl (int s, int level, int optname, const void *optval, socklen_t optlen) |
lwip_setsockopt_impl: the actual implementation of setsockopt: same argument as lwip_setsockopt, either called directly or through callback More... | |
int | lwip_shutdown (int s, int how) |
Unimplemented: Close one end of a full-duplex connection. More... | |
int | lwip_socket (int domain, int type, int protocol) |
int | lwip_write (int s, const void *data, size_t size) |
static struct lwip_sock * | tryget_socket (int s) |
Same as get_socket but doesn't set errno. More... | |
Variables | |
static const int | err_to_errno_table [] |
Table to quickly map an lwIP error (err_t) to a socket error by using -err as an index. More... | |
static volatile int | select_cb_ctr |
This counter is increased from lwip_select when the list is chagned and checked in event_callback to see if it has changed. More... | |
static struct lwip_select_cb * | select_cb_list |
The global list of tasks waiting for select. More... | |
static struct lwip_sock | sockets [NUM_SOCKETS] |
The global array of available sockets. More... | |
#define DOMAIN_TO_NETCONN_TYPE | ( | domain, | |
type | |||
) |
Referenced by lwip_socket().
#define err_to_errno | ( | err | ) |
Referenced by lwip_accept(), lwip_bind(), lwip_connect(), lwip_getaddrname(), lwip_getsockopt_impl(), lwip_listen(), lwip_recvfrom(), lwip_send(), lwip_sendto(), and lwip_shutdown().
#define ERR_TO_ERRNO_TABLE_SIZE (sizeof(err_to_errno_table)/sizeof(err_to_errno_table[0])) |
#define IP4ADDR_PORT_TO_SOCKADDR | ( | sin, | |
ipXaddr, | |||
port | |||
) |
#define IP6ADDR_PORT_TO_SOCKADDR | ( | sin6, | |
ipXaddr, | |||
port | |||
) |
#define IPXADDR_PORT_TO_SOCKADDR | ( | isipv6, | |
sockaddr, | |||
ipXaddr, | |||
port | |||
) |
Referenced by lwip_accept(), lwip_getaddrname(), and lwip_recvfrom().
#define IS_SOCK_ADDR_ALIGNED | ( | name | ) | ((((mem_ptr_t)(name)) % 4) == 0) |
Referenced by lwip_bind(), lwip_connect(), and lwip_sendto().
#define IS_SOCK_ADDR_LEN_VALID | ( | namelen | ) |
Referenced by lwip_bind(), lwip_connect(), and lwip_sendto().
#define IS_SOCK_ADDR_TYPE_VALID | ( | name | ) |
Referenced by lwip_bind(), and lwip_sendto().
#define IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC | ( | name | ) |
Referenced by lwip_connect().
#define LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC | ( | name, | |
sock | |||
) |
Referenced by lwip_getsockopt(), and lwip_setsockopt().
#define LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE | ( | name | ) | API_VAR_DECLARE(struct lwip_setgetsockopt_data, name) |
Referenced by lwip_getsockopt(), and lwip_setsockopt().
#define LWIP_SETGETSOCKOPT_DATA_VAR_FREE | ( | name | ) | API_VAR_FREE(MEMP_SOCKET_SETGETSOCKOPT_DATA, name) |
Referenced by lwip_getsockopt(), and lwip_setsockopt().
#define LWIP_SETGETSOCKOPT_DATA_VAR_REF | ( | name | ) | API_VAR_REF(name) |
Referenced by lwip_getsockopt(), and lwip_setsockopt().
#define LWIP_SO_SNDRCVTIMEO_GET_MS | ( | optval | ) | ((((struct timeval *)(optval))->tv_sec * 1000U) + (((struct timeval *)(optval))->tv_usec / 1000U)) |
Referenced by lwip_setsockopt_impl().
#define LWIP_SO_SNDRCVTIMEO_OPTTYPE struct timeval |
Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().
#define LWIP_SO_SNDRCVTIMEO_SET | ( | optval, | |
val | |||
) |
Referenced by lwip_getsockopt_impl().
#define LWIP_SOCKOPT_CHECK_OPTLEN | ( | optlen, | |
opttype | |||
) | do { if((optlen) < sizeof(opttype)) { return EINVAL; }}while(0) |
Referenced by lwip_getsockopt_impl().
#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN | ( | sock, | |
optlen, | |||
opttype | |||
) |
Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().
#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB | ( | sock, | |
optlen, | |||
opttype | |||
) |
Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().
#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE | ( | sock, | |
optlen, | |||
opttype, | |||
netconntype | |||
) |
Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().
#define NUM_SOCKETS MEMP_NUM_NETCONN |
Referenced by alloc_socket(), get_socket(), lwip_accept(), and tryget_socket().
#define SELECT_SEM_PTR | ( | sem | ) | (&(sem)) |
Referenced by event_callback(), and lwip_select().
#define SELECT_SEM_T sys_sem_t |
#define SELWAIT_T u8_t |
This is overridable for the rare case where more than 255 threads select on the same socket...
Referenced by get_socket(), lwip_close(), lwip_select(), and lwip_socket().
#define SOCK_ADDR_TYPE_MATCH | ( | name, | |
sock | |||
) |
Referenced by lwip_bind(), and lwip_sendto().
#define SOCK_ADDR_TYPE_MATCH_OR_UNSPEC | ( | name, | |
sock | |||
) |
Referenced by lwip_connect().
#define sock_set_errno | ( | sk, | |
e | |||
) |
Referenced by lwip_accept(), lwip_bind(), lwip_connect(), lwip_fcntl(), lwip_getaddrname(), lwip_getsockopt(), lwip_getsockopt_impl(), lwip_ioctl(), lwip_listen(), lwip_recvfrom(), lwip_send(), lwip_sendto(), lwip_setsockopt(), and lwip_shutdown().
#define SOCKADDR4_TO_IP4ADDR_PORT | ( | sin, | |
ipXaddr, | |||
port | |||
) |
#define SOCKADDR6_TO_IP6ADDR_PORT | ( | sin6, | |
ipXaddr, | |||
port | |||
) |
#define SOCKADDR_TO_IPXADDR_PORT | ( | isipv6, | |
sockaddr, | |||
ipXaddr, | |||
port | |||
) |
Referenced by lwip_bind(), lwip_connect(), and lwip_sendto().
|
static |
Allocate a new socket for a given netconn.
newconn | the netconn for which to allocate a socket |
accepted | 1 if socket has been created by accept(), 0 if socket has been created by socket() |
References lwip_sock::conn, lwip_sock::err, lwip_sock::errevent, lwip_sock::lastdata, lwip_sock::lastoffset, NETCONN_TCP, NETCONNTYPE_GROUP, NULL, NUM_SOCKETS, lwip_sock::rcvevent, lwip_sock::select_waiting, lwip_sock::sendevent, sockets, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), and netconn::type.
Referenced by lwip_accept(), and lwip_socket().
|
static |
Callback registered in the netconn layer for each socket-netconn.
Processes recvevent (data available) and wakes up tasks waiting for select.
References lwip_sock::errevent, lwip_select_cb::exceptset, FD_ISSET, get_socket(), LWIP_ASSERT, NETCONN_EVT_ERROR, NETCONN_EVT_RCVMINUS, NETCONN_EVT_RCVPLUS, NETCONN_EVT_SENDMINUS, NETCONN_EVT_SENDPLUS, lwip_select_cb::next, NULL, lwip_sock::rcvevent, lwip_select_cb::readset, select_cb_ctr, SELECT_SEM_PTR, lwip_sock::select_waiting, lwip_select_cb::sem, lwip_select_cb::sem_signalled, lwip_sock::sendevent, netconn::socket, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), sys_sem_signal(), and lwip_select_cb::writeset.
Referenced by lwip_accept(), and lwip_socket().
Free a socket.
The socket's netconn must have been delete before!
sock | the socket to free |
is_tcp | != 0 for TCP sockets, used to free lastdata |
References lwip_sock::conn, lwip_sock::err, lwip_sock::lastdata, lwip_sock::lastoffset, netbuf_delete(), NULL, pbuf_free(), SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), and SYS_ARCH_UNPROTECT().
Referenced by lwip_close().
|
static |
Map a externally used socket index to the internal socket representation.
s | externally used socket index |
References lwip_sock::conn, EBADF, LWIP_DEBUGF, NULL, NUM_SOCKETS, set_errno, sockets, and SOCKETS_DEBUG.
Referenced by event_callback(), lwip_accept(), lwip_bind(), lwip_close(), lwip_connect(), lwip_fcntl(), lwip_getaddrname(), lwip_getsockopt(), lwip_ioctl(), lwip_listen(), lwip_recvfrom(), lwip_send(), lwip_sendto(), lwip_setsockopt(), and lwip_shutdown().
References alloc_socket(), netconn::callback, lwip_sock::conn, ENFILE, EOPNOTSUPP, ERR_OK, err_to_errno, event_callback(), EWOULDBLOCK, get_socket(), ipX_2_ip, ipX_addr_debug_print, IPXADDR_PORT_TO_SOCKADDR, LWIP_ASSERT, LWIP_DEBUGF, netconn_accept(), netconn_delete(), netconn_is_nonblocking, netconn_peer, netconn_set_noautorecved, NETCONN_TCP, NETCONNTYPE_GROUP, NETCONNTYPE_ISIPV6, NULL, NUM_SOCKETS, lwip_sock::rcvevent, sockaddr_aligned::sa, sockaddr::sa_len, sock_set_errno, netconn::socket, sockets, SOCKETS_DEBUG, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), netconn::type, and U16_F.
References AF_INET6, lwip_sock::conn, lwip_sock::err, ERR_ARG, ERR_OK, err_to_errno, ERR_VAL, get_socket(), ipX_2_ip, ipX_addr_debug_print, IS_SOCK_ADDR_ALIGNED, IS_SOCK_ADDR_LEN_VALID, IS_SOCK_ADDR_TYPE_VALID, LWIP_DEBUGF, LWIP_ERROR(), netconn_bind(), sockaddr::sa_family, SOCK_ADDR_TYPE_MATCH, sock_set_errno, SOCKADDR_TO_IPXADDR_PORT, SOCKETS_DEBUG, and U16_F.
int lwip_close | ( | int | s | ) |
References lwip_sock::conn, free_socket(), get_socket(), lwip_sock::lastdata, LWIP_ASSERT, LWIP_DEBUGF, netconn_delete(), NETCONN_TCP, NETCONNTYPE_GROUP, NULL, set_errno, and SOCKETS_DEBUG.
References AF_INET6, AF_UNSPEC, lwip_sock::conn, lwip_sock::err, ERR_ARG, ERR_OK, err_to_errno, ERR_VAL, get_socket(), ipX_2_ip, ipX_addr_debug_print, IS_SOCK_ADDR_ALIGNED, IS_SOCK_ADDR_LEN_VALID, IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC, LWIP_DEBUGF, LWIP_ERROR(), netconn_connect(), netconn_disconnect(), sockaddr::sa_family, SOCK_ADDR_TYPE_MATCH_OR_UNSPEC, sock_set_errno, SOCKADDR_TO_IPXADDR_PORT, SOCKETS_DEBUG, and U16_F.
int lwip_fcntl | ( | int | s, |
int | cmd, | ||
int | val | ||
) |
A minimal implementation of fcntl.
Currently only the commands F_GETFL and F_SETFL are implemented. Only the flag O_NONBLOCK is implemented.
References lwip_sock::conn, ENOSYS, F_GETFL, F_SETFL, get_socket(), LWIP_DEBUGF, netconn_is_nonblocking, netconn_set_nonblocking, O_NONBLOCK, sock_set_errno, and SOCKETS_DEBUG.
|
static |
References lwip_sock::conn, ERR_OK, err_to_errno, get_socket(), ipX_2_ip, ipX_addr_debug_print, IPXADDR_PORT_TO_SOCKADDR, LWIP_DEBUGF, netconn_getaddr(), NETCONNTYPE_ISIPV6, sockaddr_aligned::sa, sockaddr::sa_len, sock_set_errno, SOCKETS_DEBUG, and U16_F.
Referenced by lwip_getpeername(), and lwip_getsockname().
References lwip_getaddrname().
References lwip_getaddrname().
References lwip_sock::conn, EFAULT, ENOBUFS, get_socket(), LOCK_TCPIP_CORE, lwip_getsockopt_callback(), lwip_getsockopt_impl(), LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC, LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE, LWIP_SETGETSOCKOPT_DATA_VAR_FREE, LWIP_SETGETSOCKOPT_DATA_VAR_REF, LWIP_SETGETSOCKOPT_MAXOPTLEN, NULL, netconn::op_completed, sock_set_errno, sys_arch_sem_wait(), tcpip_callback, and UNLOCK_TCPIP_CORE.
lwip_getsockopt_callback: only used without CORE_LOCKING to get into the tcpip_thread
References lwip_setgetsockopt_data::completed_sem, lwip_setgetsockopt_data::err, lwip_setgetsockopt_data::level, LWIP_ASSERT, lwip_getsockopt_impl(), NULL, lwip_setgetsockopt_data::optlen, lwip_setgetsockopt_data::optname, lwip_setgetsockopt_data::optval, lwip_setgetsockopt_data::s, and sys_sem_signal().
Referenced by lwip_getsockopt().
|
static |
lwip_getsockopt_impl: the actual implementation of getsockopt: same argument as lwip_getsockopt, either called directly or through callback
References raw_pcb::chksum_offset, raw_pcb::chksum_reqd, lwip_sock::conn, EAFNOSUPPORT, EBADF, EINPROGRESS, ENOPROTOOPT, lwip_sock::err, err_to_errno, udp_pcb::flags, netconn::flags, inet_addr_from_ipaddr, netconn::ip, ip_get_option, IP_TOS, IP_TTL, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_RAW, IPPROTO_TCP, IPPROTO_UDPLITE, IPV6_CHECKSUM, IPV6_V6ONLY, tcp_pcb::keep_idle, netconn::last_err, LISTEN, LWIP_DEBUGF, LWIP_SO_SNDRCVTIMEO_OPTTYPE, LWIP_SO_SNDRCVTIMEO_SET, LWIP_SOCKOPT_CHECK_OPTLEN, LWIP_SOCKOPT_CHECK_OPTLEN_CONN, LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB, LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE, NETCONN_FLAG_IPV6_V6ONLY, netconn_get_recvtimeout, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NETCONNTYPE_ISUDPLITE, NULL, netconn::pcb, netconn::raw, SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_NO_CHECK, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDTIMEO, SO_TYPE, SOCK_DGRAM, SOCK_RAW, sock_set_errno, SOCK_STREAM, SOCKETS_DEBUG, SOL_SOCKET, netconn::tcp, TCP_KEEPALIVE, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL, tcp_nagle_disabled, TCP_NODELAY, tryget_socket(), netconn::type, netconn::udp, udp_flags, UDP_FLAGS_MULTICAST_LOOP, UDP_FLAGS_NOCHKSUM, UDP_FLAGS_UDPLITE, and X32_F.
Referenced by lwip_getsockopt(), and lwip_getsockopt_callback().
int lwip_ioctl | ( | int | s, |
long | cmd, | ||
void * | argp | ||
) |
References lwip_sock::conn, EINVAL, ENOSYS, ERR_OK, FIONBIO, FIONREAD, get_socket(), if(), lwip_sock::lastdata, lwip_sock::lastoffset, LWIP_DEBUGF, netconn_recv(), netconn_set_nonblocking, NETCONN_TCP, NETCONNTYPE_GROUP, lwip_sock::rcvevent, sock_set_errno, SOCKETS_DEBUG, SYS_ARCH_GET, pbuf::tot_len, and U16_F.
int lwip_listen | ( | int | s, |
int | backlog | ||
) |
Set a socket into listen mode.
The socket may not have been used for another connection previously.
s | the socket to set to listening mode |
backlog | (ATTENTION: needs TCP_LISTEN_BACKLOG=1) |
References lwip_sock::conn, EOPNOTSUPP, lwip_sock::err, ERR_OK, err_to_errno, get_socket(), LWIP_DEBUGF, LWIP_MAX, LWIP_MIN, netconn_listen_with_backlog(), NETCONN_TCP, NETCONNTYPE_GROUP, sock_set_errno, and SOCKETS_DEBUG.
int lwip_read | ( | int | s, |
void * | mem, | ||
size_t | len | ||
) |
References lwip_recvfrom(), and NULL.
int lwip_recv | ( | int | s, |
void * | mem, | ||
size_t | len, | ||
int | flags | ||
) |
References lwip_recvfrom(), and NULL.
int lwip_recvfrom | ( | int | s, |
void * | mem, | ||
size_t | len, | ||
int | flags, | ||
struct sockaddr * | from, | ||
socklen_t * | fromlen | ||
) |
References lwip_sock::conn, ERR_CLSD, ERR_OK, err_to_errno, EWOULDBLOCK, pbuf::flags, get_socket(), ipX_2_ip, ipX_addr_debug_print, IPXADDR_PORT_TO_SOCKADDR, lwip_sock::lastdata, lwip_sock::lastoffset, LWIP_ASSERT, LWIP_DEBUGF, lwip_strerr, MSG_DONTWAIT, MSG_PEEK, netbuf_delete(), netconn_getaddr(), netconn_is_nonblocking, netconn_recv(), netconn_recv_tcp_pbuf(), netconn_recved(), NETCONN_TCP, NETCONNTYPE_GROUP, NETCONNTYPE_ISIPV6, NULL, pbuf_copy_partial(), PBUF_FLAG_PUSH, pbuf_free(), lwip_sock::rcvevent, sockaddr_aligned::sa, sockaddr::sa_len, sock_set_errno, SOCKETS_DEBUG, pbuf::tot_len, and U16_F.
Referenced by lwip_read(), lwip_recv(), and ping_recv().
int lwip_select | ( | int | maxfdp1, |
fd_set * | readset, | ||
fd_set * | writeset, | ||
fd_set * | exceptset, | ||
struct timeval * | timeout | ||
) |
Processing exceptset is not yet implemented.
References EBADF, ENOMEM, ERR_OK, lwip_select_cb::exceptset, FD_ISSET, LWIP_ASSERT, LWIP_DEBUGF, lwip_selscan(), lwip_select_cb::next, NULL, lwip_select_cb::prev, lwip_select_cb::readset, S32_F, select_cb_ctr, select_cb_list, SELECT_SEM_PTR, lwip_sock::select_waiting, lwip_select_cb::sem, lwip_select_cb::sem_signalled, set_errno, SOCKETS_DEBUG, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), sys_arch_sem_wait(), SYS_ARCH_TIMEOUT, SYS_ARCH_UNPROTECT(), sys_sem_free(), sys_sem_new(), tryget_socket(), and lwip_select_cb::writeset.
|
static |
Go through the readset and writeset lists and see which socket of the sockets set in the sets has events.
On return, readset, writeset and exceptset have the sockets enabled that had events.
exceptset is not used for now!!!
maxfdp1 | the highest socket index in the sets |
readset_in,: | set of sockets to check for read events |
writeset_in,: | set of sockets to check for write events |
exceptset_in,: | set of sockets to check for error events |
readset_out,: | set of sockets that had read events |
writeset_out,: | set of sockets that had write events |
exceptset_out,: | set os sockets that had error events |
References lwip_sock::errevent, FD_ISSET, FD_SET, FD_ZERO, lwip_sock::lastdata, LWIP_ASSERT, LWIP_DEBUGF, NULL, lwip_sock::rcvevent, lwip_sock::sendevent, SOCKETS_DEBUG, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), and tryget_socket().
Referenced by lwip_select().
int lwip_send | ( | int | s, |
const void * | data, | ||
size_t | size, | ||
int | flags | ||
) |
References lwip_sock::conn, lwip_sock::err, ERR_ARG, ERR_OK, err_to_errno, get_socket(), LWIP_DEBUGF, lwip_sendto(), MSG_DONTWAIT, MSG_MORE, NETCONN_COPY, NETCONN_DONTBLOCK, NETCONN_MORE, NETCONN_TCP, netconn_write_partly(), NETCONNTYPE_GROUP, NULL, sock_set_errno, and SOCKETS_DEBUG.
Referenced by lwip_sendto(), and lwip_write().
int lwip_sendto | ( | int | s, |
const void * | data, | ||
size_t | size, | ||
int | flags, | ||
const struct sockaddr * | to, | ||
socklen_t | tolen | ||
) |
References AF_INET6, lwip_sock::err, ERR_ARG, ERR_MEM, ERR_OK, err_to_errno, ERR_VAL, get_socket(), ipX_2_ip, ipX_addr_debug_print, ipX_addr_set_any, IS_SOCK_ADDR_ALIGNED, IS_SOCK_ADDR_LEN_VALID, IS_SOCK_ADDR_TYPE_VALID, LOCK_TCPIP_CORE, LWIP_ASSERT, LWIP_DEBUGF, LWIP_ERROR(), lwip_send(), netbuf_alloc(), netbuf_free(), netbuf_ref(), NETCONN_RAW, netconn_send(), NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NETCONNTYPE_ISIPV6, NULL, pbuf::payload, pbuf_alloc(), pbuf_free(), PBUF_RAM, PBUF_REF, PBUF_TRANSPORT, raw_sendto(), sockaddr::sa_family, SOCK_ADDR_TYPE_MATCH, sock_set_errno, SOCKADDR_TO_IPXADDR_PORT, SOCKETS_DEBUG, U16_F, udp_sendto(), and UNLOCK_TCPIP_CORE.
Referenced by lwip_send(), and ping_send().
References lwip_sock::conn, EFAULT, ENOBUFS, get_socket(), LOCK_TCPIP_CORE, LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC, LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE, LWIP_SETGETSOCKOPT_DATA_VAR_FREE, LWIP_SETGETSOCKOPT_DATA_VAR_REF, LWIP_SETGETSOCKOPT_MAXOPTLEN, lwip_setsockopt_callback(), lwip_setsockopt_impl(), NULL, netconn::op_completed, sock_set_errno, sys_arch_sem_wait(), tcpip_callback, and UNLOCK_TCPIP_CORE.
Referenced by ping_function().
lwip_setsockopt_callback: only used without CORE_LOCKING to get into the tcpip_thread
References lwip_setgetsockopt_data::completed_sem, lwip_setgetsockopt_data::err, lwip_setgetsockopt_data::level, LWIP_ASSERT, lwip_setsockopt_impl(), NULL, lwip_setgetsockopt_data::optlen, lwip_setgetsockopt_data::optname, lwip_setgetsockopt_data::optval, lwip_setgetsockopt_data::s, and sys_sem_signal().
Referenced by lwip_setsockopt().
|
static |
lwip_setsockopt_impl: the actual implementation of setsockopt: same argument as lwip_setsockopt, either called directly or through callback
References raw_pcb::chksum_offset, raw_pcb::chksum_reqd, lwip_sock::conn, EADDRNOTAVAIL, EAFNOSUPPORT, EBADF, EINVAL, ENOPROTOOPT, ERR_OK, netconn::flags, inet_addr_to_ipaddr, netconn::ip, ip_reset_option, ip_set_option, IP_TOS, IP_TTL, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_RAW, IPPROTO_TCP, IPPROTO_UDPLITE, IPV6_CHECKSUM, IPV6_V6ONLY, tcp_pcb::keep_idle, LWIP_DEBUGF, LWIP_SO_SNDRCVTIMEO_GET_MS, LWIP_SO_SNDRCVTIMEO_OPTTYPE, LWIP_SOCKOPT_CHECK_OPTLEN_CONN, LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB, LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE, NETCONN_FLAG_IPV6_V6ONLY, NETCONN_RAW, netconn_set_recvtimeout, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_ISUDPLITE, netconn::pcb, netconn::raw, SO_BROADCAST, SO_KEEPALIVE, SO_NO_CHECK, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDTIMEO, SOCKETS_DEBUG, SOL_SOCKET, netconn::tcp, TCP_KEEPALIVE, TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL, tcp_nagle_disable, tcp_nagle_enable, TCP_NODELAY, tryget_socket(), U32_F, netconn::udp, udp_flags, UDP_FLAGS_MULTICAST_LOOP, UDP_FLAGS_NOCHKSUM, UDP_FLAGS_UDPLITE, and udp_setflags.
Referenced by lwip_setsockopt(), and lwip_setsockopt_callback().
int lwip_shutdown | ( | int | s, |
int | how | ||
) |
Unimplemented: Close one end of a full-duplex connection.
Currently, the full connection is closed.
References lwip_sock::conn, EINVAL, ENOTCONN, EOPNOTSUPP, lwip_sock::err, ERR_OK, err_to_errno, get_socket(), LWIP_DEBUGF, netconn_shutdown(), NETCONN_TCP, NETCONNTYPE_GROUP, NULL, SHUT_RD, SHUT_RDWR, SHUT_WR, sock_set_errno, and SOCKETS_DEBUG.
int lwip_socket | ( | int | domain, |
int | type, | ||
int | protocol | ||
) |
References alloc_socket(), DOMAIN_TO_NETCONN_TYPE, EINVAL, ENFILE, ENOBUFS, event_callback(), IPPROTO_UDPLITE, LWIP_DEBUGF, netconn_delete(), netconn_new_with_callback, netconn_new_with_proto_and_callback(), NETCONN_RAW, netconn_set_noautorecved, NETCONN_TCP, NETCONN_UDP, NETCONN_UDPLITE, NULL, PF_INET, set_errno, SOCK_DGRAM, SOCK_RAW, SOCK_STREAM, netconn::socket, and SOCKETS_DEBUG.
Referenced by ping_function().
int lwip_write | ( | int | s, |
const void * | data, | ||
size_t | size | ||
) |
References lwip_send().
|
static |
Same as get_socket but doesn't set errno.
s | externally used socket index |
References lwip_sock::conn, NULL, NUM_SOCKETS, and sockets.
Referenced by lwip_getsockopt_impl(), lwip_select(), lwip_selscan(), and lwip_setsockopt_impl().
|
static |
Table to quickly map an lwIP error (err_t) to a socket error by using -err as an index.
|
static |
This counter is increased from lwip_select when the list is chagned and checked in event_callback to see if it has changed.
Referenced by event_callback(), and lwip_select().
|
static |
The global list of tasks waiting for select.
Referenced by lwip_select().
|
static |
The global array of available sockets.
Referenced by alloc_socket(), get_socket(), lwip_accept(), and tryget_socket().