add function: sf_terminate_myself
parent
c8a4f5e138
commit
6ccf936ee5
|
|
@ -571,7 +571,7 @@ static void *binlog_writer_func(void *arg)
|
||||||
logCrit("file: "__FILE__", line: %d, "
|
logCrit("file: "__FILE__", line: %d, "
|
||||||
"deal_binlog_records fail, "
|
"deal_binlog_records fail, "
|
||||||
"program exit!", __LINE__);
|
"program exit!", __LINE__);
|
||||||
SF_G_CONTINUE_FLAG = false;
|
sf_terminate_myself();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ static void sf_memory_oom_notify_callback(const size_t curr_size)
|
||||||
logCrit("file: "__FILE__", line: %d, "
|
logCrit("file: "__FILE__", line: %d, "
|
||||||
"alloc %"PRId64" bytes fail, exiting ...",
|
"alloc %"PRId64" bytes fail, exiting ...",
|
||||||
__LINE__, (int64_t)curr_size);
|
__LINE__, (int64_t)curr_size);
|
||||||
SF_G_CONTINUE_FLAG = false;
|
sf_terminate_myself();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sf_enable_exit_on_oom()
|
void sf_enable_exit_on_oom()
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "fastcommon/common_define.h"
|
#include "fastcommon/common_define.h"
|
||||||
#include "sf_types.h"
|
#include "sf_types.h"
|
||||||
|
#include "sf_global.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -12,6 +13,24 @@ extern "C" {
|
||||||
|
|
||||||
int sf_connect_to_server(const char *ip_addr, const int port, int *sock);
|
int sf_connect_to_server(const char *ip_addr, const int port, int *sock);
|
||||||
|
|
||||||
|
#define sf_terminate_myself() \
|
||||||
|
sf_terminate_myself_ex(__FILE__, __LINE__, __FUNCTION__)
|
||||||
|
|
||||||
|
static inline void sf_terminate_myself_ex(const char *file,
|
||||||
|
const int line, const char *func)
|
||||||
|
{
|
||||||
|
g_sf_global_vars.continue_flag = false;
|
||||||
|
if (kill(getpid(), SIGQUIT) == 0) { //signal myself to quit
|
||||||
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
|
"kill myself from caller {file: %s, line: %d, func: %s}",
|
||||||
|
__LINE__, file, line, func);
|
||||||
|
} else {
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"kill myself fail, errno: %d, error info: %s",
|
||||||
|
__LINE__, errno, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sf_enable_exit_on_oom();
|
void sf_enable_exit_on_oom();
|
||||||
|
|
||||||
static inline int sf_binlog_buffer_init(SFBinlogBuffer *buffer, const int size)
|
static inline int sf_binlog_buffer_init(SFBinlogBuffer *buffer, const int size)
|
||||||
|
|
|
||||||
38
src/sf_nio.c
38
src/sf_nio.c
|
|
@ -98,7 +98,7 @@ static inline int set_write_event(struct fast_task_info *task)
|
||||||
task->event.fd, IOEVENT_WRITE, task) != 0)
|
task->event.fd, IOEVENT_WRITE, task) != 0)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOENT;
|
result = errno != 0 ? errno : ENOENT;
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
|
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"ioevent_modify fail, "
|
"ioevent_modify fail, "
|
||||||
|
|
@ -123,7 +123,7 @@ int sf_set_read_event(struct fast_task_info *task)
|
||||||
task->event.fd, IOEVENT_READ, task) != 0)
|
task->event.fd, IOEVENT_READ, task) != 0)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : ENOENT;
|
result = errno != 0 ? errno : ENOENT;
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
|
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"ioevent_modify fail, "
|
"ioevent_modify fail, "
|
||||||
|
|
@ -180,7 +180,7 @@ static int sf_client_sock_connect(int sock, short event, void *arg)
|
||||||
"connect to server %s:%u fail, errno: %d, "
|
"connect to server %s:%u fail, errno: %d, "
|
||||||
"error info: %s", __LINE__, task->server_ip,
|
"error info: %s", __LINE__, task->server_ip,
|
||||||
task->port, result, STRERROR(result));
|
task->port, result, STRERROR(result));
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,7 +278,7 @@ static int sf_nio_deal_task(struct fast_task_info *task)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -416,7 +416,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
if (task->offset == 0 && task->req_count > 0) {
|
if (task->offset == 0 && task->req_count > 0) {
|
||||||
if (SF_CTX->timeout_callback != NULL) {
|
if (SF_CTX->timeout_callback != NULL) {
|
||||||
if (SF_CTX->timeout_callback(task) != 0) {
|
if (SF_CTX->timeout_callback(task) != 0) {
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -438,7 +438,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
__LINE__, task->client_ip, task->req_count);
|
__LINE__, task->client_ip, task->req_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,7 +450,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
"client ip: %s, recv error event: %d, "
|
"client ip: %s, recv error event: %d, "
|
||||||
"close connection", __LINE__, task->client_ip, event);
|
"close connection", __LINE__, task->client_ip, event);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -493,7 +493,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
__LINE__, task->client_ip,
|
__LINE__, task->client_ip,
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (bytes == 0) {
|
} else if (bytes == 0) {
|
||||||
|
|
@ -519,7 +519,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
__LINE__, task->client_ip, sock);
|
__LINE__, task->client_ip, sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -531,7 +531,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SF_CTX->set_body_length(task) != 0) {
|
if (SF_CTX->set_body_length(task) != 0) {
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (task->length < 0) {
|
if (task->length < 0) {
|
||||||
|
|
@ -540,7 +540,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
__LINE__, task->client_ip,
|
__LINE__, task->client_ip,
|
||||||
task->length);
|
task->length);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -552,7 +552,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
task->client_ip, task->length,
|
task->client_ip, task->length,
|
||||||
g_sf_global_vars.max_pkg_size);
|
g_sf_global_vars.max_pkg_size);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -566,7 +566,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
__LINE__, task->client_ip, task->size,
|
__LINE__, task->client_ip, task->size,
|
||||||
task->length);
|
task->length);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -577,7 +577,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
"from %d to %d fail", __LINE__,
|
"from %d to %d fail", __LINE__,
|
||||||
task->client_ip, task->size, task->length);
|
task->client_ip, task->size, task->length);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -592,7 +592,7 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
task->req_count++;
|
task->req_count++;
|
||||||
sf_nio_set_stage(task, SF_NIO_STAGE_SEND);
|
sf_nio_set_stage(task, SF_NIO_STAGE_SEND);
|
||||||
if (SF_CTX->deal_task(task) < 0) { //fatal error
|
if (SF_CTX->deal_task(task) < 0) { //fatal error
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -622,7 +622,7 @@ int sf_client_sock_write(int sock, short event, void *arg)
|
||||||
"remain: %d", __LINE__, task->client_ip, task->length,
|
"remain: %d", __LINE__, task->client_ip, task->length,
|
||||||
task->offset, task->length - task->offset);
|
task->offset, task->length - task->offset);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -631,7 +631,7 @@ int sf_client_sock_write(int sock, short event, void *arg)
|
||||||
"client ip: %s, recv error event: %d, "
|
"client ip: %s, recv error event: %d, "
|
||||||
"close connection", __LINE__, task->client_ip, event);
|
"close connection", __LINE__, task->client_ip, event);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -674,7 +674,7 @@ int sf_client_sock_write(int sock, short event, void *arg)
|
||||||
__LINE__, task->client_ip,
|
__LINE__, task->client_ip,
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (bytes == 0) {
|
} else if (bytes == 0) {
|
||||||
|
|
@ -683,7 +683,7 @@ int sf_client_sock_write(int sock, short event, void *arg)
|
||||||
"connection disconnected",
|
"connection disconnected",
|
||||||
__LINE__, task->client_ip, sock);
|
__LINE__, task->client_ip, sock);
|
||||||
|
|
||||||
iovent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue