From 17c99cdd557f288ccb0b699fbc02dc261a9ee581 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 26 Sep 2023 15:26:42 +0800 Subject: [PATCH] sf_nio_task_is_idle rename to sf_nio_task_send_done --- src/idempotency/client/receipt_handler.c | 9 +++++---- src/sf_nio.c | 11 +++++------ src/sf_nio.h | 7 +++---- src/sf_proto.h | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/idempotency/client/receipt_handler.c b/src/idempotency/client/receipt_handler.c index ac1e62a..6adcf19 100644 --- a/src/idempotency/client/receipt_handler.c +++ b/src/idempotency/client/receipt_handler.c @@ -352,7 +352,7 @@ static int receipt_deal_task(struct fast_task_info *task, const int stage) result = 0; break; } else if (stage == SF_NIO_STAGE_CONTINUE) { - if (sf_nio_task_is_idle(task)) { + if (sf_nio_task_send_done(task)) { if (((IdempotencyClientChannel *)task->arg)->established) { report_req_receipt_request(task, true); } else if (task->req_count > 0) { @@ -408,7 +408,8 @@ static int receipt_deal_task(struct fast_task_info *task, const int stage) if (result == 0) { update_lru_chain(task); - sf_nio_reset_task_length(task); + task->recv.ptr->length = 0; + task->recv.ptr->offset = 0; report_req_receipt_request(task, false); } } while (0); @@ -429,7 +430,7 @@ static void receipt_thread_check_heartbeat( break; } - if (sf_nio_task_is_idle(channel->task)) { + if (sf_nio_task_send_done(channel->task)) { channel->last_pkg_time = g_current_time; active_test_request(channel->task); } @@ -443,7 +444,7 @@ static void receipt_thread_close_idle_channel( IdempotencyClientChannel *tmp; fc_list_for_each_entry_safe(channel, tmp, &thread_ctx->head, dlink) { - if (!sf_nio_task_is_idle(channel->task)) { + if (!sf_nio_task_send_done(channel->task)) { continue; } diff --git a/src/sf_nio.c b/src/sf_nio.c index e264be9..306e4ad 100644 --- a/src/sf_nio.c +++ b/src/sf_nio.c @@ -582,6 +582,10 @@ ssize_t sf_socket_send_data(struct fast_task_info *task, SFCommAction *action) task->send.ptr->offset += bytes; if (task->send.ptr->offset >= task->send.ptr->length) { + if (task->send.ptr != task->recv.ptr) { //double buffers + task->send.ptr->offset = 0; + task->send.ptr->length = 0; + } *action = sf_comm_action_finish; } else { *action = sf_comm_action_continue; @@ -979,6 +983,7 @@ int sf_client_sock_write(int sock, short event, void *arg) total_write = 0; action = sf_comm_action_continue; + length = task->send.ptr->length; while (1) { fast_timer_modify(&task->thread_data->timer, &task->event.timer, g_current_time + @@ -992,12 +997,6 @@ int sf_client_sock_write(int sock, short event, void *arg) total_write += bytes; if (action == sf_comm_action_finish) { release_iovec_buffer(task); - - length = task->send.ptr->length; - if (task->free_queue->double_buffers) { - task->send.ptr->offset = 0; - task->send.ptr->length = 0; - } if (sf_set_read_event(task) != 0) { return -1; } diff --git a/src/sf_nio.h b/src/sf_nio.h index 3297723..1822842 100644 --- a/src/sf_nio.h +++ b/src/sf_nio.h @@ -85,15 +85,14 @@ static inline TaskCleanUpCallback sf_get_task_cleanup_callback_ex( #define sf_get_task_cleanup_callback() \ sf_get_task_cleanup_callback_ex(&g_sf_context) -#define sf_nio_task_is_idle(task) \ - ((task->send.ptr->offset == 0 && task->send.ptr->length == 0) && \ - (task->recv.ptr->offset == 0 && task->recv.ptr->length == 0)) +#define sf_nio_task_send_done(task) \ + (task->send.ptr->offset == 0 && task->send.ptr->length == 0) static inline void sf_nio_reset_task_length(struct fast_task_info *task) { task->send.ptr->length = 0; task->send.ptr->offset = 0; - if (task->free_queue->double_buffers) { + if (task->recv.ptr != task->send.ptr) { task->recv.ptr->length = 0; task->recv.ptr->offset = 0; } diff --git a/src/sf_proto.h b/src/sf_proto.h index a137d43..a38a06d 100644 --- a/src/sf_proto.h +++ b/src/sf_proto.h @@ -296,7 +296,7 @@ static inline void sf_proto_init_task_magic(struct fast_task_info *task) { SF_PROTO_SET_MAGIC(((SFCommonProtoHeader *) task->send.ptr->data)->magic); - if (task->free_queue->double_buffers) { + if (task->recv.ptr != task->send.ptr) { SF_PROTO_SET_MAGIC(((SFCommonProtoHeader *) task->recv.ptr->data)->magic); }