Microchip® Advanced Software Framework

sockets.c File Reference

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_sockget_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_socktryget_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_cbselect_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 
)
Value:
(((domain) == AF_INET) ? \
netconn_type
Protocol family and type of the netconn.
Definition: api.h:105
#define NETCONN_TYPE_IPV6
Definition: api.h:95
#define AF_INET
Definition: sockets.h:191
u8_t type
pbuf_type as u8_t instead of enum to save space
Definition: pbuf.h:108

Referenced by lwip_socket().

#define err_to_errno (   err)
Value:
((unsigned)(-(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \
#define EIO
Definition: arch.h:99
#define ERR_TO_ERRNO_TABLE_SIZE
Definition: sockets.c:270
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.
Definition: sockets.c:251

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 
)
Value:
do { \
(sin)->sin_len = sizeof(struct sockaddr_in); \
(sin)->sin_family = AF_INET; \
(sin)->sin_port = htons((port)); \
inet_addr_from_ipaddr(&(sin)->sin_addr, ipX_2_ip(ipXaddr)); \
memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0)
#define ipX_2_ip(ipaddr)
Definition: ip_addr.h:70
#define htons(x)
Definition: def.h:77
Definition: sockets.h:64
#define AF_INET
Definition: sockets.h:191
#define SIN_ZERO_LEN
Definition: sockets.h:69
#define inet_addr_from_ipaddr(target_inaddr, source_ipaddr)
Definition: inet.h:106
#define IP6ADDR_PORT_TO_SOCKADDR (   sin6,
  ipXaddr,
  port 
)
Value:
do { \
(sin6)->sin6_len = sizeof(struct sockaddr_in6); \
(sin6)->sin6_family = AF_INET6; \
(sin6)->sin6_port = htons((port)); \
(sin6)->sin6_flowinfo = 0; \
inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipX_2_ip6(ipXaddr)); }while(0)
#define AF_INET6
Definition: sockets.h:193
#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr)
Definition: inet6.h:68
#define htons(x)
Definition: def.h:77
#define ipX_2_ip6(ip6addr)
Definition: ip_addr.h:69
Definition: sockets.h:74
#define IPXADDR_PORT_TO_SOCKADDR (   isipv6,
  sockaddr,
  ipXaddr,
  port 
)
Value:
do { \
if (isipv6) { \
IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ipXaddr, port); \
} else { \
IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ipXaddr, port); \
} } while(0)
Definition: sockets.h:64
#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipXaddr, port)
Definition: sockets.c:74
Definition: sockets.h:83
if(memp!=NULL)
Definition: memp.c:426
Definition: sockets.h:74
#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipXaddr, port)
Definition: sockets.c:92

Referenced by lwip_accept(), lwip_getaddrname(), and lwip_recvfrom().

#define IS_SOCK_ADDR_ALIGNED (   name)    ((((mem_ptr_t)(name)) % 4) == 0)
#define IS_SOCK_ADDR_LEN_VALID (   namelen)
Value:
(((namelen) == sizeof(struct sockaddr_in)) || \
((namelen) == sizeof(struct sockaddr_in6)))
Definition: sockets.h:64
Definition: sockets.h:74

Referenced by lwip_bind(), lwip_connect(), and lwip_sendto().

#define IS_SOCK_ADDR_TYPE_VALID (   name)
Value:
(((name)->sa_family == AF_INET) || \
((name)->sa_family == AF_INET6))
#define AF_INET6
Definition: sockets.h:193
#define AF_INET
Definition: sockets.h:191

Referenced by lwip_bind(), and lwip_sendto().

