summaryrefslogtreecommitdiffstats
path: root/stacks/lwip_stack/src
diff options
context:
space:
mode:
authorSwarup Nayak <swarupnpvt@gmail.com>2018-09-04 17:26:26 +0530
committerSwarup Nayak <swarupnpvt@gmail.com>2018-09-17 10:41:35 +0000
commit0a5a2aadb7789251a2cba285e0a680951c5db573 (patch)
tree47792ac05182fe9f96945e95d2e87ec408f2c90e /stacks/lwip_stack/src
parentfb84b14f79f186a624fcbb93c89d20df2978b41a (diff)
Feat: Fork support
Change-Id: Iae75c1c0bd4961ee052428bdd661d6f1da1bdbcb Signed-off-by: Swarup Nayak <swarupnpvt@gmail.com>
Diffstat (limited to 'stacks/lwip_stack/src')
-rw-r--r--stacks/lwip_stack/src/sbr/sbr_protocol_api.h4
-rw-r--r--stacks/lwip_stack/src/sbr/sbr_res_mgr.h31
-rw-r--r--stacks/lwip_stack/src/sbr/sbr_socket.c43
3 files changed, 77 insertions, 1 deletions
diff --git a/stacks/lwip_stack/src/sbr/sbr_protocol_api.h b/stacks/lwip_stack/src/sbr/sbr_protocol_api.h
index 1c0fb1e..0eac1c4 100644
--- a/stacks/lwip_stack/src/sbr/sbr_protocol_api.h
+++ b/stacks/lwip_stack/src/sbr/sbr_protocol_api.h
@@ -70,6 +70,8 @@ typedef struct
int (*peak) (sbr_socket_t *);
void (*lock_common) (sbr_socket_t *);
void (*unlock_common) (sbr_socket_t *);
+ void (*fork_parent) (sbr_socket_t *, pid_t);
+ void (*fork_child) (sbr_socket_t *, pid_t, pid_t);
unsigned int (*ep_ctl) (sbr_socket_t *, int triggle_ops,
struct epoll_event * event, void *pdata);
unsigned int (*ep_getevt) (sbr_socket_t *, unsigned int events);
@@ -86,7 +88,7 @@ struct sbr_socket_s
};
int sbr_init_protocol ();
-
+int sbr_fork_protocol ();
sbr_fdopt *sbr_get_fdopt (int domain, int type, int protocol);
void sbr_app_touch_in (void); /*app send its version info to nStackMain */
diff --git a/stacks/lwip_stack/src/sbr/sbr_res_mgr.h b/stacks/lwip_stack/src/sbr/sbr_res_mgr.h
index 54729d4..e731314 100644
--- a/stacks/lwip_stack/src/sbr/sbr_res_mgr.h
+++ b/stacks/lwip_stack/src/sbr/sbr_res_mgr.h
@@ -117,6 +117,37 @@ sbr_lookup_sk (int fd)
return sk;
}
+/*****************************************************************************
+* Prototype : sbr_free_sk
+* Description : free sock
+* Input : sbr_socket_t * sk
+* Output : None
+* Return Value : static inline void
+* Calls :
+* Called By :
+*
+*****************************************************************************/
+static inline void
+sbr_free_fd (int fd)
+{
+ if ((fd < 1) || (fd > SBR_MAX_FD_NUM))
+ {
+ NSSBR_LOGERR ("fd is not ok]fd=%d", fd);
+ sbr_set_errno (EBADF);
+ return;
+ }
+
+ sbr_socket_t *sk = &g_res_group.sk[fd];
+ if (!sk->fdopt && !sk->sk_obj && !sk->stack_obj)
+ {
+ NSSBR_LOGERR
+ ("can't free empty fd] fd=%d, fdopt=%p, sk_obj=%p, stack_obj=%p", fd,
+ sk->fdopt, sk->sk_obj, sk->stack_obj);
+ return;
+ }
+ sbr_free_sk (sk);
+}
+
int sbr_init_res ();
#ifdef __cplusplus
diff --git a/stacks/lwip_stack/src/sbr/sbr_socket.c b/stacks/lwip_stack/src/sbr/sbr_socket.c
index 47aefda..e088224 100644
--- a/stacks/lwip_stack/src/sbr/sbr_socket.c
+++ b/stacks/lwip_stack/src/sbr/sbr_socket.c
@@ -1197,6 +1197,45 @@ SBR_INTERCEPT (int, fd_alloc, ())
return sbr_socket (AF_INET, SOCK_STREAM, 0);
}
+SBR_INTERCEPT (int, fork_init_child, (pid_t p, pid_t c))
+{
+ NSSBR_LOGDBG ("fork_init_child() is called]");
+ return sbr_fork_protocol ();
+}
+
+SBR_INTERCEPT (void, fork_parent_fd, (int s, pid_t p))
+{
+ NSSBR_LOGDBG ("fork_parent_fd() is called]");
+ sbr_socket_t *sk = sbr_lookup_sk (s);
+
+ if (!sk)
+ {
+ return;
+ }
+
+ sk->fdopt->fork_parent (sk, p);
+}
+
+SBR_INTERCEPT (void, fork_child_fd, (int s, pid_t p, pid_t c))
+{
+ NSSBR_LOGDBG ("fork_child_fd() is called]");
+ sbr_socket_t *sk = sbr_lookup_sk (s);
+
+ if (!sk)
+ {
+ return;
+ }
+
+ sk->fdopt->fork_child (sk, p, c);
+
+}
+
+SBR_INTERCEPT (void, fork_free_fd, (int s, pid_t p, pid_t c))
+{
+ NSSBR_LOGDBG ("fork_free_fd() is called]");
+ sbr_free_fd (s);
+}
+
/*****************************************************************************
* Prototype : nstack_stack_register
* Description : reg api to nsocket
@@ -1227,5 +1266,9 @@ nstack_stack_register (nstack_proc_cb * ops, nstack_event_cb * val)
(ops->extern_ops).ep_ctl = GET_SBR_INTERCEPT (ep_ctl);
(ops->extern_ops).peak = GET_SBR_INTERCEPT (peak);
(ops->extern_ops).stack_alloc_fd = GET_SBR_INTERCEPT (fd_alloc); /*alloc a fd id for epoll */
+ (ops->extern_ops).fork_init_child = GET_SBR_INTERCEPT (fork_init_child);
+ (ops->extern_ops).fork_parent_fd = GET_SBR_INTERCEPT (fork_parent_fd);
+ (ops->extern_ops).fork_child_fd = GET_SBR_INTERCEPT (fork_child_fd);
+ (ops->extern_ops).fork_free_fd = GET_SBR_INTERCEPT (fork_free_fd);
return 0;
}