]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/tls: use session's write_queue
authorTomas Krizek <tomas.krizek@nic.cz>
Thu, 13 Aug 2020 14:20:58 +0000 (16:20 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Thu, 13 Aug 2020 14:34:37 +0000 (16:34 +0200)
daemon/session.h
daemon/tls.c
daemon/tls.h

index 15504ee00c41f95344841056e592a4dad2a893f1..b9a622ecd64eadae6233e87f24217ca393203edd 100644 (file)
@@ -22,6 +22,12 @@ struct session_flags {
        bool wirebuf_error : 1; /**< True: last operation with wirebuf ended up with an error. */
 };
 
+struct async_write_ctx {
+       uv_write_t write_req;
+       struct session *session;
+       char buf[];
+};
+
 /* Allocate new session for a libuv handle.
  * If handle->tyoe is UV_UDP, tls parameter will be ignored. */
 struct session *session_new(uv_handle_t *handle, bool has_tls);
@@ -91,7 +97,7 @@ void session_tls_set_server_ctx(struct session *session, struct tls_ctx_t *ctx);
 struct tls_client_ctx_t *session_tls_get_client_ctx(const struct session *session);
 /** Set pointer to client-side tls-related data. */
 void session_tls_set_client_ctx(struct session *session, struct tls_client_ctx_t *ctx);
-/** Get pointer to that part of tls-related data which has common structure for 
+/** Get pointer to that part of tls-related data which has common structure for
  *  server and client. */
 struct tls_common_ctx *session_tls_get_common_ctx(const struct session *session);
 
index 1c69a4b9dd0334ea11fb2aa252b94f04412b9acf..e886e2a0510724a9a4750e683d5bae7627219704 100644 (file)
 #define DEBUG_MSG(...)
 #endif
 
-struct async_write_ctx {
-       uv_write_t write_req;
-       struct tls_common_ctx *t;
-       char buf[];
-};
-
 static char const server_logstring[] = "tls";
 static char const client_logstring[] = "tls_client";
 
@@ -90,17 +84,11 @@ static void on_write_complete(uv_write_t *req, int status)
 {
        assert(req->data != NULL);
        struct async_write_ctx *async_ctx = (struct async_write_ctx *)req->data;
-       struct tls_common_ctx *t = async_ctx->t;
-       assert(t->write_queue_size);
-       t->write_queue_size -= 1;
+       struct session *s = async_ctx->session;
+       assert(session_write_queue_dec(s) == kr_ok());
        free(req->data);
 }
 
-static bool stream_queue_is_empty(struct tls_common_ctx *t)
-{
-       return (t->write_queue_size == 0);
-}
-
 static ssize_t kres_gnutls_vec_push(gnutls_transport_ptr_t h, const giovec_t * iov, int iovcnt)
 {
        struct tls_common_ctx *t = (struct tls_common_ctx *)h;
@@ -137,7 +125,7 @@ static ssize_t kres_gnutls_vec_push(gnutls_transport_ptr_t h, const giovec_t * i
 
        /* Try to perform the immediate write first to avoid copy */
        int ret = 0;
-       if (stream_queue_is_empty(t)) {
+       if (session_write_queue_is_empty(t->session)) {
                ret = uv_try_write(handle, uv_buf, iovcnt);
                DEBUG_MSG("[%s] push %zu <%p> = %d\n",
                    t->client_side ? "tls_client" : "tls", total_len, h, ret);
@@ -177,7 +165,7 @@ static ssize_t kres_gnutls_vec_push(gnutls_transport_ptr_t h, const giovec_t * i
        if (p != NULL) {
                struct async_write_ctx *async_ctx = (struct async_write_ctx *)p;
                /* Save pointer to session tls context */
-               async_ctx->t = t;
+               async_ctx->session = t->session;
                char *buf = async_ctx->buf;
                /* Skip data written in the partial write */
                size_t to_skip = ret;
@@ -209,7 +197,7 @@ static ssize_t kres_gnutls_vec_push(gnutls_transport_ptr_t h, const giovec_t * i
                /* Perform an asynchronous write with a callback */
                if (uv_write(write_req, handle, uv_buf, 1, on_write_complete) == 0) {
                        ret = total_len;
-                       t->write_queue_size += 1;
+                       session_write_queue_inc(t->session);
                } else {
                        free(p);
                        errno = EIO;
index c4f4dfb49463cd2ea35e977b8b49613bdd62318d..754fbf18eca80be9bb79f29e82e5668f180f61d0 100644 (file)
@@ -122,7 +122,6 @@ struct tls_common_ctx {
        uint8_t recv_buf[16384];
        tls_handshake_cb handshake_cb;
        struct worker_ctx *worker;
-       size_t write_queue_size;
 };
 
 struct tls_ctx_t {