Queue data from within the HayesChannel class
This commit is contained in:
parent
cfc454623e
commit
65e7c90324
@ -1206,7 +1206,7 @@ static int _queue_push_do(Hayes * hayes, HayesChannel * channel)
|
|||||||
char const * attention;
|
char const * attention;
|
||||||
const char suffix[] = "\r\n";
|
const char suffix[] = "\r\n";
|
||||||
size_t size;
|
size_t size;
|
||||||
char * p;
|
char * buf;
|
||||||
guint timeout;
|
guint timeout;
|
||||||
|
|
||||||
if(channel->queue == NULL) /* nothing to send */
|
if(channel->queue == NULL) /* nothing to send */
|
||||||
@ -1229,17 +1229,18 @@ static int _queue_push_do(Hayes * hayes, HayesChannel * channel)
|
|||||||
fprintf(stderr, "DEBUG: %s() pushing \"%s\"\n", __func__, attention);
|
fprintf(stderr, "DEBUG: %s() pushing \"%s\"\n", __func__, attention);
|
||||||
#endif
|
#endif
|
||||||
size = strlen(prefix) + strlen(attention) + sizeof(suffix);
|
size = strlen(prefix) + strlen(attention) + sizeof(suffix);
|
||||||
if((p = realloc(channel->wr_buf, channel->wr_buf_cnt + size)) == NULL)
|
if((buf = malloc(size)) == NULL
|
||||||
|
|| snprintf(buf, size, "%s%s%s", prefix, attention,
|
||||||
|
suffix) != (int)size - 1
|
||||||
|
|| hayeschannel_queue_data(channel, buf, size - 1) != 0)
|
||||||
{
|
{
|
||||||
|
free(buf);
|
||||||
hayes_command_set_status(command, HCS_ERROR);
|
hayes_command_set_status(command, HCS_ERROR);
|
||||||
hayeschannel_queue_pop(channel);
|
hayeschannel_queue_pop(channel);
|
||||||
return -hayes->helper->error(hayes->helper->modem, strerror(
|
return -hayes->helper->error(hayes->helper->modem, strerror(
|
||||||
errno), 1);
|
errno), 1);
|
||||||
}
|
}
|
||||||
channel->wr_buf = p;
|
free(buf);
|
||||||
snprintf(&channel->wr_buf[channel->wr_buf_cnt], size, "%s%s%s", prefix,
|
|
||||||
attention, suffix);
|
|
||||||
channel->wr_buf_cnt += size - 1;
|
|
||||||
if(channel->channel != NULL && channel->wr_source == 0)
|
if(channel->channel != NULL && channel->wr_source == 0)
|
||||||
channel->wr_source = g_io_add_watch(channel->channel, G_IO_OUT,
|
channel->wr_source = g_io_add_watch(channel->channel, G_IO_OUT,
|
||||||
_on_watch_can_write, channel);
|
_on_watch_can_write, channel);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <string.h>
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
|
|
||||||
@ -73,8 +74,14 @@ void hayeschannel_set_quirks(HayesChannel * channel, unsigned int quirks)
|
|||||||
int hayeschannel_queue_data(HayesChannel * channel, char const * buf,
|
int hayeschannel_queue_data(HayesChannel * channel, char const * buf,
|
||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
/* FIXME implement */
|
char * p;
|
||||||
return -1;
|
|
||||||
|
if((p = realloc(channel->wr_buf, channel->wr_buf_cnt + size)) == NULL)
|
||||||
|
return -1;
|
||||||
|
channel->wr_buf = p;
|
||||||
|
memcpy(&channel->wr_buf[channel->wr_buf_cnt], buf, size);
|
||||||
|
channel->wr_buf_cnt += size;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user