From b9b5dd490dc5d4ece3f3cce5caf00f2ac95bf61f Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 28 Oct 2020 16:07:22 +0800 Subject: [PATCH] add function sf_strerror --- src/sf_proto.c | 7 ++++--- src/sf_service.h | 25 +++++++------------------ src/sf_util.c | 23 +++++++++++++++++++++++ src/sf_util.h | 2 ++ 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/sf_proto.c b/src/sf_proto.c index 3a7a0f4..9b1b276 100644 --- a/src/sf_proto.c +++ b/src/sf_proto.c @@ -16,6 +16,7 @@ #include #include "fastcommon/shared_func.h" +#include "sf_util.h" #include "sf_proto.h" int sf_proto_set_body_length(struct fast_task_info *task) @@ -76,9 +77,9 @@ int sf_check_response(ConnectionInfo *conn, SFResponseInfo *response, } } else { response->error.length = snprintf(response->error.message, - sizeof(response->error.message), - "response status %d, error info: %s", - response->header.status, STRERROR(response->header.status)); + sizeof(response->error.message), "response status %d, " + "error info: %s", response->header.status, + sf_strerror(response->header.status)); } return response->header.status; diff --git a/src/sf_service.h b/src/sf_service.h index 478b386..faf91b9 100644 --- a/src/sf_service.h +++ b/src/sf_service.h @@ -100,11 +100,8 @@ void sf_set_sig_quit_handler(sf_sig_quit_handler quit_handler); int sf_init_task(struct fast_task_info *task); -#define sf_alloc_init_task(sf_context, sock) \ - sf_alloc_init_task_ex(sf_context, sock, 1) - -static inline struct fast_task_info *sf_alloc_init_task_ex( - SFContext *sf_context, const int sock, const int init_reffer) +static inline struct fast_task_info *sf_alloc_init_task( + SFContext *sf_context, const int sock) { struct fast_task_info *task; @@ -116,7 +113,7 @@ static inline struct fast_task_info *sf_alloc_init_task_ex( __LINE__); return NULL; } - __sync_add_and_fetch(&task->reffer_count, init_reffer); + __sync_add_and_fetch(&task->reffer_count, 1); __sync_bool_compare_and_swap(&task->canceled, 1, 0); task->ctx = sf_context; task->event.fd = sock; @@ -126,26 +123,18 @@ static inline struct fast_task_info *sf_alloc_init_task_ex( #define sf_hold_task(task) __sync_add_and_fetch(&task->reffer_count, 1) -/* -#define sf_hold_task(task) \ - logInfo("file: "__FILE__", line: %d, " \ - "hold task %p, reffer: %d", \ - __LINE__, task, __sync_add_and_fetch(&task->reffer_count, 1)) - */ - -#define sf_try_hold_task_to_twice(task) \ - __sync_bool_compare_and_swap(&task->reffer_count, 1, 2) - static inline void sf_release_task(struct fast_task_info *task) { - int reffer_count; - if ((reffer_count=__sync_sub_and_fetch(&task->reffer_count, 1)) == 0) { + //int reffer_count; + if (__sync_sub_and_fetch(&task->reffer_count, 1) == 0) { + /* int free_count = free_queue_count(); int alloc_count = free_queue_alloc_connections(); logInfo("file: "__FILE__", line: %d, " "push task %p to queue, alloc: %d, " "used: %d, freed: %d", __LINE__, task, alloc_count, alloc_count - free_count, free_count); + */ free_queue_push(task); } else { diff --git a/src/sf_util.c b/src/sf_util.c index 2309346..972b137 100644 --- a/src/sf_util.c +++ b/src/sf_util.c @@ -23,6 +23,7 @@ #include #include #include "sf_global.h" +#include "sf_define.h" #include "sf_util.h" int64_t getticks() @@ -173,3 +174,25 @@ ScheduleEntry *sf_logger_set_schedule_entry(struct log_context *pContext, return pScheduleEntry; } + +const char *sf_strerror(const int errnum) +{ + switch (errnum) { + case SF_CLUSTER_ERROR_BINLOG_INCONSISTENT: + return "binlog inconsistent"; + case SF_CLUSTER_ERROR_LEADER_INCONSISTENT: + return "leader or master inconsistent"; + case SF_RETRIABLE_ERROR_NO_SERVER: + return "no server available"; + case SF_RETRIABLE_ERROR_NOT_MASTER: + return "i am not master"; + case SF_RETRIABLE_ERROR_NOT_ACTIVE: + return "i am not active"; + case SF_RETRIABLE_ERROR_NO_CHANNEL: + return "idempotency channel not exist"; + case SF_RETRIABLE_ERROR_CHANNEL_INVALID: + return "idempotency channel is invalid"; + default: + return STRERROR(errnum); + } +} diff --git a/src/sf_util.h b/src/sf_util.h index dfcd932..af96602 100644 --- a/src/sf_util.h +++ b/src/sf_util.h @@ -79,6 +79,8 @@ int sf_logger_init(LogContext *pContext, const char *filename_prefix); ScheduleEntry *sf_logger_set_schedule_entry(struct log_context *pContext, ScheduleEntry *pScheduleEntry); +const char *sf_strerror(const int errnum); + #ifdef __cplusplus } #endif