add function: sf_set_sig_quit_handler
parent
e7ff5f487f
commit
9e0f2dda7b
|
|
@ -25,7 +25,8 @@
|
|||
#include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
static bool bTerminateFlag = false;
|
||||
static bool terminate_flag = false;
|
||||
static sf_sig_quit_handler sig_quit_handler = NULL;
|
||||
|
||||
static void sigQuitHandler(int sig);
|
||||
static void sigHupHandler(int sig);
|
||||
|
|
@ -476,12 +477,16 @@ static void sigDumpHandler(int sig)
|
|||
|
||||
static void sigQuitHandler(int sig)
|
||||
{
|
||||
if (!bTerminateFlag) {
|
||||
bTerminateFlag = true;
|
||||
if (!terminate_flag) {
|
||||
terminate_flag = true;
|
||||
g_sf_global_vars.continue_flag = false;
|
||||
if (sig_quit_handler != NULL) {
|
||||
sig_quit_handler(sig);
|
||||
}
|
||||
|
||||
logCrit("file: "__FILE__", line: %d, "
|
||||
"catch signal %d, program exiting...",
|
||||
__LINE__, sig);
|
||||
"catch signal %d, program exiting...",
|
||||
__LINE__, sig);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -629,3 +634,8 @@ struct nio_thread_data *sf_get_random_thread_data_ex(SFContext *sf_context)
|
|||
(uint64_t)rand() / (uint64_t)RAND_MAX);
|
||||
return sf_context->thread_data + index;
|
||||
}
|
||||
|
||||
void sf_set_sig_quit_handler(sf_sig_quit_handler quit_handler)
|
||||
{
|
||||
sig_quit_handler = quit_handler;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,16 +12,12 @@
|
|||
#include "sf_types.h"
|
||||
|
||||
typedef void* (*sf_alloc_thread_extra_data_callback)(const int thread_index);
|
||||
typedef void (*sf_sig_quit_handler)(int sig);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int g_server_outer_sock;
|
||||
extern int g_server_inner_sock;
|
||||
|
||||
extern int g_worker_thread_count;
|
||||
|
||||
int sf_service_init_ex2(SFContext *sf_context,
|
||||
sf_alloc_thread_extra_data_callback
|
||||
alloc_thread_extra_data_callback,
|
||||
|
|
@ -85,6 +81,7 @@ struct nio_thread_data *sf_get_random_thread_data_ex(SFContext *sf_context);
|
|||
#define sf_get_random_thread_data() \
|
||||
sf_get_random_thread_data_ex(&g_sf_context)
|
||||
|
||||
void sf_set_sig_quit_handler(sf_sig_quit_handler quit_handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue