Perform more queue management in channels

This commit is contained in:
Pierre Pronchery 2015-12-29 00:47:12 +01:00
parent 2aa7a53fb8
commit edb9fbd1c5
3 changed files with 23 additions and 23 deletions

View File

@ -187,7 +187,6 @@ static int _hayes_queue_command(Hayes * hayes, HayesChannel * channel,
static int _hayes_queue_command_full(Hayes * hayes,
char const * attention, HayesCommandCallback callback);
#endif
static int _hayes_queue_pop(Hayes * hayes, HayesChannel * channel);
static int _hayes_queue_push(Hayes * hayes, HayesChannel * channel);
/* requests */
@ -1064,7 +1063,7 @@ static int _parse_do(Hayes * hayes, HayesChannel * channel)
/* unqueue if complete */
if(hayes_command_is_complete(command))
{
_hayes_queue_pop(hayes, channel);
hayeschannel_queue_pop(channel);
_hayes_queue_push(hayes, channel);
}
return 0;
@ -1177,24 +1176,6 @@ static int _hayes_queue_command_full(Hayes * hayes,
#endif
/* hayes_queue_pop */
static int _hayes_queue_pop(Hayes * hayes, HayesChannel * channel)
{
HayesCommand * command;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
_hayes_reset_source(&channel->timeout);
if(channel->queue == NULL) /* nothing to send */
return 0;
command = channel->queue->data; /* XXX assumes it's valid */
hayes_command_delete(command);
channel->queue = g_slist_remove(channel->queue, command);
return 0;
}
/* hayes_queue_push */
static int _queue_push_do(Hayes * hayes, HayesChannel * channel);
@ -1226,7 +1207,7 @@ static int _queue_push_do(Hayes * hayes, HayesChannel * channel)
if(hayes_command_set_status(command, HCS_PENDING) != HCS_PENDING)
{
/* no longer push the command */
_hayes_queue_pop(hayes, channel);
hayeschannel_queue_pop(channel);
return -1;
}
attention = hayes_command_get_attention(command);
@ -1237,7 +1218,7 @@ static int _queue_push_do(Hayes * hayes, HayesChannel * channel)
if((p = realloc(channel->wr_buf, channel->wr_buf_cnt + size)) == NULL)
{
hayes_command_set_status(command, HCS_ERROR);
_hayes_queue_pop(hayes, channel);
hayeschannel_queue_pop(channel);
return -hayes->helper->error(hayes->helper->modem, strerror(
errno), 1);
}
@ -2145,7 +2126,7 @@ static gboolean _on_channel_timeout(gpointer data)
if(channel->queue == NULL || (command = channel->queue->data) == NULL)
return FALSE;
hayes_command_set_status(command, HCS_TIMEOUT);
_hayes_queue_pop(hayes, channel);
hayeschannel_queue_pop(channel);
_hayes_queue_push(hayes, channel);
return FALSE;
}

View File

@ -77,6 +77,24 @@ void hayeschannel_queue_flush(HayesChannel * channel)
}
/* hayeschannel_queue_pop */
int hayeschannel_queue_pop(HayesChannel * channel)
{
HayesCommand * command;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
_hayeschannel_reset_source(&channel->timeout);
if(channel->queue == NULL) /* nothing to send */
return 0;
command = channel->queue->data; /* XXX assumes it's valid */
hayes_command_delete(command);
channel->queue = g_slist_remove(channel->queue, command);
return 0;
}
/* private */
/* functions */
/* hayeschannel_reset_source */

View File

@ -90,5 +90,6 @@ void hayeschannel_destroy(HayesChannel * channel);
/* queue management */
void hayeschannel_queue_flush(HayesChannel * channel);
int hayeschannel_queue_pop(HayesChannel * channel);
#endif /* PHONE_MODEM_HAYES_CHANNEL_H */