summaryrefslogtreecommitdiff
path: root/control_service.c
diff options
context:
space:
mode:
Diffstat (limited to 'control_service.c')
-rw-r--r--control_service.c27
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;
}