log config for multi instances
parent
de6def01e4
commit
0f2b3a8e2c
|
|
@ -0,0 +1,33 @@
|
|||
# Makefile.in
|
||||
src/Makefile
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dSYM
|
||||
*.dll
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.out
|
||||
|
||||
# other
|
||||
*.swp
|
||||
134
src/sf_global.c
134
src/sf_global.c
|
|
@ -28,17 +28,13 @@ SFGlobalVariables g_sf_global_vars = {
|
|||
|
||||
SFContext g_sf_context = {
|
||||
NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
|
||||
{'\0'}, {'\0'}, 0, true, NULL, NULL, sf_task_finish_clean_up,
|
||||
NULL
|
||||
{'\0'}, {'\0'}, 0, true, NULL, NULL, NULL,
|
||||
sf_task_finish_clean_up, NULL
|
||||
};
|
||||
|
||||
static void sf_get_config_str_value(IniContext *pIniContext,
|
||||
const char *section_name, const char *item_name,
|
||||
static inline void set_config_str_value(const char *value,
|
||||
char *dest, const int dest_size)
|
||||
{
|
||||
char *value;
|
||||
|
||||
value = iniGetStrValue(section_name, item_name, pIniContext);
|
||||
if (value == NULL) {
|
||||
*dest = '\0';
|
||||
} else {
|
||||
|
|
@ -263,16 +259,53 @@ int sf_load_context_from_config(SFContext *sf_context,
|
|||
const char *section_name, const int default_inner_port,
|
||||
const int default_outer_port)
|
||||
{
|
||||
sf_context->inner_port = iniGetIntValue(section_name,
|
||||
"inner_port", pIniContext, default_inner_port);
|
||||
sf_context->outer_port = iniGetIntValue(section_name,
|
||||
"outer_port", pIniContext, default_outer_port);
|
||||
char *inner_port;
|
||||
char *outer_port;
|
||||
char *inner_bind_addr;
|
||||
char *outer_bind_addr;
|
||||
char *bind_addr;
|
||||
int port;
|
||||
|
||||
sf_get_config_str_value(pIniContext, section_name,
|
||||
"inner_bind_addr", sf_context->inner_bind_addr,
|
||||
sf_context->inner_port = sf_context->outer_port = 0;
|
||||
|
||||
inner_port = iniGetStrValue(section_name, "inner_port", pIniContext);
|
||||
outer_port = iniGetStrValue(section_name, "outer_port", pIniContext);
|
||||
if (inner_port == NULL && outer_port == NULL) {
|
||||
port = iniGetIntValue(section_name, "port", pIniContext, 0);
|
||||
if (port > 0) {
|
||||
sf_context->inner_port = sf_context->outer_port = port;
|
||||
}
|
||||
} else {
|
||||
if (inner_port != NULL) {
|
||||
sf_context->inner_port = atoi(inner_port);
|
||||
}
|
||||
if (outer_port != NULL) {
|
||||
sf_context->outer_port = atoi(outer_port);
|
||||
}
|
||||
}
|
||||
|
||||
if (sf_context->inner_port <= 0) {
|
||||
sf_context->inner_port = default_inner_port;
|
||||
}
|
||||
if (sf_context->outer_port <= 0) {
|
||||
sf_context->outer_port = default_outer_port;
|
||||
}
|
||||
|
||||
|
||||
inner_bind_addr = iniGetStrValue(section_name,
|
||||
"inner_bind_addr", pIniContext);
|
||||
outer_bind_addr = iniGetStrValue(section_name,
|
||||
"outer_bind_addr", pIniContext);
|
||||
if (inner_bind_addr == NULL && outer_bind_addr == NULL) {
|
||||
bind_addr = iniGetStrValue(section_name,
|
||||
"bind_addr", pIniContext);
|
||||
if (bind_addr != NULL) {
|
||||
inner_bind_addr = outer_bind_addr = bind_addr;
|
||||
}
|
||||
}
|
||||
set_config_str_value(inner_bind_addr, sf_context->inner_bind_addr,
|
||||
sizeof(sf_context->inner_bind_addr));
|
||||
sf_get_config_str_value(pIniContext, section_name,
|
||||
"outer_bind_addr", sf_context->outer_bind_addr,
|
||||
set_config_str_value(outer_bind_addr, sf_context->outer_bind_addr,
|
||||
sizeof(sf_context->outer_bind_addr));
|
||||
|
||||
sf_context->accept_threads = iniGetIntValue(section_name,
|
||||
|
|
@ -300,31 +333,52 @@ int sf_load_context_from_config(SFContext *sf_context,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void sf_log_config_ex(const char *other_config)
|
||||
void sf_context_config_to_string(const SFContext *sf_context,
|
||||
char *output, const int size)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if ((sf_context->inner_port == sf_context->outer_port) &&
|
||||
(strcmp(sf_context->inner_bind_addr,
|
||||
sf_context->outer_bind_addr) == 0))
|
||||
{
|
||||
len += snprintf(output + len, size - len,
|
||||
"port=%d, bind_addr=%s",
|
||||
sf_context->inner_port,
|
||||
sf_context->inner_bind_addr);
|
||||
} else {
|
||||
len += snprintf(output + len, size - len,
|
||||
"inner_port=%d, inner_bind_addr=%s, "
|
||||
"outer_port=%d, outer_bind_addr=%s",
|
||||
sf_context->inner_port, sf_context->inner_bind_addr,
|
||||
sf_context->outer_port, sf_context->outer_bind_addr);
|
||||
}
|
||||
|
||||
len += snprintf(output + len, size - len,
|
||||
", accept_threads=%d, work_threads=%d",
|
||||
sf_context->accept_threads, sf_context->work_threads);
|
||||
}
|
||||
|
||||
void sf_global_config_to_string(char *output, const int size)
|
||||
{
|
||||
char sz_thread_stack_size[32];
|
||||
char sz_max_pkg_size[32];
|
||||
char sz_min_buff_size[32];
|
||||
char sz_max_buff_size[32];
|
||||
|
||||
logInfo("base_path=%s, inner_port=%d, inner_bind_addr=%s, "
|
||||
"outer_port=%d, outer_bind_addr=%s, "
|
||||
"max_connections=%d, accept_threads=%d, work_threads=%d, "
|
||||
"connect_timeout=%d, network_timeout=%d, thread_stack_size=%s, "
|
||||
"max_pkg_size=%s, min_buff_size=%s, max_buff_size=%s, "
|
||||
"log_level=%s, sync_log_buff_interval=%d, rotate_error_log=%d, "
|
||||
"log_file_keep_days=%d, run_by_group=%s, run_by_user=%s%s%s",
|
||||
snprintf(output, size,
|
||||
"base_path=%s, max_connections=%d, connect_timeout=%d, "
|
||||
"network_timeout=%d, thread_stack_size=%s, max_pkg_size=%s, "
|
||||
"min_buff_size=%s, max_buff_size=%s, log_level=%s, "
|
||||
"sync_log_buff_interval=%d, rotate_error_log=%d, "
|
||||
"log_file_keep_days=%d, run_by_group=%s, run_by_user=%s",
|
||||
g_sf_global_vars.base_path,
|
||||
g_sf_context.inner_port,
|
||||
g_sf_context.inner_bind_addr,
|
||||
g_sf_context.outer_port,
|
||||
g_sf_context.outer_bind_addr,
|
||||
g_sf_global_vars.max_connections,
|
||||
g_sf_context.accept_threads,
|
||||
g_sf_context.work_threads,
|
||||
g_sf_global_vars.connect_timeout,
|
||||
g_sf_global_vars.network_timeout,
|
||||
int_to_comma_str(g_sf_global_vars.thread_stack_size, sz_thread_stack_size),
|
||||
int_to_comma_str(g_sf_global_vars.thread_stack_size,
|
||||
sz_thread_stack_size),
|
||||
int_to_comma_str(g_sf_global_vars.max_pkg_size, sz_max_pkg_size),
|
||||
int_to_comma_str(g_sf_global_vars.min_buff_size, sz_min_buff_size),
|
||||
int_to_comma_str(g_sf_global_vars.max_buff_size, sz_max_buff_size),
|
||||
|
|
@ -333,8 +387,22 @@ void sf_log_config_ex(const char *other_config)
|
|||
g_sf_global_vars.rotate_error_log,
|
||||
g_sf_global_vars.log_file_keep_days,
|
||||
g_sf_global_vars.run_by_group,
|
||||
g_sf_global_vars.run_by_user,
|
||||
(other_config != NULL ? ", " : ""),
|
||||
(other_config != NULL ? other_config : "")
|
||||
g_sf_global_vars.run_by_user
|
||||
);
|
||||
}
|
||||
|
||||
void sf_log_config_ex(const char *other_config)
|
||||
{
|
||||
char sz_global_config[512];
|
||||
char sz_context_config[128];
|
||||
|
||||
sf_global_config_to_string(sz_global_config, sizeof(sz_global_config));
|
||||
sf_context_config_to_string(&g_sf_context,
|
||||
sz_context_config, sizeof(sz_context_config));
|
||||
|
||||
logInfo("%s, %s%s%s",
|
||||
sz_global_config, sz_context_config,
|
||||
(other_config != NULL && *other_config != '\0') ? ", " : "",
|
||||
(other_config != NULL) ? other_config : ""
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@ typedef struct sf_connection_stat {
|
|||
volatile int max_count;
|
||||
} SFConnectionStat;
|
||||
|
||||
typedef struct sf_custom_config {
|
||||
const char *item_prefix_name;
|
||||
int default_port;
|
||||
} SFCustomConfig;
|
||||
|
||||
typedef struct sf_global_variables {
|
||||
int connect_timeout;
|
||||
int network_timeout;
|
||||
|
|
@ -57,12 +52,10 @@ extern SFContext g_sf_context;
|
|||
#define SF_G_NETWORK_TIMEOUT g_sf_global_vars.network_timeout
|
||||
#define SF_G_THREAD_STACK_SIZE g_sf_global_vars.thread_stack_size
|
||||
#define SF_G_WORK_THREADS g_sf_context.work_threads
|
||||
#define SF_G_ALIVE_THREAD_COUNT g_sf_context.thread_count
|
||||
|
||||
#define SF_SET_CUSTOM_CONFIG(cfg, prefix_name, port) \
|
||||
do { \
|
||||
(cfg).item_prefix_name = prefix_name; \
|
||||
(cfg).default_port = port; \
|
||||
} while (0)
|
||||
#define SF_WORK_THREADS(sf_context) sf_context.work_threads
|
||||
#define SF_ALIVE_THREAD_COUNT(sf_context) sf_context.thread_count
|
||||
|
||||
#define SF_CHOWN_RETURN_ON_ERROR(path, current_uid, current_gid) \
|
||||
do { \
|
||||
|
|
@ -94,6 +87,11 @@ int sf_load_context_from_config(SFContext *sf_context,
|
|||
const char *section_name, const int default_inner_port,
|
||||
const int default_outer_port);
|
||||
|
||||
void sf_global_config_to_string(char *output, const int size);
|
||||
|
||||
void sf_context_config_to_string(const SFContext *sf_context,
|
||||
char *output, const int size);
|
||||
|
||||
void sf_log_config_ex(const char *other_config);
|
||||
|
||||
#define sf_log_config() sf_log_config_ex(NULL)
|
||||
|
|
|
|||
|
|
@ -53,11 +53,11 @@ static void sf_task_detach_thread(struct fast_task_info *pTask)
|
|||
}
|
||||
}
|
||||
|
||||
void sf_task_switch_thread_ex(SFContext *sf_context,
|
||||
struct fast_task_info *pTask, const int new_thread_index)
|
||||
void sf_task_switch_thread(struct fast_task_info *pTask,
|
||||
const int new_thread_index)
|
||||
{
|
||||
sf_task_detach_thread(pTask);
|
||||
pTask->thread_data = sf_context->thread_data + new_thread_index;
|
||||
pTask->thread_data = SF_CTX->thread_data + new_thread_index;
|
||||
}
|
||||
|
||||
void sf_task_finish_clean_up(struct fast_task_info *pTask)
|
||||
|
|
|
|||
19
src/sf_nio.h
19
src/sf_nio.h
|
|
@ -50,24 +50,18 @@ int sf_client_sock_read(int sock, short event, void *arg);
|
|||
|
||||
void sf_task_finish_clean_up(struct fast_task_info *pTask);
|
||||
|
||||
void sf_task_switch_thread_ex(SFContext *sf_context,
|
||||
struct fast_task_info *pTask, const int new_thread_index);
|
||||
|
||||
#define sf_task_switch_thread(pTask, new_thread_index) \
|
||||
sf_task_switch_thread_ex(&g_sf_context, pTask, new_thread_index)
|
||||
|
||||
int sf_nio_notify(struct fast_task_info *pTask, const int stage);
|
||||
|
||||
static inline int sf_nio_forward_request_ex(SFContext *sf_context,
|
||||
struct fast_task_info *pTask, const int new_thread_index)
|
||||
void sf_task_switch_thread(struct fast_task_info *pTask,
|
||||
const int new_thread_index);
|
||||
|
||||
static inline int sf_nio_forward_request(struct fast_task_info *pTask,
|
||||
const int new_thread_index)
|
||||
{
|
||||
sf_task_switch_thread_ex(sf_context, pTask, new_thread_index);
|
||||
sf_task_switch_thread(pTask, new_thread_index);
|
||||
return sf_nio_notify(pTask, SF_NIO_STAGE_FORWARDED);
|
||||
}
|
||||
|
||||
#define sf_nio_forward_request(pTask, new_thread_index) \
|
||||
sf_nio_forward_request_ex(&g_sf_context, pTask, new_thread_index)
|
||||
|
||||
static inline bool sf_client_sock_in_read_stage(struct fast_task_info *pTask)
|
||||
{
|
||||
return (pTask->event.callback == (IOEventCallback)sf_client_sock_read);
|
||||
|
|
@ -78,4 +72,3 @@ static inline bool sf_client_sock_in_read_stage(struct fast_task_info *pTask)
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -235,7 +235,6 @@ static void *worker_thread_entrance(void *arg)
|
|||
struct worker_thread_context *thread_ctx;
|
||||
|
||||
thread_ctx = (struct worker_thread_context *)arg;
|
||||
|
||||
__sync_fetch_and_add(&thread_ctx->sf_context->thread_count, 1);
|
||||
|
||||
ioevent_loop(thread_ctx->thread_data,
|
||||
|
|
@ -268,6 +267,7 @@ int sf_socket_server_ex(SFContext *sf_context)
|
|||
int result;
|
||||
const char *bind_addr;
|
||||
|
||||
sf_context->inner_sock = sf_context->outer_sock = -1;
|
||||
if (sf_context->outer_port == sf_context->inner_port) {
|
||||
if (*sf_context->outer_bind_addr == '\0' ||
|
||||
*sf_context->inner_bind_addr == '\0') {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ typedef int (*sf_recv_timeout_callback)(struct fast_task_info *pTask);
|
|||
|
||||
typedef struct sf_context {
|
||||
struct nio_thread_data *thread_data;
|
||||
int thread_count;
|
||||
volatile int thread_count;
|
||||
int outer_sock;
|
||||
int inner_sock;
|
||||
|
||||
|
|
@ -35,9 +35,9 @@ typedef struct sf_context {
|
|||
bool remove_from_ready_list;
|
||||
sf_deal_task_func deal_task;
|
||||
sf_set_body_length_callback set_body_length;
|
||||
sf_accept_done_callback accept_done_func;
|
||||
TaskCleanUpCallback task_cleanup_func;
|
||||
sf_recv_timeout_callback timeout_callback;
|
||||
sf_accept_done_callback accept_done_func;
|
||||
} SFContext;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue