diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-28 18:06:58 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-04-28 18:08:09 +0200 |
commit | 073faa7aeca239e2bf5422f6961241009a080f4e (patch) | |
tree | a06954d18b719f6dbeb787beaf76b4dedb42207c /src | |
parent | use sig_atomic_t for running (diff) | |
download | mds-073faa7aeca239e2bf5422f6961241009a080f4e.tar.gz mds-073faa7aeca239e2bf5422f6961241009a080f4e.tar.bz2 mds-073faa7aeca239e2bf5422f6961241009a080f4e.tar.xz |
add version when marshaling
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/libmdsserver/fd-table.c | 8 | ||||
-rw-r--r-- | src/libmdsserver/fd-table.h | 3 | ||||
-rw-r--r-- | src/libmdsserver/hash-table.c | 8 | ||||
-rw-r--r-- | src/libmdsserver/hash-table.h | 3 | ||||
-rw-r--r-- | src/libmdsserver/linked-list.c | 8 | ||||
-rw-r--r-- | src/libmdsserver/linked-list.h | 2 | ||||
-rw-r--r-- | src/libmdsserver/mds-message.c | 8 | ||||
-rw-r--r-- | src/libmdsserver/mds-message.h | 2 |
8 files changed, 38 insertions, 4 deletions
diff --git a/src/libmdsserver/fd-table.c b/src/libmdsserver/fd-table.c index 78876ce..6514289 100644 --- a/src/libmdsserver/fd-table.c +++ b/src/libmdsserver/fd-table.c @@ -253,7 +253,7 @@ void fd_table_clear(fd_table_t* restrict this) size_t fd_table_marshal_size(const fd_table_t* restrict this) { size_t bitcap = (this->capacity + 63) / 64; - return (this->capacity + 2) * sizeof(size_t) + bitcap * sizeof(uint64_t); + return (this->capacity + 2) * sizeof(size_t) + bitcap * sizeof(uint64_t) + sizeof(int); } @@ -267,6 +267,9 @@ void fd_table_marshal(const fd_table_t* restrict this, char* restrict data) { size_t bitcap = (this->capacity + 63) / 64; + ((int*)data)[0] = FD_TABLE_T_VERSION; + data += sizeof(int) / sizeof(char); + ((size_t*)data)[0] = this->capacity; ((size_t*)data)[1] = this->size; data += 2 * sizeof(size_t) / sizeof(char); @@ -291,6 +294,9 @@ int fd_table_unmarshal(fd_table_t* restrict this, char* restrict data, remap_fun { size_t bitcap; + /* ((int*)data)[0] == FD_TABLE_T_VERSION */ + data += sizeof(int) / sizeof(char); + this->capacity = ((size_t*)data)[0]; this->size = ((size_t*)data)[1]; data += 2 * sizeof(size_t) / sizeof(char); diff --git a/src/libmdsserver/fd-table.h b/src/libmdsserver/fd-table.h index 5fe9d98..289a401 100644 --- a/src/libmdsserver/fd-table.h +++ b/src/libmdsserver/fd-table.h @@ -24,6 +24,9 @@ #include <stdint.h> + +#define FD_TABLE_T_VERSION 0 + /** * Value lookup table optimised for file descriptors as keys */ diff --git a/src/libmdsserver/hash-table.c b/src/libmdsserver/hash-table.c index 78d5d49..2dbf8ad 100644 --- a/src/libmdsserver/hash-table.c +++ b/src/libmdsserver/hash-table.c @@ -388,7 +388,7 @@ size_t hash_table_marshal_size(const hash_table_t* restrict this) } } - return rc + m * 3 * sizeof(size_t); + return rc + m * 3 * sizeof(size_t) + sizeof(int); } @@ -402,6 +402,9 @@ void hash_table_marshal(const hash_table_t* restrict this, char* restrict data) { size_t i, n = this->capacity; + ((int*)data)[0] = HASH_TABLE_T_VERSION; + data += sizeof(int) / sizeof(char); + ((size_t*)data)[0] = this->capacity; data += 1 * sizeof(size_t) / sizeof(char); ((float*)data)[0] = this->load_factor; @@ -441,6 +444,9 @@ int hash_table_unmarshal(hash_table_t* restrict this, char* restrict data, remap { size_t i, n; + /* ((int*)data)[0] == HASH_TABLE_T_VERSION */ + data += sizeof(int) / sizeof(char); + this->value_comparator = NULL; this->key_comparator = NULL; this->hasher = NULL; diff --git a/src/libmdsserver/hash-table.h b/src/libmdsserver/hash-table.h index 33c0aed..9a84db2 100644 --- a/src/libmdsserver/hash-table.h +++ b/src/libmdsserver/hash-table.h @@ -22,6 +22,9 @@ #include "table-common.h" + +#define HASH_TABLE_T_VERSION 0 + /** * Hash table entry */ diff --git a/src/libmdsserver/linked-list.c b/src/libmdsserver/linked-list.c index 916eaf9..601bda0 100644 --- a/src/libmdsserver/linked-list.c +++ b/src/libmdsserver/linked-list.c @@ -430,7 +430,7 @@ void linked_list_remove(linked_list_t* restrict this, ssize_t node) */ size_t linked_list_marshal_size(const linked_list_t* restrict this) { - return sizeof(size_t) * (4 + this->reuse_head + 3 * this->end); + return sizeof(size_t) * (4 + this->reuse_head + 3 * this->end) + sizeof(int); } @@ -442,6 +442,9 @@ size_t linked_list_marshal_size(const linked_list_t* restrict this) */ void linked_list_marshal(const linked_list_t* restrict this, char* restrict data) { + ((int*)data)[0] = LINKED_LIST_T_VERSION; + data += sizeof(int) / sizeof(char); + ((size_t*)data)[0] = this->capacity; ((size_t*)data)[1] = this->end; ((size_t*)data)[2] = this->reuse_head; @@ -473,6 +476,9 @@ int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data) { size_t n; + /* ((int*)data)[0] == LINKED_LIST_T_VERSION */ + data += sizeof(int) / sizeof(char); + this->reusable = NULL; this->values = NULL; this->next = NULL; diff --git a/src/libmdsserver/linked-list.h b/src/libmdsserver/linked-list.h index aa8a09b..69298ca 100644 --- a/src/libmdsserver/linked-list.h +++ b/src/libmdsserver/linked-list.h @@ -53,6 +53,8 @@ +#define LINKED_LIST_T_VERSION 0 + /** * Linear array sentinel doubly linked list class */ diff --git a/src/libmdsserver/mds-message.c b/src/libmdsserver/mds-message.c index a999c2a..99554cb 100644 --- a/src/libmdsserver/mds-message.c +++ b/src/libmdsserver/mds-message.c @@ -307,7 +307,7 @@ size_t mds_message_marshal_size(mds_message_t* this, int include_buffer) rc += strlen(this->headers[i]); rc *= sizeof(char); rc += (include_buffer ? 4 : 2) * sizeof(size_t); - rc += (include_buffer ? 1 : 0) * sizeof(int); + rc += (include_buffer ? 2 : 1) * sizeof(int); return rc; } @@ -325,6 +325,9 @@ void mds_message_marshal(mds_message_t* this, char* data, int include_buffer) { size_t i, n; + ((int*)data)[0] = MDS_MESSAGE_T_VERSION; + data += sizeof(int) / sizeof(char); + ((size_t*)data)[0] = this->header_count; ((size_t*)data)[1] = this->payload_size; if (include_buffer) @@ -369,6 +372,9 @@ int mds_message_unmarshal(mds_message_t* this, char* data) { size_t i, n, header_count; + /* ((int*)data)[0] == MDS_MESSAGE_T_VERSION */ + data += sizeof(int) / sizeof(char); + header_count = ((size_t*)data)[0]; this->header_count = 0; this->payload_size = ((size_t*)data)[1]; diff --git a/src/libmdsserver/mds-message.h b/src/libmdsserver/mds-message.h index f1cd3b1..1bc7816 100644 --- a/src/libmdsserver/mds-message.h +++ b/src/libmdsserver/mds-message.h @@ -22,6 +22,8 @@ #include <stddef.h> +#define MDS_MESSAGE_T_VERSION 0 + /** * Message passed between a server and a client or between two of either */ |