]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/session2: remove protolayer_push - consolidate with protolayer_continue
authorOto Šťáva <oto.stava@nic.cz>
Wed, 7 Sep 2022 10:48:16 +0000 (12:48 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Thu, 26 Jan 2023 11:56:08 +0000 (12:56 +0100)
daemon/io.c
daemon/session2.c
daemon/session2.h

index 2dc060e39edc21eb24bb0376e03974dda9cb072a..6d1d069e70ec44ed3da634e0f607b762b383cbac 100644 (file)
@@ -204,11 +204,6 @@ static enum protolayer_cb_result pl_udp_unwrap(struct protolayer_data *layer, st
        return protolayer_continue(ctx);
 }
 
-static enum protolayer_cb_result pl_udp_wrap(struct protolayer_data *layer, struct protolayer_cb_ctx *ctx)
-{
-       return protolayer_push(ctx);
-}
-
 static bool pl_udp_event_wrap(enum protolayer_event_type event,
                               void **baton,
                               struct protolayer_manager *manager,
@@ -344,11 +339,6 @@ static enum protolayer_cb_result pl_tcp_unwrap(struct protolayer_data *layer, st
        return protolayer_continue(ctx);
 }
 
-static enum protolayer_cb_result pl_tcp_wrap(struct protolayer_data *layer, struct protolayer_cb_ctx *ctx)
-{
-       return protolayer_push(ctx);
-}
-
 static bool pl_tcp_event_wrap(enum protolayer_event_type event,
                               void **baton,
                               struct protolayer_manager *manager,
@@ -371,7 +361,6 @@ void io_protolayers_init(void)
                .iter_size = sizeof(struct pl_udp_iter_data),
                .iter_init = pl_udp_iter_init,
                .unwrap = pl_udp_unwrap,
-               .wrap = pl_udp_wrap,
                .event_wrap = pl_udp_event_wrap,
        };
 
@@ -380,7 +369,6 @@ void io_protolayers_init(void)
                .sess_init = pl_tcp_sess_init,
                .sess_deinit = pl_tcp_sess_deinit,
                .unwrap = pl_tcp_unwrap,
-               .wrap = pl_tcp_wrap,
                .event_wrap = pl_tcp_event_wrap,
        };
 }
index 8c01374ea9c156583767f86cc6143fe191c38303..474772898390ce665cd0fde1d3451d79a53ba7f6 100644 (file)
@@ -182,6 +182,49 @@ static int protolayer_cb_ctx_finish(struct protolayer_cb_ctx *ctx, int ret,
        return ret;
 }
 
