add func sf_enable_exit_on_oom

connection_manager
YuQing 2020-07-11 17:41:00 +08:00
parent 43351fc67b
commit 8b11d63ac6
2 changed files with 15 additions and 0 deletions

View File

@ -41,3 +41,16 @@ int sf_connect_to_server(const char *ip_addr, const int port, int *sock)
return 0; return 0;
} }
static void sf_memory_oom_notify_callback(const size_t curr_size)
{
logCrit("file: "__FILE__", line: %d, "
"alloc %"PRId64" bytes fail, exiting ...",
__LINE__, (int64_t)curr_size);
SF_G_CONTINUE_FLAG = false;
}
void sf_enable_exit_on_oom()
{
g_oom_notify = sf_memory_oom_notify_callback;
}

View File

@ -12,6 +12,8 @@ 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);
void sf_enable_exit_on_oom();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif