aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-server/sending.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-18 12:58:23 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-18 12:58:23 +0200
commitba56fc3ed660609d57fafc95875ceeb2a65ffbc5 (patch)
treed7f13bc5dc4586ceff700988abe1c476fdc559e9 /src/mds-server/sending.c
parentreduce code complexity (diff)
downloadmds-ba56fc3ed660609d57fafc95875ceeb2a65ffbc5.tar.gz
mds-ba56fc3ed660609d57fafc95875ceeb2a65ffbc5.tar.bz2
mds-ba56fc3ed660609d57fafc95875ceeb2a65ffbc5.tar.xz
reduce code complexity
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-server/sending.c')
-rw-r--r--src/mds-server/sending.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mds-server/sending.c b/src/mds-server/sending.c
index 93fba5a..8c40cc4 100644
--- a/src/mds-server/sending.c
+++ b/src/mds-server/sending.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
@@ -202,3 +203,64 @@ void multicast_message(multicast_t* multicast)
}
}
+
+/**
+ * Send the next message in a clients multicast queue
+ *
+ * @param client The client
+ */
+void send_multicast_queue(client_t* client)
+{
+ while (client->multicasts_count > 0)
+ {
+ multicast_t multicast;
+ with_mutex_if (client->mutex, client->multicasts_count > 0,
+ size_t c = (client->multicasts_count -= 1) * sizeof(multicast_t);
+ multicast = client->multicasts[0];
+ memmove(client->multicasts, client->multicasts + 1, c);
+ if (c == 0)
+ {
+ free(client->multicasts);
+ client->multicasts = NULL;
+ }
+ );
+ multicast_message(&multicast);
+ multicast_destroy(&multicast);
+ }
+}
+
+
+/**
+ * Send the messages that are in a clients reply queue
+ *
+ * @param client The client
+ */
+void send_reply_queue(client_t* client)
+{
+ char* sendbuf = client->send_pending;
+ char* sendbuf_ = sendbuf;
+ size_t sent;
+ size_t n;
+
+ if (client->send_pending_size == 0)
+ return;
+
+ n = client->send_pending_size;
+ client->send_pending_size = 0;
+ client->send_pending = NULL;
+ with_mutex (client->mutex,
+ while (n > 0)
+ {
+ sent = send_message(client->socket_fd, sendbuf_, n);
+ n -= sent;
+ sendbuf_ += sent / sizeof(char);
+ if ((n > 0) && (errno != EINTR)) /* Ignore EINTR */
+ {
+ perror(*argv);
+ break;
+ }
+ }
+ free(sendbuf);
+ );
+}
+