summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gatchat/gathdlc.c27
-rw-r--r--gatchat/gathdlc.h1
2 files changed, 20 insertions, 8 deletions
diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index 48426674..6e71eb43 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -171,16 +171,16 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
ring_buffer_drain(rbuf, pos);
}
-GAtHDLC *g_at_hdlc_new(GIOChannel *channel)
+GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
{
GAtHDLC *hdlc;
unsigned char *buf;
- if (!channel)
+ if (io == NULL)
return NULL;
hdlc = g_try_new0(GAtHDLC, 1);
- if (!hdlc)
+ if (hdlc == NULL)
return NULL;
hdlc->ref_count = 1;
@@ -192,8 +192,6 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel)
hdlc->xmit_accm[3] = 0x60000000; /* 0x7d, 0x7e */
hdlc->recv_accm = ~0U;
- hdlc->io = g_at_io_new(channel);
-
hdlc->write_buffer = ring_buffer_new(BUFFER_SIZE * 2);
if (!hdlc->write_buffer)
goto error;
@@ -207,6 +205,7 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel)
if (!hdlc->decode_buffer)
goto error;
+ hdlc->io = g_at_io_ref(io);
g_at_io_set_read_handler(hdlc->io, new_bytes, hdlc);
hdlc->record_fd = -1;
@@ -214,9 +213,6 @@ GAtHDLC *g_at_hdlc_new(GIOChannel *channel)
return hdlc;
error:
- if (hdlc->io)
- g_at_io_unref(hdlc->io);
-
if (hdlc->write_buffer)
ring_buffer_free(hdlc->write_buffer);
@@ -228,6 +224,21 @@ error:
return NULL;
}
+GAtHDLC *g_at_hdlc_new(GIOChannel *channel)
+{
+ GAtIO *io;
+ GAtHDLC *hdlc;
+
+ io = g_at_io_new(channel);
+ if (io == NULL)
+ return NULL;
+
+ hdlc = g_at_hdlc_new_from_io(io);
+ g_at_io_unref(io);
+
+ return hdlc;
+}
+
GAtHDLC *g_at_hdlc_ref(GAtHDLC *hdlc)
{
if (!hdlc)
diff --git a/gatchat/gathdlc.h b/gatchat/gathdlc.h
index 2217558a..132e1a9e 100644
--- a/gatchat/gathdlc.h
+++ b/gatchat/gathdlc.h
@@ -34,6 +34,7 @@ struct _GAtHDLC;
typedef struct _GAtHDLC GAtHDLC;
GAtHDLC *g_at_hdlc_new(GIOChannel *channel);
+GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io);
GAtHDLC *g_at_hdlc_ref(GAtHDLC *hdlc);
void g_at_hdlc_unref(GAtHDLC *hdlc);