From d48cb1ed216c6078fa79194c8ad1fa6b31d387eb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Apr 2014 14:50:26 +0200 Subject: read messages from client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-server.c | 40 ++++++++++++++++++++++++++++++++++++++-- src/mds-server.h | 7 +++++++ 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mds-server.c b/src/mds-server.c index 8ac2d03..9512457 100644 --- a/src/mds-server.c +++ b/src/mds-server.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -298,6 +299,8 @@ void* slave_loop(void* data) ssize_t entry = LINKED_LIST_UNUSED; client_t* information; size_t tmp; + int r; + /* Create information table. */ information = malloc(sizeof(client_t)); @@ -329,14 +332,47 @@ void* slave_loop(void* data) /* Fill information table. */ information->list_entry = entry; information->socket_fd = socket_fd; + if (mds_message_initialise(&(information->message))) + { + perror(*argv); + goto fail; + } + + + /* Fetch messages from the slave. */ + for (;;) + { + r = mds_message_read(&(information->message), socket_fd); + if (r == 0) + { + /* TODO */ + } + else + if (r == -2) + { + fprintf(stderr, "%s: corrupt message received.\n", *argv); + goto fail; + } + else if (errno != EINTR) + { + perror(*argv); + goto fail; + } + else + { + /* TODO */ + } + } - /* TODO */ fail: /* Close socket and free resources. */ close(socket_fd); if (information != NULL) - free(information); + { + mds_message_destroy(&(information->message)); + free(information); + } fd_table_remove(&client_map, socket_fd); /* Unlist client and decrease the slave count. */ diff --git a/src/mds-server.h b/src/mds-server.h index 5b2ab30..5c41c82 100644 --- a/src/mds-server.h +++ b/src/mds-server.h @@ -19,6 +19,8 @@ #define MDS_MDS_SERVER_H +#include + #include @@ -37,6 +39,11 @@ typedef struct client */ int socket_fd; + /** + * Message read buffer for the client + */ + mds_message_t message; + } client_t; -- cgit v1.2.3-70-g09d2