aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-04-28 14:50:26 +0200
committerMattias Andrée <maandree@operamail.com>2014-04-28 14:50:26 +0200
commitd48cb1ed216c6078fa79194c8ad1fa6b31d387eb (patch)
tree5ea15e3e877e8c10005f17593cf54167ad18e3e5
parentfix readme (diff)
downloadmds-d48cb1ed216c6078fa79194c8ad1fa6b31d387eb.tar.gz
mds-d48cb1ed216c6078fa79194c8ad1fa6b31d387eb.tar.bz2
mds-d48cb1ed216c6078fa79194c8ad1fa6b31d387eb.tar.xz
read messages from client
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/mds-server.c40
-rw-r--r--src/mds-server.h7
2 files changed, 45 insertions, 2 deletions
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 <libmdsserver/linked-list.h>
#include <libmdsserver/fd-table.h>
+#include <libmdsserver/mds-message.h>
#include <stdio.h>
#include <string.h>
@@ -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 <libmdsserver/mds-message.h>
+
#include <stdlib.h>
@@ -37,6 +39,11 @@ typedef struct client
*/
int socket_fd;
+ /**
+ * Message read buffer for the client
+ */
+ mds_message_t message;
+
} client_t;