support error handler callback
parent
414f0f1efe
commit
2a57961b59
|
|
@ -39,7 +39,7 @@ SFGlobalVariables g_sf_global_vars = {
|
||||||
SF_DEF_MAX_PACKAGE_SIZE, SF_DEF_MIN_BUFF_SIZE,
|
SF_DEF_MAX_PACKAGE_SIZE, SF_DEF_MIN_BUFF_SIZE,
|
||||||
SF_DEF_MAX_BUFF_SIZE, 0, SF_DEF_THREAD_STACK_SIZE,
|
SF_DEF_MAX_BUFF_SIZE, 0, SF_DEF_THREAD_STACK_SIZE,
|
||||||
0, 0, 0, {'\0'}, {'\0'}, {SF_DEF_SYNC_LOG_BUFF_INTERVAL, false},
|
0, 0, 0, {'\0'}, {'\0'}, {SF_DEF_SYNC_LOG_BUFF_INTERVAL, false},
|
||||||
{0, 0}
|
{0, 0}, NULL, {NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
SFContext g_sf_context = {
|
SFContext g_sf_context = {
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ typedef struct sf_global_variables {
|
||||||
|
|
||||||
SFLogConfig error_log;
|
SFLogConfig error_log;
|
||||||
SFConnectionStat connection_stat;
|
SFConnectionStat connection_stat;
|
||||||
|
sf_error_handler_callback error_handler;
|
||||||
|
string_t empty;
|
||||||
} SFGlobalVariables;
|
} SFGlobalVariables;
|
||||||
|
|
||||||
typedef struct sf_context_ini_config {
|
typedef struct sf_context_ini_config {
|
||||||
|
|
@ -84,6 +86,9 @@ extern SFContext g_sf_context;
|
||||||
#define SF_G_CONN_CURRENT_COUNT g_sf_global_vars.connection_stat.current_count
|
#define SF_G_CONN_CURRENT_COUNT g_sf_global_vars.connection_stat.current_count
|
||||||
#define SF_G_CONN_MAX_COUNT g_sf_global_vars.connection_stat.max_count
|
#define SF_G_CONN_MAX_COUNT g_sf_global_vars.connection_stat.max_count
|
||||||
|
|
||||||
|
#define SF_G_ERROR_HANDLER g_sf_global_vars.error_handler
|
||||||
|
#define SF_G_EMPTY_STRING g_sf_global_vars.empty
|
||||||
|
|
||||||
#define SF_WORK_THREADS(sf_context) sf_context.work_threads
|
#define SF_WORK_THREADS(sf_context) sf_context.work_threads
|
||||||
#define SF_ALIVE_THREAD_COUNT(sf_context) sf_context.thread_count
|
#define SF_ALIVE_THREAD_COUNT(sf_context) sf_context.thread_count
|
||||||
#define SF_THREAD_INDEX(sf_context, tdata) (int)(tdata - sf_context.thread_data)
|
#define SF_THREAD_INDEX(sf_context, tdata) (int)(tdata - sf_context.thread_data)
|
||||||
|
|
@ -207,6 +212,12 @@ static inline void sf_set_global_base_path(const char *base_path)
|
||||||
SF_G_BASE_PATH_INITED = true;
|
SF_G_BASE_PATH_INITED = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void sf_set_error_handler(
|
||||||
|
sf_error_handler_callback error_handler)
|
||||||
|
{
|
||||||
|
SF_G_ERROR_HANDLER = error_handler;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@
|
||||||
if (client_ctx->auth.enabled) { \
|
if (client_ctx->auth.enabled) { \
|
||||||
out_bytes += FCFS_AUTH_SESSION_ID_LEN; \
|
out_bytes += FCFS_AUTH_SESSION_ID_LEN; \
|
||||||
memcpy(the_req_start, client_ctx->auth.ctx-> \
|
memcpy(the_req_start, client_ctx->auth.ctx-> \
|
||||||
session_id, FCFS_AUTH_SESSION_ID_LEN); \
|
session.id, FCFS_AUTH_SESSION_ID_LEN); \
|
||||||
the_req_start += FCFS_AUTH_SESSION_ID_LEN; \
|
the_req_start += FCFS_AUTH_SESSION_ID_LEN; \
|
||||||
} \
|
} \
|
||||||
if (the_req_id > 0) { \
|
if (the_req_id > 0) { \
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ typedef int (*sf_recv_timeout_callback)(struct fast_task_info *task);
|
||||||
/* calback for release iovec buffer */
|
/* calback for release iovec buffer */
|
||||||
typedef void (*sf_release_buffer_callback)(struct fast_task_info *task);
|
typedef void (*sf_release_buffer_callback)(struct fast_task_info *task);
|
||||||
|
|
||||||
|
typedef int (*sf_error_handler_callback)(const int errnum);
|
||||||
|
|
||||||
typedef struct sf_context {
|
typedef struct sf_context {
|
||||||
char name[64];
|
char name[64];
|
||||||
struct nio_thread_data *thread_data;
|
struct nio_thread_data *thread_data;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "sf_global.h"
|
|
||||||
#include "sf_define.h"
|
#include "sf_define.h"
|
||||||
#include "sf_util.h"
|
#include "sf_util.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include "fastcommon/sched_thread.h"
|
#include "fastcommon/sched_thread.h"
|
||||||
#include "sf_define.h"
|
#include "sf_define.h"
|
||||||
#include "sf_types.h"
|
#include "sf_types.h"
|
||||||
|
#include "sf_global.h"
|
||||||
|
|
||||||
#ifdef DEBUG_FLAG /*only for format check*/
|
#ifdef DEBUG_FLAG /*only for format check*/
|
||||||
|
|
||||||
|
|
@ -127,8 +128,12 @@ static inline int sf_unify_errno(const int errnum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int sf_localize_errno(const int errnum)
|
static inline int sf_localize_errno(int errnum)
|
||||||
{
|
{
|
||||||
|
if (SF_G_ERROR_HANDLER != NULL) {
|
||||||
|
errnum = SF_G_ERROR_HANDLER(errnum);
|
||||||
|
}
|
||||||
|
|
||||||
switch (errnum) {
|
switch (errnum) {
|
||||||
case SF_ERROR_EBUSY:
|
case SF_ERROR_EBUSY:
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue