feat(lwip): Add multi-thread support

This commit is contained in:
Dong Heng
2018-06-25 17:46:53 +08:00
parent cccd058783
commit e912bc25fa
7 changed files with 151 additions and 90 deletions

View File

@ -0,0 +1,33 @@
/**
* @file
* This file is a posix wrapper for lwip/errno.h.
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#include "posix/errno.h"

View File

@ -0,0 +1,33 @@
/**
* @file
* This file is a posix wrapper for lwip/netdb.h.
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#include "posix/netdb.h"

View File

@ -1,8 +1,41 @@
#ifndef _SOCKETS_MT_H_
#define _SOCKETS_MT_H_
/**
* @file
* This file is a posix wrapper for lwip/sockets.h.
*/
#ifdef SOCKETS_MT
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#ifndef _SOCKET_MT_H_
#define _SOCKET_MT_H_
#include "posix/sys/socket.h"
#if LWIP_COMPAT_SOCKETS == 3
int lwip_mt_init(void);
int lwip_socket_mt(int domain, int type, int protocol);
int lwip_bind_mt(int s, const struct sockaddr *name, socklen_t namelen);
@ -27,46 +60,26 @@ int lwip_close_mt(int s);
int lwip_select_mt(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout);
int lwip_fcntl_mt(int s, int cmd, int val);
#ifdef SOCKETS_TCP_TRACE
int lwip_trace_tcp(int s, int cmd, void *arg);
#endif
#if LWIP_COMPAT_SOCKETS
#ifdef SOCKETS_MT_DBUG
#define accept(a,b,c) lwip_accept_mt(a,b,c); printf("%s %d\n", __FUNCTION__, __LINE__);
#define bind(a,b,c) lwip_bind_mt(a,b,c); printf("%s %d\n", __FUNCTION__, __LINE__);
#define shutdown(a,b) lwip_shutdown_mt(a,b); printf("%s %d\n", __FUNCTION__, __LINE__);
#define closesocket(s) lwip_close_mt(s); printf("%s %d\n", __FUNCTION__, __LINE__);
#define connect(a,b,c) lwip_connect_mt(a,b,c); printf("%s %d\n", __FUNCTION__, __LINE__);
#define getsockname(a,b,c) lwip_getsockname_mt(a,b,c); printf("%s %d\n", __FUNCTION__, __LINE__);
#define getpeername(a,b,c) lwip_getpeername_mt(a,b,c); printf("%s %d\n", __FUNCTION__, __LINE__);
#define setsockopt(a,b,c,d,e) lwip_setsockopt_mt(a,b,c,d,e); printf("%s %d\n", __FUNCTION__, __LINE__);
#define getsockopt(a,b,c,d,e) lwip_getsockopt_mt(a,b,c,d,e); printf("%s %d\n", __FUNCTION__, __LINE__);
#define listen(a,b) lwip_listen_mt(a,b); printf("%s %d\n", __FUNCTION__, __LINE__);
#define recv(a,b,c,d) lwip_recv_mt(a,b,c,d); printf("%s %d\n", __FUNCTION__, __LINE__);
#define recvfrom(a,b,c,d,e,f) lwip_recvfrom_mt(a,b,c,d,e,f); printf("%s %d\n", __FUNCTION__, __LINE__);
#define send(a,b,c,d) lwip_send_mt(a,b,c,d); printf("%s %d\n", __FUNCTION__, __LINE__);
#define sendto(a,b,c,d,e,f) lwip_sendto_mt(a,b,c,d,e,f); printf("%s %d\n", __FUNCTION__, __LINE__);
#define socket(a,b,c) lwip_socket_mt(a,b,c); printf("%s %d\n", __FUNCTION__, __LINE__);
#define accept(a,b,c) lwip_accept_mt(a,b,c)
#define bind(a,b,c) lwip_bind_mt(a,b,c)
#define shutdown(a,b) lwip_shutdown_mt(a,b)
#define connect(a,b,c) lwip_connect_mt(a,b,c)
#define getsockname(a,b,c) lwip_getsockname_mt(a,b,c)
#define getpeername(a,b,c) lwip_getpeername_mt(a,b,c)
#define setsockopt(a,b,c,d,e) lwip_setsockopt_mt(a,b,c,d,e)
#define getsockopt(a,b,c,d,e) lwip_getsockopt_mt(a,b,c,d,e)
#define listen(a,b) lwip_listen_mt(a,b)
#define recv(a,b,c,d) lwip_recv_mt(a,b,c,d)
#define recvfrom(a,b,c,d,e,f) lwip_recvfrom_mt(a,b,c,d,e,f)
#define send(a,b,c,d) lwip_send_mt(a,b,c,d)
#define sendto(a,b,c,d,e,f) lwip_sendto_mt(a,b,c,d,e,f)
#define socket(a,b,c) lwip_socket_mt(a,b,c)
#define select(a,b,c,d,e) lwip_select_mt(a,b,c,d,e)
#define ioctlsocket(a,b,c) lwip_ioctl_mt(a,b,c) ; printf("%s %d\n", __FUNCTION__, __LINE__);
#if LWIP_POSIX_SOCKETS_IO_NAMES
#define read(a,b,c) lwip_read_mt(a,b,c)
#define write(a,b,c) lwip_write_mt(a,b,c)
#define close(s) lwip_close_mt(s)
#define fcntl(a,b,c) lwip_fcntl_mt(a,b,c)
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
#else /* SOCKETS_MT_DBUG */
#define ioctlsocket(a,b,c) lwip_ioctl_mt(a,b,c)
#define accept(a,b,c) lwip_accept_mt(a,b,c)
#define bind(a,b,c) lwip_bind_mt(a,b,c)
#define shutdown(a,b) lwip_shutdown_mt(a,b)
#define closesocket(s) lwip_close_mt(s)
#define connect(a,b,c) lwip_connect_mt(a,b,c)
#define getsockname(a,b,c) lwip_getsockname_mt(a,b,c)
#define getpeername(a,b,c) lwip_getpeername_mt(a,b,c)
@ -87,12 +100,6 @@ int lwip_trace_tcp(int s, int cmd, void *arg);
#define close(s) lwip_close_mt(s)
#define fcntl(a,b,c) lwip_fcntl_mt(a,b,c)
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
#endif /* SOCKETS_MT_DBUG */
#endif /* LWIP_COMPAT_SOCKETS */
#endif /* SOCKETS_MT */
#endif
#endif /* _SOCKET_H_ */