diff options
Diffstat (limited to '')
-rw-r--r-- | src/mds-server/client.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/mds-server/client.c b/src/mds-server/client.c index 0e8e0b5..0a8b107 100644 --- a/src/mds-server/client.c +++ b/src/mds-server/client.c @@ -17,6 +17,8 @@ */ #include "client.h" +#include "multicast.h" + #include <libmdsserver/macros.h> #include <stdlib.h> @@ -42,6 +44,13 @@ void client_destroy(client_t* restrict this) if (this->mutex_created) pthread_mutex_destroy(&(this->mutex)); mds_message_destroy(&(this->message)); + if (this->multicasts != NULL) + { + size_t i; + for (i = 0; i < this->multicasts_count; i++) + multicast_destroy(this->multicasts + i); + free(this->multicasts); + } free(this->send_pending); free(this); } @@ -55,12 +64,14 @@ void client_destroy(client_t* restrict this) */ size_t client_marshal_size(const client_t* restrict this) { - size_t n = sizeof(ssize_t) + 2 * sizeof(int) + sizeof(uint64_t) + 3 * sizeof(size_t); + size_t n = sizeof(ssize_t) + 2 * sizeof(int) + sizeof(uint64_t) + 4 * sizeof(size_t); size_t i; n += mds_message_marshal_size(&(this->message), 1); for (i = 0; i < this->interception_conditions_count; i++) n += interception_condition_marshal_size(this->interception_conditions + i); + for (i = 0; i < this->multicasts_count; i++) + n += multicast_marshal_size(this->multicasts + i); n += this->send_pending_size * sizeof(char); return n; @@ -88,6 +99,9 @@ size_t client_marshal(const client_t* restrict this, char* restrict data) buf_set_next(data, size_t, this->interception_conditions_count); for (i = 0; i < this->interception_conditions_count; i++) data += interception_condition_marshal(this->interception_conditions + i, data) / sizeof(char); + buf_set_next(data, size_t, this->multicasts_count); + for (i = 0; i < this->multicasts_count; i++) + data += multicast_marshal(this->multicasts + i, data) / sizeof(char); buf_set_next(data, size_t, this->send_pending_size); if (this->send_pending_size > 0) memcpy(data, this->send_pending, this->send_pending_size * sizeof(char)); @@ -104,10 +118,12 @@ size_t client_marshal(const client_t* restrict this, char* restrict data) */ size_t client_unmarshal(client_t* restrict this, char* restrict data) { - size_t i, n, rc = sizeof(ssize_t) + 2 * sizeof(int) + sizeof(uint64_t) + 3 * sizeof(size_t); + size_t i, n, rc = sizeof(ssize_t) + 2 * sizeof(int) + sizeof(uint64_t) + 4 * sizeof(size_t); this->interception_conditions = NULL; + this->multicasts = NULL; this->send_pending = NULL; this->mutex_created = 0; + this->multicasts_count = 0; buf_get_next(data, ssize_t, this->list_entry); buf_get_next(data, int, this->socket_fd); buf_get_next(data, int, this->open); @@ -131,6 +147,16 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) data += n / sizeof(char); rc += n; } + buf_get_next(data, size_t, n); + if (xmalloc(this->multicasts, n, sizeof(multicast_t))) + goto fail; + for (i = 0; i < n; i++, this->multicasts_count++) + { + size_t m = multicast_unmarshal(this->multicasts + i, data); + if (m == 0) + goto fail; + data += m / sizeof(char); + } buf_get_next(data, size_t, this->send_pending_size); if (this->send_pending_size > 0) { @@ -145,6 +171,9 @@ size_t client_unmarshal(client_t* restrict this, char* restrict data) for (i = 0; i < this->interception_conditions_count; i++) free(this->interception_conditions[i].condition); free(this->interception_conditions); + for (i = 0; i < this->multicasts_count; i++) + multicast_destroy(this->multicasts + i); + free(this->multicasts); free(this->send_pending); return 0; } @@ -167,6 +196,13 @@ size_t client_unmarshal_skip(char* restrict data) buf_get_next(data, size_t, c); while (c--) { + n = multicast_unmarshal_skip(data); + data += n / sizeof(char); + rc += n; + } + buf_get_next(data, size_t, c); + while (c--) + { n = interception_condition_unmarshal_skip(data); data += n / sizeof(char); rc += n; |