aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/messages6
-rw-r--r--src/libmdsserver/mds-message.h2
-rw-r--r--src/mds-server.c63
-rw-r--r--src/mds-server.h14
4 files changed, 58 insertions, 27 deletions
diff --git a/doc/messages b/doc/messages
index debcd71..7236750 100644
--- a/doc/messages
+++ b/doc/messages
@@ -30,10 +30,10 @@ only non-unique ID and client with this ID cannot
get responses. It can however ask for interceptions,
which it would receive. To get a real ID it must
ask the master server (which is the only server that
-can communicate with it when it does not have an UD)
+can communicate with it when it does not have an ID)
for an ID, this can only be done when it does not
have an ID. To do this, it sends an message with
-two headers and no payload. One of headers is
+two headers and no payload. One of the headers is
‘Command’ and its value should be ‘assign-id’,
the other header is ‘Message ID’ and its value is
an unsigned 32-bit integer of the index of the
@@ -90,7 +90,7 @@ requested to be able to modify the message. This
is done by sending the header ‘Modify’ and the
header ‘Modify ID’ with the same value as for the
message is is responding to. The value of the
-‘Modify’ header should be ‘no’ it the message
+‘Modify’ header should be ‘no’ if the message
is not modified. If the message should be modify
it the value of the ‘Modify’ header should be
‘yes’ and the payload should be the new message
diff --git a/src/libmdsserver/mds-message.h b/src/libmdsserver/mds-message.h
index 1bc7816..0f07830 100644
--- a/src/libmdsserver/mds-message.h
+++ b/src/libmdsserver/mds-message.h
@@ -34,7 +34,7 @@ typedef struct mds_message
* as an unparsed header, it consists of both the header
* name and its associated value, joined by ": ". A header
* cannot be `NULL` (unless its memory allocation failed,)
- * but `headers` itself is NULL if there are not headers.
+ * but `headers` itself is NULL if there are no headers.
* The "Length" should be included in this list.
*/
char** headers;
diff --git a/src/mds-server.c b/src/mds-server.c
index e0ef547..6f0764d 100644
--- a/src/mds-server.c
+++ b/src/mds-server.c
@@ -99,6 +99,11 @@ static fd_table_t client_map;
*/
static linked_list_t client_list;
+/**
+ * The next free ID for a client
+ */
+static uint64_t next_id = 1;
+
/**
@@ -476,6 +481,7 @@ void* slave_loop(void* data)
information->list_entry = entry;
information->socket_fd = socket_fd;
information->open = 1;
+ information->id = 0;
if (mds_message_initialise(&(information->message)))
{
perror(*argv);
@@ -489,21 +495,11 @@ void* slave_loop(void* data)
/* Make the server update without all slaves dying on SIGUSR1. */
- {
- struct sigaction action;
- sigset_t sigset;
-
- sigemptyset(&sigset);
- action.sa_handler = sigusr1_trap;
- action.sa_mask = sigset;
- action.sa_flags = 0;
-
- if (sigaction(SIGUSR1, &action, NULL) < 0)
- {
- perror(*argv);
- goto fail;
- }
- }
+ if (xsigaction(SIGUSR1, sigusr1_trap) < 0)
+ {
+ perror(*argv);
+ goto fail;
+ }
/* Fetch messages from the slave. */
@@ -512,9 +508,7 @@ void* slave_loop(void* data)
{
r = mds_message_read(&(information->message), socket_fd);
if (r == 0)
- {
- /* TODO */
- }
+ message_received(information);
else
if (r == -2)
{
@@ -526,9 +520,7 @@ void* slave_loop(void* data)
r = mds_message_read(&(information->message), socket_fd);
information->open = 0;
if (r == 0)
- {
- /* TODO */
- }
+ message_received(information);
/* Connection closed. */
break;
}
@@ -583,6 +575,25 @@ void* slave_loop(void* data)
/**
+ * Perform actions that should be taken when
+ * a message has been received from a client
+ *
+ * @param client The client has sent a message
+ */
+void message_received(client_t* client)
+{
+ mds_message_t message = client->message;
+ size_t i;
+
+ for (i = 0; i < message.header_count; i++)
+ {
+ char* header = message.headers[i];
+ /* TODO */
+ }
+}
+
+
+/**
* Exec into the mdsinitrc script
*
* @param args The arguments to the child process
@@ -729,8 +740,9 @@ int marshal_server(int fd)
/* Tell the new version of the program what version of the program it is marshalling. */
buf_set_next(state_buf_, int, MDS_SERVER_VARS_VERSION);
- /* Marshal the program's running–exit state. */
+ /* Marshal the miscellaneous state data. */
buf_set_next(state_buf_, sig_atomic_t, running);
+ buf_set_next(state_buf_, uint64_t, next_id);
/* Tell the program how large the marshalled client list is and how any clients are marshalled. */
buf_set_next(state_buf_, size_t, list_size);
@@ -755,6 +767,7 @@ int marshal_server(int fd)
buf_set_next(state_buf_, ssize_t, value->list_entry);
buf_set_next(state_buf_, int, value->socket_fd);
buf_set_next(state_buf_, int, value->open);
+ buf_set_next(state_buf_, uint64_t, value->id);
/* Marshal the message. */
mds_message_marshal(&(value->message), state_buf_, 1);
state_buf_ += msg_size / sizeof(char);
@@ -903,8 +916,9 @@ int unmarshal_server(int fd)
/* buf_get(state_buf_, int, 0, MDS_SERVER_VARS_VERSION); */
buf_next(state_buf_, int, 1);
- /* Unmarshal the program's running–exit state. */
+ /* Unmarshal the miscellaneous state data. */
buf_get_next(state_buf_, sig_atomic_t, running);
+ buf_get_next(state_buf_, uint64_t, next_id);
/* Get the marshalled size of the client list and how any clients that are marshalled. */
buf_get_next(state_buf_, size_t, list_size);
@@ -932,12 +946,14 @@ int unmarshal_server(int fd)
buf_get_next(state_buf_, ssize_t, value->list_entry);
buf_get_next(state_buf_, int, value->socket_fd);
buf_get_next(state_buf_, int, value->open);
+ buf_set_next(state_buf_, uint64_t, value->id);
/* Unmarshal the message. */
if (mds_message_unmarshal(&(value->message), state_buf_))
{
perror(*argv);
mds_message_destroy(&(value->message));
free(value);
+ buf_prev(state_buf_, uint64_t, 1);
buf_prev(state_buf_, int, 2);
buf_prev(state_buf_, size_t, 3);
goto clients_fail;
@@ -960,6 +976,7 @@ int unmarshal_server(int fd)
msg_size = ((size_t*)state_buf_)[1];
buf_next(state_buf_, size_t, 3);
buf_next(state_buf_, int, 2);
+ buf_next(state_buf_, uint64_t, 1);
state_buf_ += msg_size / sizeof(char);
}
break;
diff --git a/src/mds-server.h b/src/mds-server.h
index 609d7cf..cf0d24a 100644
--- a/src/mds-server.h
+++ b/src/mds-server.h
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <pthread.h>
+#include <stdint.h>
/**
@@ -55,6 +56,11 @@ typedef struct client
*/
pthread_t thread;
+ /**
+ * The client's ID
+ */
+ uint64_t id;
+
} client_t;
@@ -67,6 +73,14 @@ typedef struct client
void* slave_loop(void* data);
/**
+ * Perform actions that should be taken when
+ * a message has been received from a client
+ *
+ * @param client The client has sent a message
+ */
+void message_received(client_t* client);
+
+/**
* Exec into the mdsinitrc script
*
* @param args The arguments to the child process