From b8e2797d71e55ff6c0ba06cbeded8ee7441357eb Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Thu, 20 Jul 2023 16:52:28 -0400 Subject: [PATCH 1/2] put outbound close messages on the write queue --- inc_internal/zt_internal.h | 1 + library/connect.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inc_internal/zt_internal.h b/inc_internal/zt_internal.h index ca260001..d9cef716 100644 --- a/inc_internal/zt_internal.h +++ b/inc_internal/zt_internal.h @@ -121,6 +121,7 @@ struct ziti_write_req_s { uint8_t *buf; size_t len; bool eof; + bool close; struct message_s *message; ziti_write_cb cb; diff --git a/library/connect.c b/library/connect.c index b28348f3..299d35ba 100644 --- a/library/connect.c +++ b/library/connect.c @@ -573,6 +573,12 @@ static void ziti_write_req(struct ziti_write_req_s *req) { conn->write_reqs--; free(req); return; + } else if (req->close) { + // conn->state will be set on_disconnect callback + message *m = create_message(conn, ContentTypeStateClosed, 0); + send_message(conn, m, req); + // conn->write_reqs will be decremented and wreq freed in on_write_completed + return; } if (req->cb) { @@ -615,12 +621,11 @@ static void ziti_disconnect_async(struct ziti_conn *conn) { case Connected: case CloseWrite: case Timedout: { - message *m = create_message(conn, ContentTypeStateClosed, 0); NEWP(wr, struct ziti_write_req_s); wr->conn = conn; wr->cb = on_disconnect; - conn->write_reqs++; - send_message(conn, m, wr); + TAILQ_INSERT_TAIL(&conn->wreqs, wr, _next); + flush_connection(conn); break; } From ce4c25bb3da3fb5782b8baf4dc4642171d7ae49b Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Mon, 24 Jul 2023 15:21:01 -0400 Subject: [PATCH 2/2] set close flag on write request --- library/connect.c | 1 + 1 file changed, 1 insertion(+) diff --git a/library/connect.c b/library/connect.c index 299d35ba..300fa2e1 100644 --- a/library/connect.c +++ b/library/connect.c @@ -623,6 +623,7 @@ static void ziti_disconnect_async(struct ziti_conn *conn) { case Timedout: { NEWP(wr, struct ziti_write_req_s); wr->conn = conn; + wr->close = true; wr->cb = on_disconnect; TAILQ_INSERT_TAIL(&conn->wreqs, wr, _next); flush_connection(conn);