add function sf_strerror

connection_manager
YuQing 2020-10-28 16:07:22 +08:00
parent 719f8b2b32
commit b9b5dd490d
4 changed files with 36 additions and 21 deletions

View File

@ -16,6 +16,7 @@
#include <errno.h>
#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;

View File

@ -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 {

View File

@ -23,6 +23,7 @@
#include <string.h>
#include <pthread.h>
#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);
}
}

View File

@ -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