summaryrefslogtreecommitdiff
path: root/gatchat
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-08-07 16:20:59 -0500
committerMarcel Holtmann <marcel@holtmann.org>2009-08-07 18:57:10 -0700
commit4957458bfb61b41451977feaad2761226d30585d (patch)
treedc3d2c94e5a433664104842e64a71fec1f64ba5e /gatchat
parentc78db61246eee132abf421b095baab5b996dd066 (diff)
downloadconnman-4957458bfb61b41451977feaad2761226d30585d.tar.gz
connman-4957458bfb61b41451977feaad2761226d30585d.tar.bz2
connman-4957458bfb61b41451977feaad2761226d30585d.zip
Ensure g_timeout_add source can be removed safely
Diffstat (limited to 'gatchat')
-rw-r--r--gatchat/gatchat.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index 1347f183..ba8d66d6 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -83,6 +83,7 @@ struct _GAtChat {
char *pdu_notify; /* Unsolicited Resp w/ PDU */
GSList *response_lines; /* char * lines of the response */
char *wakeup; /* command sent to wakeup modem */
+ gint timeout_source;
gdouble inactivity_time; /* Period of inactivity */
guint wakeup_timeout; /* How long to wait for resp */
GTimer *wakeup_timer; /* Keep track of elapsed time */
@@ -719,6 +720,8 @@ static gboolean wakeup_no_response(gpointer user)
GAtChat *chat = user;
struct at_command *cmd = g_queue_peek_head(chat->command_queue);
+ chat->timeout_source = 0;
+
/* Sometimes during startup the modem is still in the ready state
* and might acknowledge our 'wakeup' command. In that case don't
* timeout the wrong command
@@ -788,8 +791,8 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond,
len = strlen(chat->wakeup);
- g_timeout_add(chat->wakeup_timeout, wakeup_no_response,
- chat);
+ chat->timeout_source = g_timeout_add(chat->wakeup_timeout,
+ wakeup_no_response, chat);
}
towrite = len - chat->cmd_bytes_written;
@@ -988,6 +991,11 @@ gboolean g_at_chat_shutdown(GAtChat *chat)
if (chat->channel == NULL)
return FALSE;
+ if (chat->timeout_source) {
+ g_source_remove(chat->timeout_source);
+ chat->timeout_source = 0;
+ }
+
chat->disconnecting = TRUE;
if (chat->read_watch)