summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-11-09 17:32:57 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-11-09 17:32:57 +0100
commitf46355f8bc63011c8c4b3c7a707164261f94b976 (patch)
tree93276440b40d57c5eae5a80c6b4ce9f6c86fa645
parent3a0427b1e84070e4698480f7b55ac371cae06606 (diff)
downloadpjctl-f46355f8bc63011c8c4b3c7a707164261f94b976.tar.gz
pjctl-f46355f8bc63011c8c4b3c7a707164261f94b976.tar.bz2
pjctl-f46355f8bc63011c8c4b3c7a707164261f94b976.zip
Mege read_cb and recv
-rw-r--r--src/pjctl.c72
1 files changed, 32 insertions, 40 deletions
diff --git a/src/pjctl.c b/src/pjctl.c
index 92a6667..3c20d96 100644
--- a/src/pjctl.c
+++ b/src/pjctl.c
@@ -199,58 +199,50 @@ quit:
return -1;
}
-static int
-recv(struct pjctl *pjctl)
+static gboolean
+read_cb(GObject *pollable_stream, gpointer userdata)
{
+ struct pjctl *pjctl = userdata;
gssize ret;
char data[136];
char *end;
GError *error = NULL;
- ret = g_pollable_input_stream_read_nonblocking(pjctl->in,
- data, sizeof (data),
- NULL, &error);
-
- if (ret <= 0) {
- if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
- return 0;
-
+ do {
+ ret = g_pollable_input_stream_read_nonblocking(pjctl->in,
+ data,
+ sizeof data,
+ NULL, &error);
- if (ret == 0 && error == NULL) {
- g_main_loop_quit(pjctl->loop);
- return 0;
- }
+ if (ret <= 0) {
+ if (g_error_matches(error, G_IO_ERROR,
+ G_IO_ERROR_WOULD_BLOCK))
+ break;
- g_printerr("read failed: %ld: %d %s\n", ret,
- error ? error->code : -1,
- error ? error->message: "unknown");
- return 0;
- }
+ if (ret == 0 && error == NULL) {
+ g_main_loop_quit(pjctl->loop);
+ break;
+ }
- end = memchr(data, 0x0d, ret);
- if (end == NULL) {
- g_printerr("invalid pjlink msg received\n");
- g_main_loop_quit(pjctl->loop);
- return 0;
- }
+ g_printerr("read failed: %ld: %d %s\n", ret,
+ error ? error->code : -1,
+ error ? error->message: "unknown");
- *end = '\0';
- handle_data(pjctl, data, (ptrdiff_t) (end-data));
-
- return 1;
-}
+ break;
+ }
-static gboolean
-read_cb(GObject *pollable_stream, gpointer data)
-{
- struct pjctl *pjctl = data;
- GPollableInputStream *input = G_POLLABLE_INPUT_STREAM(pollable_stream);
- gint count;
+ end = memchr(data, 0x0d, ret);
+ if (end == NULL) {
+ g_printerr("invalid pjlink msg received\n");
+ g_main_loop_quit(pjctl->loop);
+ return 0;
+ }
- do {
- count = recv(pjctl);
- } while (count && g_pollable_input_stream_is_readable(input));
+ *end = '\0';
+ if (handle_data(pjctl, data, (ptrdiff_t) (end - data)) < 0)
+ break;
+ } while (g_pollable_input_stream_is_readable(pjctl->in));
return TRUE;
}
@@ -258,8 +250,8 @@ read_cb(GObject *pollable_stream, gpointer data)
static void
connection_ready(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- GError *error = NULL;
struct pjctl *pjctl = user_data;
+ GError *error = NULL;
pjctl->con = g_socket_client_connect_to_host_finish(pjctl->sc, res,
&error);