summaryrefslogtreecommitdiffstats
path: root/gatchat/gatchat.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-01-28 12:41:31 +0100
committerMarcel Holtmann <marcel@holtmann.org>2010-01-28 12:41:31 +0100
commit839988cfa372877f121d70e358ce3b6f9b67ccaa (patch)
tree59227af5eb86009aaac9623c6e73bb8d19b51558 /gatchat/gatchat.c
parent406988b94eba99142776868b139c3674b036d80f (diff)
downloadofono-839988cfa372877f121d70e358ce3b6f9b67ccaa.tar.bz2
Limit the number of continues read attempts
Diffstat (limited to 'gatchat/gatchat.c')
-rw-r--r--gatchat/gatchat.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index 7026408c..336a4238 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -78,6 +78,7 @@ struct _GAtChat {
gpointer user_disconnect_data; /* user disconnect data */
struct ring_buffer *buf; /* Current read buffer */
guint read_so_far; /* Number of bytes processed */
+ guint max_read_attempts; /* max number of read attempts */
GAtDebugFunc debugf; /* debugging output function */
gpointer debug_data; /* Data to pass to debug func */
char *pdu_notify; /* Unsolicited Resp w/ PDU */
@@ -694,6 +695,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
gsize rbytes;
gsize toread;
gsize total_read = 0;
+ guint read_count = 0;
if (cond & G_IO_NVAL)
return FALSE;
@@ -702,8 +704,10 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
do {
toread = ring_buffer_avail_no_wrap(chat->buf);
- if (toread == 0)
+ if (toread == 0) {
+ err = G_IO_ERROR_NONE;
break;
+ }
rbytes = 0;
buf = ring_buffer_write_ptr(chat->buf);
@@ -712,12 +716,15 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
g_at_util_debug_chat(TRUE, (char *)buf, rbytes,
chat->debugf, chat->debug_data);
+ read_count++;
+
total_read += rbytes;
if (rbytes > 0)
ring_buffer_write_advance(chat->buf, rbytes);
- } while (err == G_IO_ERROR_NONE && rbytes > 0);
+ } while (err == G_IO_ERROR_NONE && rbytes > 0 &&
+ read_count < chat->max_read_attempts);
if (total_read > 0)
new_bytes(chat);
@@ -902,6 +909,8 @@ GAtChat *g_at_chat_new(GIOChannel *channel, GAtSyntax *syntax)
chat->next_notify_id = 1;
chat->debugf = NULL;
+ chat->max_read_attempts = 1;
+
chat->buf = ring_buffer_new(4096);
if (!chat->buf)