summaryrefslogtreecommitdiff
path: root/gatchat
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-04-24 18:59:44 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-04-24 18:59:44 +0200
commit8f05535bb280bb8f957e179241fb6134b947e48a (patch)
tree03cc9cc0665803941a355b8bf1cb44aa675a9620 /gatchat
parent9fd7d841c861d460e036556f0fe4dfacb2d1f1da (diff)
downloadofono-8f05535bb280bb8f957e179241fb6134b947e48a.tar.gz
Add offset parameter to ring_buffer_write_ptr() function
Diffstat (limited to 'gatchat')
-rw-r--r--gatchat/gatchat.c2
-rw-r--r--gatchat/gathdlc.c4
-rw-r--r--gatchat/gatserver.c2
-rw-r--r--gatchat/ringbuffer.c5
-rw-r--r--gatchat/ringbuffer.h9
5 files changed, 12 insertions, 10 deletions
diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index 613aad2d..6f1aa721 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -711,7 +711,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
break;
rbytes = 0;
- buf = ring_buffer_write_ptr(chat->buf);
+ buf = ring_buffer_write_ptr(chat->buf, 0);
err = g_io_channel_read(channel, (char *) buf, toread, &rbytes);
g_at_util_debug_chat(TRUE, (char *)buf, rbytes,
diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index 4ee63bba..f56fb488 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -123,7 +123,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
break;
rbytes = 0;
- buf = ring_buffer_write_ptr(hdlc->read_buffer);
+ buf = ring_buffer_write_ptr(hdlc->read_buffer, 0);
err = g_io_channel_read(channel, (char *) buf, toread, &rbytes);
g_at_util_debug_dump(TRUE, buf, rbytes,
@@ -319,7 +319,7 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size)
{
unsigned int avail = ring_buffer_avail(hdlc->write_buffer);
unsigned int wrap = ring_buffer_avail_no_wrap(hdlc->write_buffer);
- unsigned char *buf = ring_buffer_write_ptr(hdlc->write_buffer);
+ unsigned char *buf = ring_buffer_write_ptr(hdlc->write_buffer, 0);
unsigned char tail[3];
unsigned int i = 0;
guint16 fcs = HDLC_INITFCS;
diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index 06a6a93a..148754a0 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -944,7 +944,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
break;
rbytes = 0;
- buf = ring_buffer_write_ptr(server->read_buf);
+ buf = ring_buffer_write_ptr(server->read_buf, 0);
err = g_io_channel_read(channel, (char *) buf, toread, &rbytes);
g_at_util_debug_chat(TRUE, (char *)buf, rbytes,
diff --git a/gatchat/ringbuffer.c b/gatchat/ringbuffer.c
index f82a9f9d..5e9b6340 100644
--- a/gatchat/ringbuffer.c
+++ b/gatchat/ringbuffer.c
@@ -90,9 +90,10 @@ int ring_buffer_write(struct ring_buffer *buf, const void *data,
return len;
}
-unsigned char *ring_buffer_write_ptr(struct ring_buffer *buf)
+unsigned char *ring_buffer_write_ptr(struct ring_buffer *buf,
+ unsigned int offset)
{
- return buf->buffer + buf->in % buf->size;
+ return buf->buffer + (buf->in + offset) % buf->size;
}
int ring_buffer_avail_no_wrap(struct ring_buffer *buf)
diff --git a/gatchat/ringbuffer.h b/gatchat/ringbuffer.h
index f1bf3b8d..32416533 100644
--- a/gatchat/ringbuffer.h
+++ b/gatchat/ringbuffer.h
@@ -56,11 +56,12 @@ int ring_buffer_write(struct ring_buffer *buf, const void *data,
int ring_buffer_write_advance(struct ring_buffer *buf, unsigned int len);
/*!
- * Returns the write pointer. Careful not to write past the end of the
- * buffer. Use the ring_buffer_avail_no_wrap function,
- * ring_buffer_write_advance.
+ * Returns the write pointer with write offset specified by offset. Careful
+ * not to write past the end of the buffer. Use the ring_buffer_avail_no_wrap
+ * function, and ring_buffer_write_advance.
*/
-unsigned char *ring_buffer_write_ptr(struct ring_buffer *buf);
+unsigned char *ring_buffer_write_ptr(struct ring_buffer *buf,
+ unsigned int offset);
/*!
* Returns the number of free bytes available in the buffer