diff options
author | charan makkina <charan795m@gmail.com> | 2019-04-30 17:40:53 +0530 |
---|---|---|
committer | charan makkina <charan795m@gmail.com> | 2019-05-20 18:14:40 +0530 |
commit | a826fe833d3f2a8fe2673fa05811fe1a22baf045 (patch) | |
tree | da11a17c46ca9b8a002a52a290628574fa3f5eda /src/nSocket/nstack/nstack_fd_mng.h | |
parent | 3e6bf7b64eea418c59959c18750261b815b2892c (diff) |
Feature: 19.04 part 1
Change-Id: Ibba924b8deca1f246b9dcb12d89d085b6fd33046
Signed-off-by: charan makkina <charan795m@gmail.com>
Diffstat (limited to 'src/nSocket/nstack/nstack_fd_mng.h')
-rw-r--r-- | src/nSocket/nstack/nstack_fd_mng.h | 179 |
1 files changed, 102 insertions, 77 deletions
diff --git a/src/nSocket/nstack/nstack_fd_mng.h b/src/nSocket/nstack/nstack_fd_mng.h index cb25e8e..fcf7ed4 100644 --- a/src/nSocket/nstack/nstack_fd_mng.h +++ b/src/nSocket/nstack/nstack_fd_mng.h @@ -18,15 +18,17 @@ #define __NSTACK_FD_MNG_H__ #include <semaphore.h> +#ifndef SPL_INSTANCE_H #include "nstack_atomic.h" +#endif #include "types.h" #include "nstack_module.h" -#include "nstack_types.h" -#include "nstack_eventpoll.h" -#include "common_mem_spinlock.h" -#include "common_mem_api.h" -#include "common_func.h" + +#include "pid_common.h" +#include "nsfw_maintain_api.h" +#include "dmm_spinlock.h" +#include "nstack_rd_priv.h" #ifdef __cplusplus /* *INDENT-OFF* */ @@ -34,12 +36,14 @@ extern "C" { /* *INDENT-ON* */ #endif +#define KERNEL_FD_SUPPORT 1 + #define NSTACK_FDT_BLOCK_NOFFSET 10 #define NSTACK_FDT_CONVERT_FLAG 0x40000000 /* flag set means nstack socket */ -#define NSTACK_MAX_SOCK_NUM 8192 +#define NSTACK_MAX_SOCK_NUM MAX_SOCKET_NUM -#define NSTACK_MAX_PID 65536 /* release sockets when app exit */ +#define NSTACK_MAX_PID 65536 /* release sockets when app exit Add */ #ifndef AF_INET #define AF_INET 2 @@ -50,28 +54,37 @@ extern "C" { /* setsockopt level type*/ enum { - NSTACK_SOCKOPT = 0xff02 + NSTACK_SOCKOPT = 0xff02 }; /*setsockopt optname type*/ enum { - NSTACK_SEM_SLEEP = 0X001 + NSTACK_SEM_SLEEP = 0X001, + MPTCP_SET_PRIO = 0X002, + NSTACK_RD_MODE = 0X003, +}; + +enum +{ + NSTACK_RD_OPT_KERNEL = 0, + NSTACK_RD_OPT_STACKPOOL = 1, + NSTACK_RD_OPT_MAX = 2, }; #endif #define nstack_is_nstack_sk(fd) ((fd) >= 0 && ((fd) < (int)NSTACK_KERNEL_FD_MAX)) typedef enum __nstack_fd_Stat { - NSTACK_FD_INUSING, - NSTACK_FD_DISCARD + NSTACK_FD_INUSING, + NSTACK_FD_DISCARD } nstack_fd_stat; #define NSTACK_BIND_SUCCESS 0 #define NSTACK_LISTEN_SUCCESS 0 #define NSTACK_LISTEN_FAIL 1 #define NSTACK_BIND_FAIL 1 -#define NSTACK_LISTENING 1 -#define NSTACK_NO_LISTENING 0 +#define NSTACK_LISENING 1 +#define NSTACK_NO_LISENING 0 #define NSTACK_FD_INIT (0) #define NSTACK_FD_OPEN (1) @@ -80,81 +93,94 @@ typedef enum __nstack_fd_Stat #define NSTACK_FD_NOBIND (0) #define NSTACK_FD_BIND (1) -/* release sockets when app exit */ - typedef struct { - ns_int32 fd; - ns_int32 errCode; - union - { - struct result + ns_int32 fd; + ns_int32 errCode; + union { - ns_int32 brslt:8; - ns_int32 lrslt:8; - ns_int32 resrv:16; - } rslt; - ns_int32 pad; - }; - ns_int32 liststate; + struct reslt + { + ns_int32 brslt:8; + ns_int32 lrslt:8; + ns_int32 resrv:16; + } rslt; + ns_int32 pad; + }; + ns_int32 liststate; } __attribute__ ((__packed__)) nstack_protoFD_t; -#define NSTACK_FD_ATTR_NONBLOCKING 0x00000001 +#define NSTACK_FD_ATTR_NONBLOKING 0x00000001 #define NSTACK_FD_ATTR_EPOLL_SOCKET 0x00000002 #define NSTACK_FD_ATTR_LISTEN_SOCKET 0x00000004 -#define NSTACK_IS_FD_NONBLOCKING(inf) ((inf)->attr & NSTACK_FD_ATTR_NONBLOCKING) -#define NSTACK_SET_FD_NONBLOCKING(inf) ((inf)->attr |= NSTACK_FD_ATTR_NONBLOCKING) -#define NSTACK_SET_FD_BLOCKING(inf) ((inf)->attr &= (~NSTACK_FD_ATTR_NONBLOCKING)) +#define NSTACK_IS_FD_NONBLOKING(inf) ((inf)->attr & NSTACK_FD_ATTR_NONBLOKING) +#define NSTACK_SET_FD_NONBLOKING(inf) ((inf)->attr |= NSTACK_FD_ATTR_NONBLOKING) +#define NSTACK_SET_FD_BLOKING(inf) ((inf)->attr &= (~NSTACK_FD_ATTR_NONBLOKING)) #define NSTACK_IS_FD_EPOLL_SOCKET(inf) ((inf)->attr & NSTACK_FD_ATTR_EPOLL_SOCKET) #define NSTACK_SET_FD_EPOLL_SOCKET(inf) ((inf)->attr |= NSTACK_FD_ATTR_EPOLL_SOCKET) #define NSTACK_IS_FD_LISTEN_SOCKET(inf) ((inf)->attr & NSTACK_FD_ATTR_LISTEN_SOCKET) #define NSTACK_SET_FD_LISTEN_SOCKET(inf) ((inf)->attr |= NSTACK_FD_ATTR_LISTEN_SOCKET) +#define NSTACK_SET_FD_ATTR(inf, _attr) ((inf)->attr |= (_attr)) +#define NSTACK_IS_FD_ATTR(inf, _attr) ((inf)->attr &= (_attr)) + typedef struct { - atomic_t fd_ref; - common_mem_spinlock_t close_lock; - volatile int fd_status; + atomic_t fd_ref; + dmm_spinlock_t close_lock; + volatile int fd_status; } nstack_fd_local_lock_info_t; + /* fd_ref:the number of times the fd is used, when it is 0, should release fd resource close_lock:lock for close and epoll fd_status:when created, it is FD_OPEN;after close, it is FD_CLOSING;after release_fd, it is FD_CLOSE. -- Begin */ +*/ typedef enum { - FD_CLOSE, - FD_OPEN, - FD_CLOSING + FD_CLOSE, + FD_OPEN, + FD_CLOSING } FD_STATUS; typedef enum { - NSTACK_STATE_CLOSE, - NSTACK_STATE_OPEN, - NSTACK_STATE_MAX + NSTACK_STATE_CLOSE, + NSTACK_STATE_OPEN, + NSTACK_STATE_MAX } nstack_fdstate; + typedef struct __nstack_fd_Inf { - ns_int32 rlfd; /*the protocl stack returned fd */ - ns_int32 rmidx; - ns_int32 nxtfd; - nstack_socket_ops *ops; /*opers of the fd, for save space we user opIdx here */ - ns_int32 type; /*the fd type like SOCK_STREAM|SOCK_NONBLOCK ... */ - ns_int32 stat; - ns_int32 fd; - ns_uint32 attr; /* attribute like non-blocking, listen socket , epoll socket.... */ - - nstack_protoFD_t protoFD[NSTACK_MAX_MODULE_NUM]; // where is protocol fd stores, index is module type - nstack_fd_local_lock_info_t local_lock; - /* if has bound to an addr */ - u8_t isBound; /*0:no call bind, 1: call bind */ - char last_reserve[2]; //reserve for update + ns_int32 rlfd; /*the protocl stack returned fd */ + ns_int32 rmidx; + ns_int32 nxtfd; + nstack_socket_ops *ops; /*opers of the fd, for save space we user opIdx here */ + ns_int32 type; /*the fd type like SOCK_STREAM|SOCK_NONBLOCK ... */ + ns_int32 stat; + ns_int32 fd; + ns_uint32 attr; /* attribute like non-blocking, listen socket , epoll socket.... */ + ns_int32 rd_opt; /* select stacks by setsockopt */ + + nstack_protoFD_t protoFD[NSTACK_MAX_MODULE_NUM]; // where is protocol fd stores, index is module type + nstack_fd_local_lock_info_t local_lock; + /* if has bound to an addr */ + u8_t isBound; /*0:no call bind, 1: call bind */ + rd_data_item rd_item; // associated matched rd item + char last_reserve[2]; //reserve for update } nstack_fd_Inf; +// TODO: DFX function +/* +typedef struct __ns_udp_route_info{ + struct sockaddr_in iaddr; + int selectmod; +}ns_udp_route_Inf; +*/ + #define nstack_set_router_protocol(_fdInf, _proto) \ (_fdInf)->rmidx = (_proto); \ nsep_set_infomdix((_fdInf)->fd, (_proto));\ @@ -162,26 +188,25 @@ typedef struct __nstack_fd_Inf #define nstack_set_routed_fd(_fdInf, _protoFD) \ (_fdInf)->rlfd = (_protoFD); \ - nsep_set_infoRlfd((_fdInf)->fd, (_protoFD));\ + nsep_set_info_rlfd((_fdInf)->fd, (_protoFD));\ -nstack_fd_Inf *nstack_fd2inf (int fd); +nstack_fd_Inf *nstack_fd2inf(int fd); -void nstack_reset_fdInf (nstack_fd_Inf * fdInf); +void nstack_reset_fd_inf(nstack_fd_Inf * fdInf); -static inline nstack_fd_Inf * -nstack_getValidInf (int fd) +static inline nstack_fd_Inf *nstack_get_valid_inf(int fd) { - nstack_fd_Inf *retInf = NULL; - retInf = nstack_fd2inf (fd); - if (NULL == retInf || FD_OPEN != retInf->local_lock.fd_status) + nstack_fd_Inf *retInf = NULL; + retInf = nstack_fd2inf(fd); + if (NULL == retInf || FD_OPEN != retInf->local_lock.fd_status) { - return NULL; + return NULL; } - return retInf; + return retInf; } -#define nstack_get_protoFd(fdInf, modInx) ((fdInf)->protoFD[modInx].fd) +#define nstack_get_proto_fd(fdInf, modInx) ((fdInf)->protoFD[modInx].fd) #define nstack_set_bind_ret(fdInf, modInx, ret) ((fdInf)->protoFD[modInx].rslt.brslt = ret) #define nstack_set_listen_ret(fdInf, modInx, ret) ((fdInf)->protoFD[modInx].rslt.lrslt = ret) #define nstack_set_ret(fdInf, modInx, ret) ((fdInf)->protoFD[modInx].pad = ret) @@ -189,17 +214,17 @@ nstack_getValidInf (int fd) #define nstack_get_listen_state(fdInf, modInx) ((fdInf)->protoFD[modInx].liststate) #define nstack_get_listen_ret(fdInf, modInx) ((fdInf)->protoFD[modInx].rslt.lrslt) #define nstack_get_bind_ret(fdInf, modInx) ((fdInf)->protoFD[modInx].rslt.brslt) -#define nstack_get_protoFdSt(fdInf, modInx) (&(fdInf)->protoFD[modInx]) -void nstack_set_protoFd (nstack_fd_Inf * fdInf, int modInx, int protofd); -void nstack_set_app_info (nstack_fd_Inf * fdInf, int modInx); - -int nstack_fd_free_with_kernel (nstack_fd_Inf * fdInf); -int nstack_fd_free_without_kernel (nstack_fd_Inf * fdInf, int ref); -extern nstack_fd_Inf *nstack_lk_fd_alloc_with_kernel (int nfd); //alloc a nstack socket that include kernel fd -extern void nstack_fd_free (nstack_fd_Inf * fdInf); - -void nstack_fork_init_child (pid_t ppid); -void nstack_fork_init_parent (pid_t ppid); +#define nstack_get_proto_fd_st(fdInf, modInx) (&(fdInf)->protoFD[modInx]) +void nstack_set_proto_fd(nstack_fd_Inf * fdInf, int modInx, int protofd); +void nstack_set_app_info(nstack_fd_Inf * fdInf, int modInx); +int nstack_fd_free_with_kernel(nstack_fd_Inf * fdInf); +int nstack_fd_free_without_kernel(nstack_fd_Inf * fdInf, int ref); +extern nstack_fd_Inf *nstack_lk_fd_alloc_with_kernel(int nfd); //alloc a nstack socket that include kernel fd +extern nstack_fd_Inf *nstack_lk_fd_alloc_without_kernel(); +extern void nstack_fd_free(nstack_fd_Inf * fdInf); + +void nstack_fork_init_child(pid_t ppid); +void nstack_fork_fd(pid_t ppid); #ifdef __cplusplus /* *INDENT-OFF* */ |