[PATCH 15/17] SAP: Remove connection when closing io

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is no need to keep it in memory after io has been closed.
---
 sap/server.c |   51 ++++++++++++++++++++-------------------------------
 1 file changed, 20 insertions(+), 31 deletions(-)

diff --git a/sap/server.c b/sap/server.c
index ee2624d..a619a23 100644
--- a/sap/server.c
+++ b/sap/server.c
@@ -580,6 +580,24 @@ static void stop_guard_timer(struct sap_server *server)
 	}
 }
 
+static void sap_server_remove_conn(struct sap_server *server)
+{
+	struct sap_connection *conn = server->conn;
+
+	DBG("conn %p", conn);
+
+	if (!conn)
+		return;
+
+	if (conn->io) {
+		g_io_channel_shutdown(conn->io, TRUE, NULL);
+		g_io_channel_unref(conn->io);
+	}
+
+	g_free(conn);
+	server->conn = NULL;
+}
+
 static gboolean guard_timeout(gpointer data)
 {
 	struct sap_server *server = data;
@@ -598,11 +616,7 @@ static gboolean guard_timeout(gpointer data)
 		/* Client opened RFCOMM channel but didn't send CONNECT_REQ,
 		 * in fixed time or client disconnected SAP connection but
 		 * didn't closed RFCOMM channel in fixed time.*/
-		if (conn->io) {
-			g_io_channel_shutdown(conn->io, TRUE, NULL);
-			g_io_channel_unref(conn->io);
-			conn->io = NULL;
-		}
+		sap_server_remove_conn(server);
 		break;
 
 	case SAP_STATE_GRACEFUL_DISCONNECT:
@@ -717,14 +731,7 @@ int sap_disconnect_rsp(void *sap_device)
 		return send_message(conn, &msg, sizeof(msg));
 
 	case SAP_STATE_IMMEDIATE_DISCONNECT:
-		conn->state = SAP_STATE_DISCONNECTED;
-		conn->processing_req = SAP_NO_REQ;
-
-		if (conn->io) {
-			g_io_channel_shutdown(conn->io, TRUE, NULL);
-			g_io_channel_unref(conn->io);
-			conn->io = NULL;
-		}
+		sap_server_remove_conn(server);
 
 		return 0;
 
@@ -1080,24 +1087,6 @@ error_rsp:
 	return -EBADMSG;
 }
 
-static void sap_server_remove_conn(struct sap_server *server)
-{
-	struct sap_connection *conn = server->conn;
-
-	DBG("conn %p", conn);
-
-	if (!conn)
-		return;
-
-	if (conn->io) {
-		g_io_channel_shutdown(conn->io, TRUE, NULL);
-		g_io_channel_unref(conn->io);
-	}
-
-	g_free(conn);
-	server->conn = NULL;
-}
-
 static gboolean sap_io_cb(GIOChannel *io, GIOCondition cond, gpointer data)
 {
 	char buf[SAP_BUF_SIZE];
-- 
on behalf of ST-Ericsson

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux