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/mds-server.c | |
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 |
1 files changed, 14 insertions, 90 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 |