Hardened the management of callbacks
This commit is contained in:
parent
2dfa1e0cec
commit
df6c2f84c3
@ -648,6 +648,8 @@ int gsm_queue_with_error(GSM * gsm, char const * command, GSMError error)
|
|||||||
int gsm_reset(GSM * gsm, unsigned int delay)
|
int gsm_reset(GSM * gsm, unsigned int delay)
|
||||||
{
|
{
|
||||||
_gsm_queue_flush(gsm);
|
_gsm_queue_flush(gsm);
|
||||||
|
if(gsm->source != 0)
|
||||||
|
g_source_remove(gsm->source);
|
||||||
if(delay > 0)
|
if(delay > 0)
|
||||||
gsm->source = g_timeout_add(delay, _on_reset, gsm);
|
gsm->source = g_timeout_add(delay, _on_reset, gsm);
|
||||||
else
|
else
|
||||||
@ -755,7 +757,8 @@ static int _parse_do(GSM * gsm, size_t * i)
|
|||||||
{
|
{
|
||||||
if(strcmp(gsm->rd_buf, "OK") != 0)
|
if(strcmp(gsm->rd_buf, "OK") != 0)
|
||||||
return 0;
|
return 0;
|
||||||
g_source_remove(gsm->source);
|
if(gsm->source != 0)
|
||||||
|
g_source_remove(gsm->source);
|
||||||
gsm->source = 0;
|
gsm->source = 0;
|
||||||
*i = gsm->rd_buf_cnt; /* XXX ugly: flush read buffer */
|
*i = gsm->rd_buf_cnt; /* XXX ugly: flush read buffer */
|
||||||
g_io_channel_flush(gsm->channel, NULL); /* XXX check errors? */
|
g_io_channel_flush(gsm->channel, NULL); /* XXX check errors? */
|
||||||
@ -1188,7 +1191,8 @@ static gboolean _on_reset(gpointer data)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||||
#endif
|
#endif
|
||||||
gsm->source = 0;
|
if(gsm->source != 0)
|
||||||
|
g_source_remove(gsm->source);
|
||||||
if(gsm->channel != NULL)
|
if(gsm->channel != NULL)
|
||||||
{
|
{
|
||||||
/* XXX should the file descriptor also be freed? */
|
/* XXX should the file descriptor also be freed? */
|
||||||
@ -1205,6 +1209,7 @@ static gboolean _on_reset(gpointer data)
|
|||||||
close(fd);
|
close(fd);
|
||||||
if(gsm->retry > 0)
|
if(gsm->retry > 0)
|
||||||
gsm->source = g_timeout_add(gsm->retry, _on_reset, gsm);
|
gsm->source = g_timeout_add(gsm->retry, _on_reset, gsm);
|
||||||
|
gsm->source = 0;
|
||||||
return phone_error(NULL, buf, FALSE);
|
return phone_error(NULL, buf, FALSE);
|
||||||
}
|
}
|
||||||
gsm->channel = g_io_channel_unix_new(fd);
|
gsm->channel = g_io_channel_unix_new(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user