diff mbox series

[2/8] gweb: Factor out session transport closure.

Message ID FCE333B7-454D-46B5-BEE6-CEFC74346A18@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Add Configurable Online Check TCP Connect Timeout | expand

Commit Message

Grant Erickson Nov. 11, 2023, 6:58 p.m. UTC
This factors out the three actions undertake to close a GWeb session
TCP tranport into a function, 'close_session_transport', that can be
reused both at object destruction time, when the reference count
reaches zero, but also when a TCP connection timeout occurs and the
connection needs to be aborted.
---
 gweb/gweb.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/gweb/gweb.c b/gweb/gweb.c
index bc0aa7a801a6..5f09cb3a99cf 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -154,6 +154,29 @@  static void _debug(GWeb *web, const char *file, const char *caller,
 	va_end(ap);
 }
 
+static void close_session_transport(struct web_session *session)
+{
+	if (!session)
+		return;
+
+	debug(session->web, "closing session transport");
+
+	if (session->transport_watch > 0) {
+		g_source_remove(session->transport_watch);
+		session->transport_watch = 0;
+	}
+
+	if (session->send_watch > 0) {
+		g_source_remove(session->send_watch);
+		session->send_watch = 0;
+	}
+
+	if (session->transport_channel) {
+		g_io_channel_unref(session->transport_channel);
+		session->transport_channel = NULL;
+	}
+}
+
 static void free_session(struct web_session *session)
 {
 	GWeb *web;
@@ -171,14 +194,7 @@  static void free_session(struct web_session *session)
 	if (session->resolv_action > 0)
 		g_resolv_cancel_lookup(web->resolv, session->resolv_action);
 
-	if (session->transport_watch > 0)
-		g_source_remove(session->transport_watch);
-
-	if (session->send_watch > 0)
-		g_source_remove(session->send_watch);
-
-	if (session->transport_channel)
-		g_io_channel_unref(session->transport_channel);
+	close_session_transport(session);
 
 	g_free(session->result.last_key);