]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: pass handle when calling qr_task_on_send()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 12 Feb 2021 12:22:18 +0000 (13:22 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Fri, 5 Mar 2021 11:07:30 +0000 (12:07 +0100)
... in all cases where it makes sense, on a quick look.
It can be useful for error handling/logging ;-)

daemon/udp_queue.c
daemon/worker.c

index 0050fbaaccd99e34ce4e6559f3c0d2cd073ef607..d2caec9650e24e98cfd05b8dd3f3f9e8d7760f0c 100644 (file)
@@ -72,7 +72,13 @@ struct {
 static void udp_queue_send(int fd)
 {
        udp_queue_t *const q = state.udp_queues[fd];
-       const uv_handle_t * const uv_h = NULL; // TODO: get a real value?
+       if (!q->len) return;
+       // whole queue shares `fd`, so the UV handle is the same as well
+       struct request_ctx *ctx = worker_task_get_request(q->items[0].task);
+       const uv_handle_t * const uv_h =
+               session_get_handle(worker_request_get_source_session(ctx));
+       assert(uv_h);
+
        for (int i = 0; i < q->len;) { // send from `i` onwards
                int len_done = sendmmsg(fd, q->msgvec + i, q->len - i, 0);
                (void)likely(len_done == q->len - i);
index b13bb3911f1ee1eff4e3588ac607bc50f2021bb6..fbcda129554b146141bfea1d2dece62c541f3e51 100644 (file)
@@ -1283,12 +1283,13 @@ static int qr_task_finalize(struct qr_task *task, int state)
 
        task->finished = true;
        if (source_session == NULL) {
-               (void) qr_task_on_send(task, NULL, kr_error(EIO));
+               (void)qr_task_on_send(task, NULL/*src_handle*/, kr_error(EIO));
                return state == KR_STATE_DONE ? kr_ok() : kr_error(EIO);
        }
 
+       const uv_handle_t *src_handle = session_get_handle(source_session);
        if (unlikely(ctx->req.answer == NULL)) { /* meant to be dropped */
-               (void) qr_task_on_send(task, NULL, kr_ok());
+               (void)qr_task_on_send(task, src_handle, kr_ok());
                return kr_ok();
        }
 
@@ -1301,7 +1302,6 @@ static int qr_task_finalize(struct qr_task *task, int state)
 
        /* Send back answer */
        int ret;
-       const uv_handle_t *src_handle = session_get_handle(source_session);
        if (src_handle->type != UV_UDP && src_handle->type != UV_TCP
                                       && src_handle->type != UV_POLL) {
                assert(false);
@@ -1322,7 +1322,7 @@ static int qr_task_finalize(struct qr_task *task, int state)
        }
 
        if (ret != kr_ok()) {
-               (void) qr_task_on_send(task, NULL, kr_error(EIO));
+               (void)qr_task_on_send(task, src_handle, kr_error(EIO));
                /* Since source session is erroneous detach all tasks. */
                while (!session_tasklist_is_empty(source_session)) {
                        struct qr_task *t = session_tasklist_del_first(source_session, false);