+static void protolayer_push_finished(int status, struct session2 *s, const void *target, void *baton)
+{
+       struct protolayer_cb_ctx *ctx = baton;
+       ctx->status = status;
+       protolayer_cb_ctx_finish(ctx, PROTOLAYER_RET_NORMAL, true);
+}
+
+/** Pushes the specified protocol layer's payload to the session's transport. */
+static int protolayer_push(struct protolayer_cb_ctx *ctx)
+{
+       struct session2 *session = ctx->manager->session;
+
+       if (ctx->payload.type == PROTOLAYER_PAYLOAD_WIRE_BUF) {
+               ctx->payload = protolayer_as_buffer(&ctx->payload);
+       }
+
+       if (kr_log_is_debug(PROTOLAYER, NULL)) {
+               kr_log_debug(PROTOLAYER, "Pushing %s\n",
+                               protolayer_payload_names[ctx->payload.type]);
+       }
+
+       int status;
+       if (ctx->payload.type == PROTOLAYER_PAYLOAD_BUFFER) {
+               status = session2_transport_push(session,
+                               ctx->payload.buffer.buf, ctx->payload.buffer.len,
+                               ctx->target, protolayer_push_finished, ctx);
+       } else if (ctx->payload.type == PROTOLAYER_PAYLOAD_IOVEC) {
+               status = session2_transport_pushv(session,
+                               ctx->payload.iovec.iov, ctx->payload.iovec.cnt,
+                               ctx->target, protolayer_push_finished, ctx);
+       } else {
+               kr_assert(false && "Invalid payload type");
+               status = kr_error(EINVAL);
+       }
+
+       if (status < 0) {
+               ctx->status = status;
+               return protolayer_cb_ctx_finish(ctx, status, true);
+       }
+
+       return PROTOLAYER_RET_ASYNC;
+}
+
 /** Processes as many layers as possible synchronously, returning when either
  * a layer has gone asynchronous, or when the whole sequence has finished.
  *
@@ -216,8 +259,8 @@ static int protolayer_step(struct protolayer_cb_ctx *ctx)
 
                        ldata->processed = true;
                } else {
-                       //kr_assert(false && "Repeated protocol layer step");
-                       kr_log_debug(PROTOLAYER, "Repeated protocol layer step\n");
+                       kr_assert(false && "Repeated protocol layer step");
+                       //kr_log_debug(PROTOLAYER, "Repeated protocol layer step\n");
                }
 
                if (kr_fails_assert(result == PROTOLAYER_CB_RESULT_MAGIC)) {
@@ -243,9 +286,13 @@ static int protolayer_step(struct protolayer_cb_ctx *ctx)
                }
 
                if (ctx->action == PROTOLAYER_CB_ACTION_CONTINUE) {
-                       if (protolayer_cb_ctx_is_last(ctx))
+                       if (protolayer_cb_ctx_is_last(ctx)) {
+                               if (ctx->direction == PROTOLAYER_WRAP)
+                                       return protolayer_push(ctx);
+
                                return protolayer_cb_ctx_finish(
                                                ctx, PROTOLAYER_RET_NORMAL, true);
+                       }
 
                        protolayer_cb_ctx_next(ctx);
                        continue;
@@ -416,48 +463,6 @@ enum protolayer_cb_result protolayer_break(struct protolayer_cb_ctx *ctx, int st
        return PROTOLAYER_CB_RESULT_MAGIC;
 }
 
-static void protolayer_push_finished(int status, struct session2 *s, const void *target, void *baton)
-{
-       struct protolayer_cb_ctx *ctx = baton;
-       protolayer_break(ctx, status);
-}
-
-enum protolayer_cb_result protolayer_push(struct protolayer_cb_ctx *ctx)
-{
-       int ret;
-       struct session2 *session = ctx->manager->session;
-
-       if (ctx->payload.type == PROTOLAYER_PAYLOAD_WIRE_BUF) {
-               ctx->payload = protolayer_as_buffer(&ctx->payload);
-       }
-
-       if (kr_log_is_debug(PROTOLAYER, NULL)) {
-               kr_log_debug(PROTOLAYER, "Pushing %s\n",
-                               protolayer_payload_names[ctx->payload.type]);
-       }
-
-       if (ctx->payload.type == PROTOLAYER_PAYLOAD_BUFFER) {
-               ret = session2_transport_push(session,
-                               ctx->payload.buffer.buf, ctx->payload.buffer.len,
-                               ctx->target, protolayer_push_finished, ctx);
-       } else if (ctx->payload.type == PROTOLAYER_PAYLOAD_IOVEC) {
-               ret = session2_transport_pushv(session,
-                               ctx->payload.iovec.iov, ctx->payload.iovec.cnt,
-                               ctx->target, protolayer_push_finished, ctx);
-       } else {
-               kr_assert(false && "Invalid payload type");
-               ret = kr_error(EINVAL);
-       }
-
-       /* Push error - otherwise the callback will be called by a push
-        * function called above. */
-       if (ret && ctx->finished_cb)
-               ctx->finished_cb(ret, session, ctx->finished_cb_target,
-                               ctx->finished_cb_baton);
-
-       return PROTOLAYER_CB_RESULT_MAGIC;
-}
-
 
 int wire_buf_init(struct wire_buf *wb, size_t initial_size)
 {
index d7b1aa6831b2e0e97bec2967869bf097fd80a96d..a7b496f02dc7b29347fe4e5bfed3a568cf39df8c 100644 (file)
@@ -426,17 +426,6 @@ enum protolayer_cb_result protolayer_continue(struct protolayer_cb_ctx *ctx);
  * by a non-zero `status`). */
 enum protolayer_cb_result protolayer_break(struct protolayer_cb_ctx *ctx, int status);
 
-/** *Layer sequence return function* - pushes data to the session's transport
- * and signalizes that the layer wants to stop processing of the buffer and
- * clean up.
- *
- * This function is to be called by the `wrap` callback of first layer in
- * the sequence.
- *
- * TODO: get rid of this and just do the push within `_continue` when called
- * from the first layer in `_UNWRAP` direction. */
-enum protolayer_cb_result protolayer_push(struct protolayer_cb_ctx *ctx);
-
 /** *Layer sequence return function* - signalizes that the current sequence
  * will continue in an asynchronous manner. The layer should store the context
  * and call another sequence return function at another point. This may be used