aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-08-02 20:46:31 +0200
committerMattias Andrée <maandree@operamail.com>2014-08-02 20:46:31 +0200
commit6c2873ba2bedf239fcfe6587702b1f34691cb405 (patch)
treedaa9b9e02bd0c782780ca7c26329729550580f5c /src
parentmisc (diff)
downloadmds-6c2873ba2bedf239fcfe6587702b1f34691cb405.tar.gz
mds-6c2873ba2bedf239fcfe6587702b1f34691cb405.tar.bz2
mds-6c2873ba2bedf239fcfe6587702b1f34691cb405.tar.xz
mds-registry: notify client
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/mds-registry/registry.c4
-rw-r--r--src/mds-registry/slave.c41
2 files changed, 40 insertions, 5 deletions
diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c
index b05d1a1..80bfbe3 100644
--- a/src/mds-registry/registry.c
+++ b/src/mds-registry/registry.c
@@ -385,10 +385,10 @@ static int list_registry(const char* recv_client_id, const char* recv_message_id
/* Construct message headers. */
sprintf(send_buffer + ptr, "To: %s\nIn response to: %s\nMessage ID: %" PRIi32 "\nLength: %" PRIu64 "\n\n",
- recv_message_id, recv_client_id, message_id, ptr);
+ recv_client_id, recv_message_id, message_id, ptr);
/* Increase message ID. */
- message_id = message_id == INT32_MAX ? 0 : (message_id + 1);
+ with_mutex (slave_mutex, message_id = message_id == INT32_MAX ? 0 : (message_id + 1););
/* Send message. */
if (full_send(send_buffer + ptr, strlen(send_buffer + ptr)))
diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c
index 6afc69f..6c5406d 100644
--- a/src/mds-registry/slave.c
+++ b/src/mds-registry/slave.c
@@ -22,15 +22,50 @@
#include "../mds-base.h"
+#include <libmdsserver/util.h>
#include <libmdsserver/macros.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
+#include <inttypes.h>
/**
+ * Notify the waiting client that it may resume
+ *
+ * @param slave The slave
+ * @return Non-zero, `errno` will be set accordingly
+ */
+static int slave_notify_client(slave_t* slave)
+{
+ char buf[sizeof("To: %s\nIn response to: %s\nMessage ID: %" PRIi32 "\n\n") / sizeof(char) + 40];
+ size_t ptr = 0, sent, left;
+
+ /* Construct message headers. */
+ sprintf(buf, "To: %s\nIn response to: %s\nMessage ID: %" PRIi32 "\n\n",
+ slave->client_id, slave->message_id, message_id);
+
+ /* Increase message ID. */
+ message_id = message_id == INT32_MAX ? 0 : (message_id + 1);
+
+ /* Send message to client. */
+ left = strlen(buf);
+ while (left > 0)
+ {
+ sent = send_message(socket_fd, buf + ptr, left);
+ if ((sent < left) && errno && (errno != EINTR))
+ return -1;
+ left -= sent;
+ ptr += sent;
+ }
+
+ return 0;
+}
+
+
+/**
* Master function for slave threads
*
* @param data Input data
@@ -55,10 +90,10 @@ static void* slave_loop(void* data)
pthread_cond_wait(&slave_cond, &slave_mutex);
}
- pthread_mutex_unlock(&slave_mutex);
+ if (!(slave->closed) && (slave->wait_set->size == 0))
+ slave_notify_client(slave);
- if (!(slave->closed) && slave->wait_set->size)
- ; /* FIXME send inside slave_mutex */
+ pthread_mutex_unlock(&slave_mutex);
goto done;