From 3aa1faddef0b6542da8a0ee5e8aeb8f1c73b87c1 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Tue, 27 Apr 2010 17:05:58 -0500 Subject: [PATCH] gatchat: Replace shutdown by suspend/resume Shutdown was actually pointless and according to Marcel he only had it in mind for PPP useage. --- gatchat/gatchat.c | 39 +++++++++++++++++++++++++++------------ gatchat/gatchat.h | 3 ++- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index dadee1fe..fc289198 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -79,6 +79,7 @@ struct _GAtChat { GAtDisconnectFunc user_disconnect; /* user disconnect func */ gpointer user_disconnect_data; /* user disconnect data */ guint read_so_far; /* Number of bytes processed */ + gboolean suspended; /* Are we suspended? */ GAtDebugFunc debugf; /* debugging output function */ gpointer debug_data; /* Data to pass to debug func */ char *pdu_notify; /* Unsolicited Resp w/ PDU */ @@ -638,7 +639,7 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data) g_at_chat_ref(p); - while (p->channel && (p->read_so_far < len)) { + while (p->suspended == FALSE && (p->read_so_far < len)) { gsize rbytes = MIN(len - p->read_so_far, wrap - p->read_so_far); result = p->syntax->feed(p->syntax, (char *)buf, &rbytes); @@ -933,6 +934,28 @@ GAtChat *g_at_chat_ref(GAtChat *chat) return chat; } +void g_at_chat_suspend(GAtChat *chat) +{ + if (chat == NULL) + return; + + chat->suspended = TRUE; + + g_at_io_set_read_handler(chat->io, NULL, NULL); + g_at_io_set_debug(chat->io, NULL, NULL); +} + +void g_at_chat_resume(GAtChat *chat) +{ + if (chat == NULL) + return; + + chat->suspended = FALSE; + + g_at_io_set_read_handler(chat->io, new_bytes, chat); + g_at_io_set_debug(chat->io, chat->debugf, chat->debug_data); +} + void g_at_chat_unref(GAtChat *chat) { gboolean is_zero; @@ -945,23 +968,15 @@ void g_at_chat_unref(GAtChat *chat) if (is_zero == FALSE) return; - g_at_chat_shutdown(chat); - g_free(chat); -} - -gboolean g_at_chat_shutdown(GAtChat *chat) -{ - if (chat->io == NULL) - return FALSE; - if (chat->write_watch) g_source_remove(chat->write_watch); - g_at_io_set_read_handler(chat->io, NULL, NULL); + g_at_chat_suspend(chat); + g_at_io_unref(chat->io); g_at_chat_cleanup(chat); - return TRUE; + g_free(chat); } gboolean g_at_chat_set_disconnect_function(GAtChat *chat, diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h index 4c3ab07d..ea6626e5 100644 --- a/gatchat/gatchat.h +++ b/gatchat/gatchat.h @@ -46,7 +46,8 @@ GIOChannel *g_at_chat_get_channel(GAtChat *chat); GAtChat *g_at_chat_ref(GAtChat *chat); void g_at_chat_unref(GAtChat *chat); -gboolean g_at_chat_shutdown(GAtChat *chat); +void g_at_chat_suspend(GAtChat *chat); +void g_at_chat_resume(GAtChat *chat); gboolean g_at_chat_set_disconnect_function(GAtChat *chat, GAtDisconnectFunc disconnect, gpointer user_data);