diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-18 12:58:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-18 12:58:23 +0200 |
commit | ba56fc3ed660609d57fafc95875ceeb2a65ffbc5 (patch) | |
tree | d7f13bc5dc4586ceff700988abe1c476fdc559e9 /src/mds-server | |
parent | reduce code complexity (diff) | |
download | mds-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 '')
-rw-r--r-- | src/mds-server/mds-server.c | 104 | ||||
-rw-r--r-- | src/mds-server/mds-server.h | 14 | ||||
-rw-r--r-- | src/mds-server/sending.c | 62 | ||||
-rw-r--r-- | src/mds-server/sending.h | 15 |
4 files changed, 91 insertions, 104 deletions
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c index b129170..2f587a7 100644 --- a/src/mds-server/mds-server.c +++ b/src/mds-server/mds-server.c @@ -210,37 +210,22 @@ int main(int argc_, char** argv_) { /* Accept connection. */ int client_fd = accept(socket_fd, NULL, NULL); - - /* Handle errors and shutdown. */ - if (client_fd == -1) + if (client_fd >= 0) { - switch (errno) - { - case EINTR: - /* Interrupted. */ - if (terminating) - goto terminate; - break; - - case ECONNABORTED: - case EINVAL: - /* Closing. */ - running = 0; - break; - - default: - /* Error. */ - perror(*argv); - break; - } - continue; - } - - /* Increase number of running slaves. */ - with_mutex (slave_mutex, running_slaves++;); + /* Increase number of running slaves. */ + with_mutex (slave_mutex, running_slaves++;); - /* Start slave thread. */ - create_slave(&slave_thread, client_fd); + /* Start slave thread. */ + create_slave(&slave_thread, client_fd); + } + else + /* Handle errors and shutdown. */ + if ((errno == EINTR) && terminating) /* Interrupted for termination. */ + goto terminate; + else if ((errno == ECONNABORTED) || (errno == EINVAL)) /* Closing. */ + running = 0; + else if (errno != EINTR) /* Error. */ + perror(*argv); } terminate: @@ -451,67 +436,6 @@ void* slave_loop(void* data) /** - * 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); - ); -} - - -/** * Receive a full message and update open status if the client closes * * @param client The client diff --git a/src/mds-server/mds-server.h b/src/mds-server/mds-server.h index 3936e32..a6ed9d4 100644 --- a/src/mds-server/mds-server.h +++ b/src/mds-server/mds-server.h @@ -33,20 +33,6 @@ void* slave_loop(void* data); /** - * Send the next message in a clients multicast queue - * - * @param client The client - */ -void send_multicast_queue(client_t* client); - -/** - * Send the messages that are in a clients reply queue - * - * @param client The client - */ -void send_reply_queue(client_t* client); - -/** * Perform actions that should be taken when * a message has been received from a client * 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); + ); +} + diff --git a/src/mds-server/sending.h b/src/mds-server/sending.h index 693bd37..a181c2e 100644 --- a/src/mds-server/sending.h +++ b/src/mds-server/sending.h @@ -20,6 +20,7 @@ #include "multicast.h" +#include "client.h" /** @@ -29,6 +30,20 @@ */ 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); + +/** + * Send the messages that are in a clients reply queue + * + * @param client The client + */ +void send_reply_queue(client_t* client); + #endif |