#define IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC (   name)
Value:
(((name)->sa_family == AF_UNSPEC) || \
#define AF_UNSPEC
Definition: sockets.h:190
#define IS_SOCK_ADDR_TYPE_VALID(name)
Definition: sockets.c:87

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
#define LWIP_SO_SNDRCVTIMEO_SET (   optval,
  val 
)
Value:
do { \
s32_t loc = (val); \
((struct timeval *)(optval))->tv_sec = (loc) / 1000U; \
((struct timeval *)(optval))->tv_usec = ((loc) % 1000U) * 1000U; }while(0)
signed int s32_t
Definition: cc.h:54

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 
)
Value:
do { \
LWIP_SOCKOPT_CHECK_OPTLEN(optlen, opttype); \
if ((sock)->conn == NULL) { return EINVAL; } }while(0)
#define EINVAL
Definition: arch.h:116
#define LWIP_SOCKOPT_CHECK_OPTLEN(optlen, opttype)
Definition: sockets.c:133
if(memp!=NULL)
Definition: memp.c:426
#define NULL
Definition: nm_bsp.h:70

Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().

#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB (   sock,
  optlen,
  opttype 
)
Value:
do { \
LWIP_SOCKOPT_CHECK_OPTLEN(optlen, opttype); \
if (((sock)->conn == NULL) || ((sock)->conn->pcb.tcp == NULL)) { return EINVAL; } }while(0)
#define EINVAL
Definition: arch.h:116
#define LWIP_SOCKOPT_CHECK_OPTLEN(optlen, opttype)
Definition: sockets.c:133
if(memp!=NULL)
Definition: memp.c:426
#define NULL
Definition: nm_bsp.h:70

Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().

#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE (   sock,
  optlen,
  opttype,
  netconntype 
)
Value:
do { \
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, opttype); \
if (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) != netconntype) { return ENOPROTOOPT; } }while(0)
#define ENOPROTOOPT
Definition: arch.h:188
#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, opttype)
Definition: sockets.c:137
netconn_type
Protocol family and type of the netconn.
Definition: api.h:105
if(memp!=NULL)
Definition: memp.c:426
#define NETCONNTYPE_GROUP(t)
Definition: api.h:92

Referenced by lwip_getsockopt_impl(), and lwip_setsockopt_impl().

#define NUM_SOCKETS   MEMP_NUM_NETCONN
#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...

#define set_errno (   err)    do { if (err) { errno = (err); } } while(0)
#define SOCK_ADDR_TYPE_MATCH (   name,
  sock 
)
Value:
((((name)->sa_family == AF_INET) && !(NETCONNTYPE_ISIPV6((sock)->conn->type))) || \
(((name)->sa_family == AF_INET6) && (NETCONNTYPE_ISIPV6((sock)->conn->type))))
#define NETCONNTYPE_ISIPV6(t)
Definition: api.h:96
#define AF_INET6
Definition: sockets.h:193
#define AF_INET
Definition: sockets.h:191

Referenced by lwip_bind(), and lwip_sendto().

#define SOCK_ADDR_TYPE_MATCH_OR_UNSPEC (   name,
  sock 
)
Value:
(((name)->sa_family == AF_UNSPEC) || \
#define SOCK_ADDR_TYPE_MATCH(name, sock)
Definition: sockets.c:89
#define AF_UNSPEC
Definition: sockets.h:190

Referenced by lwip_connect().

#define sock_set_errno (   sk,
 
)
#define SOCKADDR4_TO_IP4ADDR_PORT (   sin,
  ipXaddr,
  port 
)
Value:
do { \
inet_addr_to_ipaddr(ipX_2_ip(ipXaddr), &((sin)->sin_addr)); \
(port) = ntohs((sin)->sin_port); }while(0)
#define ipX_2_ip(ipaddr)
Definition: ip_addr.h:70
#define inet_addr_to_ipaddr(target_ipaddr, source_inaddr)
Definition: inet.h:107
#define ntohs(x)
Definition: def.h:78
#define SOCKADDR6_TO_IP6ADDR_PORT (   sin6,
  ipXaddr,
  port 
)
Value:
do { \
inet6_addr_to_ip6addr(ipX_2_ip6(ipXaddr), &((sin6)->sin6_addr)); \
(port) = ntohs((sin6)->sin6_port); }while(0)
#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr)
Definition: inet6.h:72
#define ipX_2_ip6(ip6addr)
Definition: ip_addr.h:69
#define ntohs(x)
Definition: def.h:78
#define SOCKADDR_TO_IPXADDR_PORT (   isipv6,
  sockaddr,
  ipXaddr,
  port 
)
Value:
do { \
if (isipv6) { \
SOCKADDR6_TO_IP6ADDR_PORT((struct sockaddr_in6*)(void*)(sockaddr), ipXaddr, port); \
} else { \
SOCKADDR4_TO_IP4ADDR_PORT((struct sockaddr_in*)(void*)(sockaddr), ipXaddr, port); \
} } while(0)
#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipXaddr, port)
Definition: sockets.c:80
#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipXaddr, port)
Definition: sockets.c:104
Definition: sockets.h:64
Definition: sockets.h:83
if(memp!=NULL)
Definition: memp.c:426
Definition: sockets.h:74

