From: Felix Morgner Date: Sun, 1 Jun 2014 14:58:23 +0000 (+0200) Subject: Some optimizations X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=5ee3db88fdd2cbe29b490a53e7e55f2a56e9cf65;hp=676d49d2b2975c49bf80d62bf4a76301d0e22e57;p=umurmur.git Some optimizations Firstly, eliminated a stupid if statement which could be replaced by a for loop. Secondly, on systems with no IPv6 support, there are no unnecessary pollfd structures being allocated anymore. --- diff --git a/src/server.c b/src/server.c index 4dee126..704f650 100644 --- a/src/server.c +++ b/src/server.c @@ -120,14 +120,8 @@ void Server_runLoop(struct pollfd* pollfds) struct sockaddr_storage remote; int i; - if (nofServerSocks == 4) { - pollfds[0].revents = 0; - pollfds[1].revents = 0; - pollfds[2].revents = 0; - pollfds[3].revents = 0; - } else { - pollfds[0].revents = 0; - pollfds[1].revents = 0; + for(i = 0; i < nofServerSocks; i++) { + pollfds[i].revents = 0; } clientcount = Client_getfds(&pollfds[nofServerSocks]); @@ -275,13 +269,13 @@ void Server_run() { struct pollfd *pollfds; - /* max clients + listen sock + udp sock + client connecting that will be disconnected */ - if ((pollfds = calloc((getIntConf(MAX_CLIENTS) + 5) , sizeof(struct pollfd))) == NULL) - Log_fatal("out of memory"); - /* Figure out bind address and port */ struct sockaddr_storage** addresses = Server_setupAddressesAndPorts(); + /* max clients + server sokets + client connecting that will be disconnected */ + if ((pollfds = calloc((getIntConf(MAX_CLIENTS) + nofServerSocks + 1) , sizeof(struct pollfd))) == NULL) + Log_fatal("out of memory"); + /* Prepare TCP sockets */ Server_setupTCPSockets(addresses, pollfds);