[Pkg-voip-commits] [janus] 211/282: Make sure pending messages are sent before closing a Unix Socket for timeout (fixes #1009)

Jonas Smedegaard dr at jones.dk
Wed Dec 20 21:53:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.

commit c493057649c74fbd03276fa1cb2272444e468691
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Tue Nov 28 19:20:49 2017 +0100

    Make sure pending messages are sent before closing a Unix Socket for timeout (fixes #1009)
---
 transports/janus_pfunix.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/transports/janus_pfunix.c b/transports/janus_pfunix.c
index e589b27..9da498f 100644
--- a/transports/janus_pfunix.c
+++ b/transports/janus_pfunix.c
@@ -416,22 +416,11 @@ void janus_pfunix_session_over(void *transport, guint64 session_id, gboolean tim
 	janus_mutex_lock(&clients_mutex);
 	if(g_hash_table_lookup(clients, client) != NULL) {
 		client->session_timeout = TRUE;
-		if(client->fd != -1) {
-			/* Shutdown the client socket */
-			shutdown(client->fd, SHUT_WR);
-		} else {
-			/* Destroy the client */
-			g_hash_table_remove(clients_by_path, client->addr.sun_path);
-			g_hash_table_remove(clients, client);
-			if(client->messages != NULL) {
-				char *response = NULL;
-				while((response = g_async_queue_try_pop(client->messages)) != NULL) {
-					g_free(response);
-				}
-				g_async_queue_unref(client->messages);
-			}
-			g_free(client);
-		}
+		/* Notify the thread about this */
+		int res = 0;
+		do {
+			res = write(write_fd[1], "x", 1);
+		} while(res == -1 && errno == EINTR);
 	}
 	janus_mutex_unlock(&clients_mutex);
 }
@@ -582,6 +571,23 @@ void *janus_pfunix_thread(void *data) {
 						JANUS_LOG(LOG_HUGE, "Written %d/%zu bytes on %d\n", res, strlen(payload), client->fd);
 						g_free(payload);
 					}
+					if(client->session_timeout) {
+						/* We should actually get rid of this connection, now */
+						shutdown(SHUT_RDWR, poll_fds[i].fd);
+						close(poll_fds[i].fd);
+						client->fd = -1;
+						/* Destroy the client */
+						g_hash_table_remove(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd));
+						g_hash_table_remove(clients, client);
+						if(client->messages != NULL) {
+							char *response = NULL;
+							while((response = g_async_queue_try_pop(client->messages)) != NULL) {
+								g_free(response);
+							}
+							g_async_queue_unref(client->messages);
+						}
+						g_free(client);
+					}
 				}
 				janus_mutex_unlock(&clients_mutex);
 			}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list