From 62a35f03d5094409cd8912b6a525eddcf4dd38d5 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 22 Sep 2020 17:26:46 +0800 Subject: [PATCH] add macro sf_nio_notify_silence --- src/idempotency/client/client_channel.c | 2 +- src/sf_nio.c | 28 +++++++++++++++---------- src/sf_nio.h | 7 +++++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/idempotency/client/client_channel.c b/src/idempotency/client/client_channel.c index abfd475..2532c7e 100644 --- a/src/idempotency/client/client_channel.c +++ b/src/idempotency/client/client_channel.c @@ -318,7 +318,7 @@ int idempotency_client_channel_push(struct idempotency_client_channel *channel, if (notify) { if (__sync_add_and_fetch(&channel->in_ioevent, 0)) { if (__sync_add_and_fetch(&channel->established, 0)) { - sf_nio_notify(channel->task, SF_NIO_STAGE_CONTINUE); + sf_nio_notify_silence(channel->task, SF_NIO_STAGE_CONTINUE); } } else { return idempotency_client_channel_check_reconnect(channel); diff --git a/src/sf_nio.c b/src/sf_nio.c index 979c45e..9e6adbc 100644 --- a/src/sf_nio.c +++ b/src/sf_nio.c @@ -285,7 +285,7 @@ static int sf_nio_deal_task(struct fast_task_info *task) } int sf_nio_notify_ex(struct fast_task_info *task, const int new_stage, - const char *file, const int line) + const int log_level, const char *file, const int line) { int64_t n; int result; @@ -298,11 +298,14 @@ int sf_nio_notify_ex(struct fast_task_info *task, const int new_stage, new_stage == SF_NIO_STAGE_CLOSE)) { if (SF_NIO_STAGE_IS_INPROGRESS(old_stage)) { - logWarning("file: "__FILE__", line: %d, " - "from caller {file: %s, line: %d}, " - "client ip: %s, nio stage in progress, " - "current stage: %d, skip set to %d", __LINE__, - file, line, task->client_ip, old_stage, new_stage); + if (FC_LOG_BY_LEVEL(log_level)) { + log_it_ex(&g_log_context, log_level, + "file: "__FILE__", line: %d, " + "from caller {file: %s, line: %d}, " + "client ip: %s, nio stage in progress, " + "current stage: %d, skip set to %d", __LINE__, + file, line, task->client_ip, old_stage, new_stage); + } return EBUSY; } } @@ -310,11 +313,14 @@ int sf_nio_notify_ex(struct fast_task_info *task, const int new_stage, if (!__sync_bool_compare_and_swap(&task->nio_stage, old_stage, new_stage)) { - logWarning("file: "__FILE__", line: %d, " - "from caller {file: %s, line: %d}, " - "client ip: %s, skip set stage to %d because stage " - "changed, current stage: %d", __LINE__, file, line, - task->client_ip, new_stage, SF_NIO_TASK_STAGE_FETCH(task)); + if (FC_LOG_BY_LEVEL(log_level)) { + log_it_ex(&g_log_context, log_level, + "file: "__FILE__", line: %d, " + "from caller {file: %s, line: %d}, " + "client ip: %s, skip set stage to %d because stage " + "changed, current stage: %d", __LINE__, file, line, + task->client_ip, new_stage, SF_NIO_TASK_STAGE_FETCH(task)); + } return EEXIST; } diff --git a/src/sf_nio.h b/src/sf_nio.h index 5d972cc..897df00 100644 --- a/src/sf_nio.h +++ b/src/sf_nio.h @@ -51,10 +51,13 @@ int sf_client_sock_read(int sock, short event, void *arg); void sf_task_finish_clean_up(struct fast_task_info *task); int sf_nio_notify_ex(struct fast_task_info *task, const int new_stage, - const char *file, const int line); + const int log_level, const char *file, const int line); #define sf_nio_notify(task, new_stage) \ - sf_nio_notify_ex(task, new_stage, __FILE__, __LINE__) + sf_nio_notify_ex(task, new_stage, LOG_WARNING, __FILE__, __LINE__) + +#define sf_nio_notify_silence(task, new_stage) \ + sf_nio_notify_ex(task, new_stage, LOG_NOTHING, __FILE__, __LINE__) #define sf_nio_task_is_idle(task) \ (task->offset == 0 && task->length == 0)