add function: sf_set_sig_quit_handler

connection_manager
YuQing 2020-08-30 16:44:09 +08:00
parent e7ff5f487f
commit 9e0f2dda7b
2 changed files with 17 additions and 10 deletions

View File

@ -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;
}

View File

@ -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
}