From 71e7066c81199f402a8b1640505705f28c567c35 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Fri, 29 Sep 2023 14:59:58 +0800 Subject: [PATCH] invoke send done callback correctly --- src/sf_nio.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sf_nio.c b/src/sf_nio.c index 21bcef0..8f3add2 100644 --- a/src/sf_nio.c +++ b/src/sf_nio.c @@ -542,6 +542,7 @@ static inline int check_task(struct fast_task_info *task, ssize_t sf_socket_send_data(struct fast_task_info *task, SFCommAction *action) { int bytes; + int length; if (task->iovec_array.iovs != NULL) { bytes = writev(task->event.fd, task->iovec_array.iovs, @@ -584,10 +585,16 @@ 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) { + length = task->send.ptr->length; if (task->send.ptr != task->recv.ptr) { //double buffers task->send.ptr->offset = 0; task->send.ptr->length = 0; } + if (SF_CTX->callbacks.send_done != NULL) { + if (SF_CTX->callbacks.send_done(task, length) != 0) { + return -1; + } + } *action = sf_comm_action_finish; } else { *action = sf_comm_action_continue; @@ -1018,13 +1025,6 @@ int sf_client_sock_write(int sock, short event, void *arg) return -1; } - if (SF_CTX->callbacks.send_done != NULL) { - if (SF_CTX->callbacks.send_done(task, length) != 0) { - ioevent_add_to_deleted_list(task); - return -1; - } - } - break; } else if (action == sf_comm_action_break) { break;