diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-30 23:21:39 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-30 23:21:39 +0200 |
commit | 56761cf66047107f3459424d8b37bb41d40ccdf4 (patch) | |
tree | f97ae4f777198a9399edb64a6ebeec32a217366e /control_service.c | |
parent | 651ebc75e6dae751bdebffe018701618afcc49df (diff) |
Use GDataInputStream to read data in the control and command services.
Diffstat (limited to 'control_service.c')
-rw-r--r-- | control_service.c | 27 |
1 files changed, 12 insertions, 15 deletions
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; } |