From 9bd094197e8dcc04a72db283cf46cd71bab2fede Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 5 Nov 2017 14:36:48 +0800 Subject: [libc] Add HAVE_SYS_SELECT_H/HAVE_SYS_SOCKET_H options. --- components/dfs/KConfig | 14 +++ components/dfs/filesystems/net/SConscript | 6 ++ components/dfs/filesystems/net/select/sys/select.h | 30 ++++++ components/dfs/filesystems/net/socket/sys/socket.h | 110 +++++++++++++++++++++ components/dfs/filesystems/net/sys/select.h | 30 ------ components/dfs/filesystems/net/sys/socket.h | 110 --------------------- 6 files changed, 160 insertions(+), 140 deletions(-) create mode 100644 components/dfs/filesystems/net/select/sys/select.h create mode 100644 components/dfs/filesystems/net/socket/sys/socket.h delete mode 100644 components/dfs/filesystems/net/sys/select.h delete mode 100644 components/dfs/filesystems/net/sys/socket.h diff --git a/components/dfs/KConfig b/components/dfs/KConfig index 97379b3e4e..e7dfb2abb8 100644 --- a/components/dfs/KConfig +++ b/components/dfs/KConfig @@ -96,6 +96,20 @@ if RT_USING_DFS help Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs. + if RT_USING_DFS_NET + config HAVE_SYS_SELECT_H + bool "Toolchains/libc have provide sys/select.h" + default n + help + Toolchains/libc have provide sys/select.h file, therefore, disable the sys/select.h in RT-Thread. + + config HAVE_SYS_SOCKET_H + bool "Toolchains/libc have provide sys/socket.h" + default n + help + Toolchains/libc have provide sys/socket.h file, therefore, disable the sys/socket.h in RT-Thread. + endif + config RT_USING_DFS_ROMFS bool "Enable ReadOnly file system on flash" default n diff --git a/components/dfs/filesystems/net/SConscript b/components/dfs/filesystems/net/SConscript index 810ca16fef..0b5e45c090 100644 --- a/components/dfs/filesystems/net/SConscript +++ b/components/dfs/filesystems/net/SConscript @@ -6,6 +6,12 @@ cwd = GetCurrentDir() src = Glob('*.c') CPPPATH = [cwd] +if not GetDepend('HAVE_SYS_SELECT_H'): + CPPPATH += [cwd + '/select'] + +if not GetDepend('HAVE_SYS_SOCKET_H'): + CPPPATH += [cwd + '/socket'] + group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS', 'RT_USING_DFS_NET'], CPPPATH = CPPPATH) Return('group') diff --git a/components/dfs/filesystems/net/select/sys/select.h b/components/dfs/filesystems/net/select/sys/select.h new file mode 100644 index 0000000000..ce91583904 --- /dev/null +++ b/components/dfs/filesystems/net/select/sys/select.h @@ -0,0 +1,30 @@ +/* + * File : select.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-05-02 Bernard First version + */ + +#ifndef SELECT_H__ +#define SELECT_H__ + +#include + +#endif diff --git a/components/dfs/filesystems/net/socket/sys/socket.h b/components/dfs/filesystems/net/socket/sys/socket.h new file mode 100644 index 0000000000..89e0c5bfa5 --- /dev/null +++ b/components/dfs/filesystems/net/socket/sys/socket.h @@ -0,0 +1,110 @@ +/* + * File : socket.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-02-17 Bernard First version + */ + +#ifndef SOCKET_H__ +#define SOCKET_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +#include + +#if LWIP_VERSION < 0x2000000 +typedef uint16_t sa_family_t; +typedef uint16_t in_port_t; + +struct sockaddr_storage +{ + sa_family_t ss_family; /* Address family */ + char ss_data[14]; /* 14-bytes of address data */ +}; +#endif + +#if LWIP_VERSION < 0x2000000 +#define SELWAIT_T int +#else +#ifndef SELWAIT_T +#define SELWAIT_T u8_t +#endif +#endif + +/* + * Re-define lwip socket + * + * NOTE: please make sure the definitions same in lwip::net_socket.c + */ +struct lwip_sock { + /** sockets currently are built on netconns, each socket has one netconn */ + struct netconn *conn; + /** data that was left from the previous read */ + void *lastdata; + /** offset in the data that was left from the previous read */ + u16_t lastoffset; + /** number of times data was received, set by event_callback(), + tested by the receive and select functions */ + s16_t rcvevent; + /** number of times data was ACKed (free send buffer), set by event_callback(), + tested by select */ + u16_t sendevent; + /** error happened for this socket, set by event_callback(), tested by select */ + u16_t errevent; + /** last error that occurred on this socket */ + int err; + /** counter of how many threads are waiting for this socket using select */ + SELWAIT_T select_waiting; + + rt_wqueue_t wait_head; +}; +struct lwip_sock *lwip_tryget_socket(int s); + +int accept(int s, struct sockaddr *addr, socklen_t *addrlen); +int bind(int s, const struct sockaddr *name, socklen_t namelen); +int shutdown(int s, int how); +int getpeername (int s, struct sockaddr *name, socklen_t *namelen); +int getsockname (int s, struct sockaddr *name, socklen_t *namelen); +int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); +int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); +int connect(int s, const struct sockaddr *name, socklen_t namelen); +int listen(int s, int backlog); +int recv(int s, void *mem, size_t len, int flags); +int recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen); +int send(int s, const void *dataptr, size_t size, int flags); +int sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen); +int socket(int domain, int type, int protocol); +int closesocket(int s); +int ioctlsocket(int s, long cmd, void *arg); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/dfs/filesystems/net/sys/select.h b/components/dfs/filesystems/net/sys/select.h deleted file mode 100644 index ce91583904..0000000000 --- a/components/dfs/filesystems/net/sys/select.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * File : select.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2015, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2015-05-02 Bernard First version - */ - -#ifndef SELECT_H__ -#define SELECT_H__ - -#include - -#endif diff --git a/components/dfs/filesystems/net/sys/socket.h b/components/dfs/filesystems/net/sys/socket.h deleted file mode 100644 index 89e0c5bfa5..0000000000 --- a/components/dfs/filesystems/net/sys/socket.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * File : socket.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2015, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2015-02-17 Bernard First version - */ - -#ifndef SOCKET_H__ -#define SOCKET_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#include - -#if LWIP_VERSION < 0x2000000 -typedef uint16_t sa_family_t; -typedef uint16_t in_port_t; - -struct sockaddr_storage -{ - sa_family_t ss_family; /* Address family */ - char ss_data[14]; /* 14-bytes of address data */ -}; -#endif - -#if LWIP_VERSION < 0x2000000 -#define SELWAIT_T int -#else -#ifndef SELWAIT_T -#define SELWAIT_T u8_t -#endif -#endif - -/* - * Re-define lwip socket - * - * NOTE: please make sure the definitions same in lwip::net_socket.c - */ -struct lwip_sock { - /** sockets currently are built on netconns, each socket has one netconn */ - struct netconn *conn; - /** data that was left from the previous read */ - void *lastdata; - /** offset in the data that was left from the previous read */ - u16_t lastoffset; - /** number of times data was received, set by event_callback(), - tested by the receive and select functions */ - s16_t rcvevent; - /** number of times data was ACKed (free send buffer), set by event_callback(), - tested by select */ - u16_t sendevent; - /** error happened for this socket, set by event_callback(), tested by select */ - u16_t errevent; - /** last error that occurred on this socket */ - int err; - /** counter of how many threads are waiting for this socket using select */ - SELWAIT_T select_waiting; - - rt_wqueue_t wait_head; -}; -struct lwip_sock *lwip_tryget_socket(int s); - -int accept(int s, struct sockaddr *addr, socklen_t *addrlen); -int bind(int s, const struct sockaddr *name, socklen_t namelen); -int shutdown(int s, int how); -int getpeername (int s, struct sockaddr *name, socklen_t *namelen); -int getsockname (int s, struct sockaddr *name, socklen_t *namelen); -int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); -int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); -int connect(int s, const struct sockaddr *name, socklen_t namelen); -int listen(int s, int backlog); -int recv(int s, void *mem, size_t len, int flags); -int recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen); -int send(int s, const void *dataptr, size_t size, int flags); -int sendto(int s, const void *dataptr, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen); -int socket(int domain, int type, int protocol); -int closesocket(int s); -int ioctlsocket(int s, long cmd, void *arg); - -#ifdef __cplusplus -} -#endif - -#endif -- cgit v1.3.1