aboutsummaryrefslogtreecommitdiffstats
path: root/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 /src
parentfb84b14f79f186a624fcbb93c89d20df2978b41a (diff)
Feat: Fork support
Change-Id: Iae75c1c0bd4961ee052428bdd661d6f1da1bdbcb Signed-off-by: Swarup Nayak <swarupnpvt@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/nSocket/include/nstack_dmm_api.h1
-rw-r--r--src/nSocket/include/nstack_select.h2
-rw-r--r--src/nSocket/kernel/linux_kernel_module.c1
-rw-r--r--src/nSocket/nstack/event/select/nstack_select.c22
-rw-r--r--src/nSocket/nstack/nstack.c2
-rw-r--r--src/nSocket/nstack/nstack_module.c20
-rw-r--r--src/nSocket/nstack/nstack_module.h1
-rw-r--r--src/nSocket/nstack/nstack_socket.c2
8 files changed, 50 insertions, 1 deletions
diff --git a/src/nSocket/include/nstack_dmm_api.h b/src/nSocket/include/nstack_dmm_api.h
index dff69f3..ab06650 100644
--- a/src/nSocket/include/nstack_dmm_api.h
+++ b/src/nSocket/include/nstack_dmm_api.h
@@ -57,6 +57,7 @@ typedef enum
typedef struct __nstack_extern_ops
{
int (*module_init) (void); /*stack module init */
+ int (*module_init_child) (void); /*stack module init for child process */
int (*fork_init_child) (pid_t p, pid_t c); /*after fork, stack child process init again if needed. */
void (*fork_parent_fd) (int s, pid_t p); /*after fork, stack parent process proc again if needed. */
void (*fork_child_fd) (int s, pid_t p, pid_t c); /*after fork, child record pid for recycle if needed. */
diff --git a/src/nSocket/include/nstack_select.h b/src/nSocket/include/nstack_select.h
index 5c84846..659c477 100644
--- a/src/nSocket/include/nstack_select.h
+++ b/src/nSocket/include/nstack_select.h
@@ -141,6 +141,8 @@ extern i32 select_add_cb (struct select_entry *entry);
extern i32 select_rm_cb (struct select_entry *entry);
extern i32 select_entry_reset (struct select_entry *entry);
extern i32 select_module_init ();
+extern i32 select_module_init_child ();
+
extern struct select_module_info *get_select_module (void);
#ifdef __cplusplus
/* *INDENT-OFF* */
diff --git a/src/nSocket/kernel/linux_kernel_module.c b/src/nSocket/kernel/linux_kernel_module.c
index 6a262d0..eb3dd8d 100644
--- a/src/nSocket/kernel/linux_kernel_module.c
+++ b/src/nSocket/kernel/linux_kernel_module.c
@@ -324,6 +324,7 @@ kernel_stack_register (nstack_proc_cb * ops, nstack_event_cb * val)
ops->extern_ops.ep_ctl = kernel_ep_fd_add;
ops->extern_ops.ep_prewait_proc = kernel_prewait_proc;
ops->extern_ops.module_init = kernel_module_init;
+ ops->extern_ops.module_init_child = kernel_module_init;
ops->extern_ops.stack_alloc_fd = kernel_fd_alloc;
/* don't close file descriptor */
diff --git a/src/nSocket/nstack/event/select/nstack_select.c b/src/nSocket/nstack/event/select/nstack_select.c
index ba64cff..930f1db 100644
--- a/src/nSocket/nstack/event/select/nstack_select.c
+++ b/src/nSocket/nstack/event/select/nstack_select.c
@@ -753,4 +753,26 @@ nssct_set_index (i32 fd, i32 inx)
select_set_index (fd, inx);
}
+i32
+select_module_init_child ()
+{
+ pthread_t select_thread_id;
+ i32 retval;
+
+ if (pthread_create (&select_thread_id, NULL, nstack_select_thread, NULL))
+ {
+ goto ERR_RET;
+ }
+
+ retval = pthread_setname_np (select_thread_id, "nstack_select_child");
+ if (retval)
+ {
+ /*set thread name failed */
+ }
+ return TRUE;
+
+ERR_RET:
+ return FALSE;
+}
+
#endif /* NSTACK_SELECT_MODULE */
diff --git a/src/nSocket/nstack/nstack.c b/src/nSocket/nstack/nstack.c
index 707cb49..861bc37 100644
--- a/src/nSocket/nstack/nstack.c
+++ b/src/nSocket/nstack/nstack.c
@@ -587,7 +587,7 @@ nstack_for_epoll_init ()
NSSOC_LOGINF ("fork]g_nStackInfo.pid=%u,getpid=%d", g_nStackInfo.pid,
getpid ());
- nstack_stack_module_init();
+ nstack_stack_module_init_child();
}
return 0;
}
diff --git a/src/nSocket/nstack/nstack_module.c b/src/nSocket/nstack/nstack_module.c
index bef91e5..9566ab8 100644
--- a/src/nSocket/nstack/nstack_module.c
+++ b/src/nSocket/nstack/nstack_module.c
@@ -265,3 +265,23 @@ nstack_stack_module_init ()
}
return 0;
}
+
+int
+nstack_stack_module_init_child ()
+{
+ ns_uint32 idx;
+ for (idx = 0; idx < g_module_num; idx++)
+ {
+ if (g_nstack_modules.modules[idx].mops.extern_ops.module_init_child)
+ {
+ if (0 !=
+ g_nstack_modules.modules[idx].mops.
+ extern_ops.module_init_child ())
+ {
+ NSSOC_LOGERR ("nstack[%s] modx:%d init child fail",
+ g_nstack_modules.modules[idx].modulename, idx);
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/nSocket/nstack/nstack_module.h b/src/nSocket/nstack/nstack_module.h
index e0105af..ec81ac1 100644
--- a/src/nSocket/nstack/nstack_module.h
+++ b/src/nSocket/nstack/nstack_module.h
@@ -135,6 +135,7 @@ extern nstack_module_keys g_nstack_module_desc[];
for ((modInx) = 0; ((modInx) < nstack_get_modNum() && (pMod = nstack_get_module((modInx)))); (modInx)++)
int nstack_stack_module_init ();
+int nstack_stack_module_init_child ();
int nstack_get_deploy_type ();
diff --git a/src/nSocket/nstack/nstack_socket.c b/src/nSocket/nstack/nstack_socket.c
index e3da248..cd1557b 100644
--- a/src/nSocket/nstack/nstack_socket.c
+++ b/src/nSocket/nstack/nstack_socket.c
@@ -2775,6 +2775,8 @@ nstack_fork (void)
dmm_spinlock_lock_with_pid (nstack_get_fork_share_lock (),
get_sys_pid ());
nsep_fork_child_proc (parent_pid);
+
+ (void) select_module_init_child ();
common_mem_spinlock_unlock (nstack_get_fork_share_lock ());
}
else if (pid > 0)