summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-04-09 16:01:30 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-04-13 12:03:32 -0500
commit843db6f9a50306a1eb14dc183fbf7c2cc6912ab0 (patch)
tree4ffab8026c72894421e74bdc1b50a9e169ae1ea9
parentb916f189f58fc5fb9eb791e4c6bef4ce3191d698 (diff)
downloadofono-843db6f9a50306a1eb14dc183fbf7c2cc6912ab0.tar.bz2
ppp: unref should mean a hard shutdown
This can happen when e.g. the modem is physically removed from the system and it is not feasible to wait for the nice shutdown state to be reached.
-rw-r--r--gatchat/gatppp.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index 48af6474..0813435c 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -349,30 +349,9 @@ static gboolean ppp_read_cb(GIOChannel *channel, GIOCondition cond,
static void ppp_dead(GAtPPP *ppp)
{
- if (ppp->write_watch)
- return;
-
/* notify interested parties */
if (ppp->disconnect_cb)
ppp->disconnect_cb(ppp->disconnect_data);
-
- if (g_atomic_int_get(&ppp->ref_count))
- return;
-
- /* cleanup queue */
- g_queue_free(ppp->xmit_queue);
-
- /* cleanup modem channel */
- g_source_remove(ppp->read_watch);
- g_source_remove(ppp->write_watch);
- g_io_channel_unref(ppp->modem);
-
- lcp_free(ppp->lcp);
- auth_free(ppp->auth);
- ipcp_free(ppp->ipcp);
- ppp_net_free(ppp->net);
-
- g_free(ppp);
}
static void ppp_transition_phase(GAtPPP *ppp, enum ppp_phase phase)
@@ -568,16 +547,30 @@ void g_at_ppp_ref(GAtPPP *ppp)
void g_at_ppp_unref(GAtPPP *ppp)
{
- if (g_atomic_int_dec_and_test(&ppp->ref_count))
- g_at_ppp_shutdown(ppp);
+ gboolean is_zero;
- /*
- * we can't free the link yet, because we need to terminate
- * the link first.
- */
+ is_zero = g_atomic_int_dec_and_test(&ppp->ref_count);
+
+ if (is_zero == FALSE)
+ return;
if (ppp->record_fd > fileno(stderr))
close(ppp->record_fd);
+
+ /* cleanup queue */
+ g_queue_free(ppp->xmit_queue);
+
+ /* cleanup modem channel */
+ g_source_remove(ppp->read_watch);
+ g_source_remove(ppp->write_watch);
+ g_io_channel_unref(ppp->modem);
+
+ lcp_free(ppp->lcp);
+ auth_free(ppp->auth);
+ ipcp_free(ppp->ipcp);
+ ppp_net_free(ppp->net);
+
+ g_free(ppp);
}
GAtPPP *g_at_ppp_new(GIOChannel *modem)