diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-08-12 14:39:47 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-08-12 14:39:47 +0000 |
commit | a68d448170540639afaa8d8ff21e581c664afd36 (patch) | |
tree | a741568a9c15a04f78713caa1739ab87a1e127fe /audio/avdtp.c | |
parent | 0e46105aa473b7bdc4dfb80b0a0f7858404d94da (diff) |
avdtp_unref improvements
Diffstat (limited to 'audio/avdtp.c')
-rw-r--r-- | audio/avdtp.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/audio/avdtp.c b/audio/avdtp.c index c3bbccc6..ef04126c 100644 --- a/audio/avdtp.c +++ b/audio/avdtp.c @@ -479,8 +479,8 @@ static void connection_lost(struct avdtp *session, int err) if (session->ref != 1) error("connection_lost: ref count not 1 after all callbacks"); - - avdtp_unref(session); + else + avdtp_unref(session); } void avdtp_unref(struct avdtp *session) @@ -495,19 +495,26 @@ void avdtp_unref(struct avdtp *session) session->ref--; - debug("avdtp_unref: ref=%d", session->ref); + debug("avdtp_unref(%p): ref=%d", session, session->ref); if (session->ref == 1) { - if (session->dc_timer) - remove_disconnect_timer(session); - if (session->sock >= 0) + if (session->state == AVDTP_SESSION_STATE_CONNECTING) { + close(session->sock); + session->sock = -1; + } + + if (session->sock >= 0) set_disconnect_timer(session); - return; + else /* Drop the local ref if we aren't connected */ + session->ref--; } if (session->ref > 0) return; + debug("avdtp_unref(%p): freeing session and removing from list", + session); + if (session->dc_timer) remove_disconnect_timer(session); @@ -527,7 +534,7 @@ void avdtp_unref(struct avdtp *session) struct avdtp *avdtp_ref(struct avdtp *session) { session->ref++; - debug("avdtp_ref: ref=%d", session->ref); + debug("avdtp_ref(%p): ref=%d", session, session->ref); if (session->dc_timer) remove_disconnect_timer(session); return session; @@ -1066,7 +1073,6 @@ static gboolean l2cap_connect_cb(GIOChannel *chan, GIOCondition cond, } if (session->state == AVDTP_SESSION_STATE_CONNECTING) { - session->sock = sk; session->mtu = l2o.imtu; session->buf = g_malloc0(session->mtu); session->state = AVDTP_SESSION_STATE_CONNECTED; @@ -1136,11 +1142,16 @@ static int l2cap_connect(struct avdtp *session) g_io_channel_unref(io); return -errno; } + g_io_add_watch(io, G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc) l2cap_connect_cb, session); - if (session->state == AVDTP_SESSION_STATE_DISCONNECTED) + if (session->state == AVDTP_SESSION_STATE_DISCONNECTED) { + session->sock = sk; session->state = AVDTP_SESSION_STATE_CONNECTING; + } + + } else l2cap_connect_cb(io, G_IO_OUT, session); |