Drop NO_LEVEL; it does not look very pretty now.
[cubemap] / acceptor.cpp
index 6f7ffa240a140584afd3ea620bae7c52cbc09893..70cd30c23bdfdcd53c16efe025c2ce4e58b01bdd 100644 (file)
@@ -1,15 +1,16 @@
+#include <assert.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <poll.h>
 #include <stdio.h>
-#include <unistd.h>
-#include <string.h>
 #include <stdlib.h>
-#include <signal.h>
-#include <errno.h>
-#include <arpa/inet.h>
+#include <string.h>
 #include <sys/ioctl.h>
-#include <sys/poll.h>
 #include <sys/socket.h>
+#include <unistd.h>
 
 #include "acceptor.h"
+#include "log.h"
 #include "serverpool.h"
 #include "state.pb.h"
 
@@ -28,26 +29,26 @@ int create_server_socket(int port, SocketType socket_type)
                server_sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
        }
        if (server_sock == -1) {
-               perror("socket");
+               log_perror("socket");
                exit(1);
        }
 
        int one = 1;
        if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) {
-               perror("setsockopt(SO_REUSEADDR)");
+               log_perror("setsockopt(SO_REUSEADDR)");
                exit(1);
        }
 
        // We want dual-stack sockets. (Sorry, OpenBSD and Windows XP...)
        int zero = 0;
        if (setsockopt(server_sock, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)) == -1) {
-               perror("setsockopt(IPV6_V6ONLY)");
+               log_perror("setsockopt(IPV6_V6ONLY)");
                exit(1);
        }
 
        // Set as non-blocking, so the acceptor thread can notice that we want to shut it down.
        if (ioctl(server_sock, FIONBIO, &one) == -1) {
-               perror("ioctl(FIONBIO)");
+               log_perror("ioctl(FIONBIO)");
                exit(1);
        }
 
@@ -57,13 +58,13 @@ int create_server_socket(int port, SocketType socket_type)
        addr.sin6_port = htons(port);
 
        if (bind(server_sock, reinterpret_cast<sockaddr *>(&addr), sizeof(addr)) == -1) {
-               perror("bind");
+               log_perror("bind");
                exit(1);
        }
 
        if (socket_type == TCP_SOCKET) {
                if (listen(server_sock, 128) == -1) {
-                       perror("listen");
+                       log_perror("listen");
                        exit(1);
                }
        }
@@ -99,7 +100,7 @@ void Acceptor::close_socket()
        } while (ret == -1 && errno == EINTR);
 
        if (ret == -1) {
-               perror("close");
+               log_perror("close");
        }
 }
 
@@ -117,7 +118,7 @@ void Acceptor::do_work()
                        continue;
                }
                if (nfds == -1) {
-                       perror("poll");
+                       log_perror("poll");
                        usleep(100000);
                        continue;
                }
@@ -131,7 +132,7 @@ void Acceptor::do_work()
                        continue;
                }
                if (sock == -1) {
-                       perror("accept");
+                       log_perror("accept");
                        usleep(100000);
                        continue;
                }
@@ -139,7 +140,7 @@ void Acceptor::do_work()
                // Set the socket as nonblocking.
                int one = 1;
                if (ioctl(sock, FIONBIO, &one) == -1) {
-                       perror("FIONBIO");
+                       log_perror("FIONBIO");
                        exit(1);
                }