From 56761cf66047107f3459424d8b37bb41d40ccdf4 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 30 Aug 2010 23:21:39 +0200 Subject: Use GDataInputStream to read data in the control and command services. --- control_service.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'control_service.c') diff --git a/control_service.c b/control_service.c index a496812..097ae88 100644 --- a/control_service.c +++ b/control_service.c @@ -15,23 +15,15 @@ static gboolean service_incoming(GSocketService *service, GSocketConnection *connection, GObject *source_object, gpointer user_data) { GError *error = NULL; - GSocket *socket = g_socket_connection_get_socket(connection); - gchar buffer[0x400]; - gssize size; - - while((size = g_socket_receive(socket, buffer, 0x400, NULL, NULL)) > 0) { - gchar *pos = g_strstr_len(buffer, size, "\r"); - if(pos == NULL) { - pos = g_strstr_len(buffer, size, "\n"); - } - if(pos == NULL) { - g_warning("EOL not found"); - return FALSE; - } - *pos = '\0'; + GDataInputStream *input = g_data_input_stream_new(g_io_stream_get_input_stream((GIOStream*)connection)); + g_data_input_stream_set_newline_type(input, G_DATA_STREAM_NEWLINE_TYPE_LF); + gchar *line; + gsize size; - commands_handle(connection, buffer, &error); + while(g_socket_is_connected(socket) == TRUE && + (line = g_data_input_stream_read_line(input, &size, NULL, &error)) != NULL) { + commands_handle(connection, line, &error); if(error != NULL) { g_warning(error->message); @@ -43,6 +35,11 @@ static gboolean service_incoming(GSocketService *service, } } + if(error != NULL) { + g_warning(error->message); + g_error_free(error); + } + return FALSE; } -- cgit v1.2.3