mirror of git://git.sysmocom.de/ofono
Simplify cleanup logic
This commit is contained in:
parent
91555b9165
commit
a1e67482bb
|
@ -78,7 +78,6 @@ struct _GAtChat {
|
||||||
gpointer user_disconnect_data; /* user disconnect data */
|
gpointer user_disconnect_data; /* user disconnect data */
|
||||||
struct ring_buffer *buf; /* Current read buffer */
|
struct ring_buffer *buf; /* Current read buffer */
|
||||||
guint read_so_far; /* Number of bytes processed */
|
guint read_so_far; /* Number of bytes processed */
|
||||||
gboolean disconnecting; /* Whether we're disconnecting */
|
|
||||||
GAtDebugFunc debugf; /* debugging output function */
|
GAtDebugFunc debugf; /* debugging output function */
|
||||||
gpointer debug_data; /* Data to pass to debug func */
|
gpointer debug_data; /* Data to pass to debug func */
|
||||||
char *pdu_notify; /* Unsolicited Resp w/ PDU */
|
char *pdu_notify; /* Unsolicited Resp w/ PDU */
|
||||||
|
@ -243,20 +242,21 @@ static void g_at_chat_cleanup(GAtChat *chat)
|
||||||
chat->wakeup_timer = 0;
|
chat->wakeup_timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chat->timeout_source) {
|
||||||
|
g_source_remove(chat->timeout_source);
|
||||||
|
chat->timeout_source = 0;
|
||||||
|
}
|
||||||
|
|
||||||
g_at_syntax_unref(chat->syntax);
|
g_at_syntax_unref(chat->syntax);
|
||||||
chat->syntax = NULL;
|
chat->syntax = NULL;
|
||||||
|
|
||||||
|
chat->channel = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_watcher_destroy_notify(GAtChat *chat)
|
static void read_watcher_destroy_notify(GAtChat *chat)
|
||||||
{
|
{
|
||||||
chat->read_watch = 0;
|
|
||||||
|
|
||||||
if (chat->disconnecting)
|
|
||||||
return;
|
|
||||||
|
|
||||||
chat->channel = NULL;
|
|
||||||
|
|
||||||
g_at_chat_cleanup(chat);
|
g_at_chat_cleanup(chat);
|
||||||
|
chat->read_watch = 0;
|
||||||
|
|
||||||
if (chat->user_disconnect)
|
if (chat->user_disconnect)
|
||||||
chat->user_disconnect(chat->user_disconnect_data);
|
chat->user_disconnect(chat->user_disconnect_data);
|
||||||
|
@ -630,7 +630,7 @@ static void new_bytes(GAtChat *p)
|
||||||
|
|
||||||
/* We're overflowing the buffer, shutdown the socket */
|
/* We're overflowing the buffer, shutdown the socket */
|
||||||
if (ring_buffer_avail(p->buf) == 0)
|
if (ring_buffer_avail(p->buf) == 0)
|
||||||
g_at_chat_shutdown(p);
|
g_source_remove(p->read_watch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void debug_chat(GAtChat *chat, gboolean in, const char *str, gsize len)
|
static void debug_chat(GAtChat *chat, gboolean in, const char *str, gsize len)
|
||||||
|
@ -858,7 +858,7 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond,
|
||||||
&bytes_written);
|
&bytes_written);
|
||||||
|
|
||||||
if (err != G_IO_ERROR_NONE) {
|
if (err != G_IO_ERROR_NONE) {
|
||||||
g_at_chat_shutdown(chat);
|
g_source_remove(chat->read_watch);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1017,12 +1017,11 @@ void g_at_chat_unref(GAtChat *chat)
|
||||||
|
|
||||||
is_zero = g_atomic_int_dec_and_test(&chat->ref_count);
|
is_zero = g_atomic_int_dec_and_test(&chat->ref_count);
|
||||||
|
|
||||||
if (is_zero) {
|
if (is_zero == FALSE)
|
||||||
g_at_chat_shutdown(chat);
|
return;
|
||||||
|
|
||||||
g_at_chat_cleanup(chat);
|
g_at_chat_shutdown(chat);
|
||||||
g_free(chat);
|
g_free(chat);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean g_at_chat_shutdown(GAtChat *chat)
|
gboolean g_at_chat_shutdown(GAtChat *chat)
|
||||||
|
@ -1030,12 +1029,9 @@ gboolean g_at_chat_shutdown(GAtChat *chat)
|
||||||
if (chat->channel == NULL)
|
if (chat->channel == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (chat->timeout_source) {
|
/* Don't trigger user disconnect on shutdown */
|
||||||
g_source_remove(chat->timeout_source);
|
chat->user_disconnect = NULL;
|
||||||
chat->timeout_source = 0;
|
chat->user_disconnect_data = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
chat->disconnecting = TRUE;
|
|
||||||
|
|
||||||
if (chat->read_watch)
|
if (chat->read_watch)
|
||||||
g_source_remove(chat->read_watch);
|
g_source_remove(chat->read_watch);
|
||||||
|
|
Loading…
Reference in New Issue