summaryrefslogtreecommitdiffstats
path: root/gatchat/gatserver.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-01-29 15:18:16 -0600
committerDenis Kenzior <denkenz@gmail.com>2010-02-01 17:59:28 -0600
commitb6961b0d68220ed09fa5f1539755612b6df12143 (patch)
tree18e265fb2a7eb85ed7f7ca86fdd524d0bd862361 /gatchat/gatserver.c
parent1514997ff16af413fcab6d94c122fd470d594393 (diff)
downloadofono-b6961b0d68220ed09fa5f1539755612b6df12143.tar.bz2
Refactor: Support max_read attempts like GAtChat
Diffstat (limited to 'gatchat/gatserver.c')
-rw-r--r--gatchat/gatserver.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index 85727ac5..50b64a08 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -81,6 +81,7 @@ struct _GAtServer {
GAtDebugFunc debugf; /* Debugging output function */
gpointer debug_data; /* Data to pass to debug func */
struct ring_buffer *buf; /* Current read buffer */
+ guint max_read_attempts; /* Max reads per select */
};
static int at_server_parse(GAtServer *server, char *buf);
@@ -308,6 +309,8 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
GIOError err;
gsize rbytes;
gsize toread;
+ guint total_read = 0;
+ guint read_count = 0;
if (cond & G_IO_NVAL)
return FALSE;
@@ -325,18 +328,22 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
g_at_util_debug_chat(TRUE, (char *)buf, rbytes,
server->debugf, server->debug_data);
- if (rbytes > 0) {
- ring_buffer_write_advance(server->buf, rbytes);
+ read_count++;
- new_bytes(server);
- }
+ total_read += rbytes;
+
+ if (rbytes > 0)
+ ring_buffer_write_advance(server->buf, rbytes);
+ } while (err == G_IO_ERROR_NONE && rbytes > 0 &&
+ read_count < server->max_read_attempts);
- } while (err == G_IO_ERROR_NONE && rbytes > 0);
+ if (total_read > 0)
+ new_bytes(server);
if (cond & (G_IO_HUP | G_IO_ERR))
return FALSE;
- if (rbytes == 0 && err != G_IO_ERROR_AGAIN)
+ if (read_count > 0 && rbytes == 0 && err != G_IO_ERROR_AGAIN)
return FALSE;
return TRUE;
@@ -388,6 +395,7 @@ GAtServer *g_at_server_new(GIOChannel *io)
server->debugf = NULL;
server->debug_data = NULL;
server->buf = ring_buffer_new(4096);
+ server->max_read_attempts = 3;
if (!server->buf)
goto error;