Referenced by lwip_bind(), lwip_connect(), and lwip_sendto().

static int alloc_socket ( struct netconn newconn,
int  accepted 
)
static

Allocate a new socket for a given netconn.

Parameters
newconnthe netconn for which to allocate a socket
accepted1 if socket has been created by accept(), 0 if socket has been created by socket()
Returns
the index of the new socket; -1 on error

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 void free_socket ( struct lwip_sock sock,
int  is_tcp 
)
static

Free a socket.

The socket's netconn must have been delete before!

Parameters
sockthe 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 struct lwip_sock* get_socket ( int  s)
static

Map a externally used socket index to the internal socket representation.

Parameters
sexternally used socket index
Returns
struct lwip_sock for the socket or NULL if not found

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().

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.

int lwip_getpeername ( int  s,
struct sockaddr name,
socklen_t namelen 
)

References lwip_getaddrname().

int lwip_getsockname ( int  s,
struct sockaddr name,
socklen_t namelen 
)

References lwip_getaddrname().

static u8_t lwip_getsockopt_impl ( int  s,
int  level,
int  optname,
void optval,
socklen_t optlen 
)
static
int lwip_listen ( int  s,
int  backlog 
)

Set a socket into listen mode.

The socket may not have been used for another connection previously.

Parameters
sthe socket to set to listening mode
backlog(ATTENTION: needs TCP_LISTEN_BACKLOG=1)
Returns
0 on success, non-zero on failure

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.

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 
)
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!!!

Parameters
maxfdp1the 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
Returns
number of sockets that had events (read/write/exception) (>= 0)

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_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_write ( int  s,
const void data,
size_t  size 
)

References lwip_send().

static struct lwip_sock* tryget_socket ( int  s)
static

Same as get_socket but doesn't set errno.

Parameters
sexternally used socket index
Returns
struct lwip_sock for the socket or NULL if not found

References lwip_sock::conn, NULL, NUM_SOCKETS, and sockets.

Referenced by lwip_getsockopt_impl(), lwip_select(), lwip_selscan(), and lwip_setsockopt_impl().

const int err_to_errno_table[]
static
Initial value:
= {
0,
EIO,
-1,
}
#define EINVAL
Definition: arch.h:116
#define EIO
Definition: arch.h:99
#define ECONNABORTED
Definition: arch.h:199
#define ENOTCONN
Definition: arch.h:203
#define ENOBUFS
Definition: arch.h:201
#define EWOULDBLOCK
Definition: arch.h:135
#define EALREADY
Definition: arch.h:210
#define ECONNRESET
Definition: arch.h:200
#define ENOMEM
Definition: arch.h:106
#define EHOSTUNREACH
Definition: arch.h:209
#define EINPROGRESS
Definition: arch.h:211
#define EADDRINUSE
Definition: arch.h:194

Table to quickly map an lwIP error (err_t) to a socket error by using -err as an index.

volatile int select_cb_ctr
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().

struct lwip_select_cb* select_cb_list
static

The global list of tasks waiting for select.

Referenced by lwip_select().

struct lwip_sock sockets[NUM_SOCKETS]
static

The global array of available sockets.

Referenced by alloc_socket(), get_socket(), lwip_accept(), and tryget_socket().