From af6855c6c25e15e647c91a8298c279b4a7457303 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 29 Jul 2013 17:04:39 +0300 Subject: [PATCH] audio/AVCTP: Do not process browsing queue until connection completes Any request processed before the connection completes will likely fail in avctp_browsing_send so instead delay the processing. --- profiles/audio/avctp.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c index 2c1aa9443..845027f99 100644 --- a/profiles/audio/avctp.c +++ b/profiles/audio/avctp.c @@ -1107,6 +1107,7 @@ static void avctp_connect_browsing_cb(GIOChannel *chan, GError *err, gpointer data) { struct avctp *session = data; + struct avctp_channel *browsing = session->browsing; char address[18]; uint16_t imtu, omtu; GError *gerr = NULL; @@ -1131,18 +1132,25 @@ static void avctp_connect_browsing_cb(GIOChannel *chan, GError *err, DBG("AVCTP Browsing: connected to %s", address); - if (session->browsing == NULL) - session->browsing = avctp_channel_create(session, chan, + if (browsing == NULL) { + browsing = avctp_channel_create(session, chan, avctp_destroy_browsing); + session->browsing = browsing; + } - session->browsing->imtu = imtu; - session->browsing->omtu = omtu; - session->browsing->buffer = g_malloc0(MAX(imtu, omtu)); - session->browsing->watch = g_io_add_watch(session->browsing->io, + browsing->imtu = imtu; + browsing->omtu = omtu; + browsing->buffer = g_malloc0(MAX(imtu, omtu)); + browsing->watch = g_io_add_watch(session->browsing->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, (GIOFunc) session_browsing_cb, session); avctp_set_state(session, AVCTP_STATE_BROWSING_CONNECTED); + + /* Process any request that was pending the connection to complete */ + if (browsing->process_id == 0 && !g_queue_is_empty(browsing->queue)) + browsing->process_id = g_idle_add(process_queue, browsing); + return; fail: @@ -1543,6 +1551,10 @@ int avctp_send_browsing_req(struct avctp *session, g_queue_push_tail(browsing->queue, p); + /* Connection did not complete, delay process of the request */ + if (browsing->watch == 0) + return 0; + if (browsing->process_id == 0) browsing->process_id = g_idle_add(process_queue, browsing); -- 2.11.0