]> git.sesse.net Git - cubemap/commitdiff
Use accept4() to save a system call. Probably inconsequential, but still nice.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Jun 2015 20:40:40 +0000 (22:40 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Jun 2015 20:40:40 +0000 (22:40 +0200)
acceptor.cpp

index 593e4d4eb9cc207fce83730aee1c29e7a35519f2..7c28ca58038c27b107cad1b8dd82d6dd3b78bd3c 100644 (file)
@@ -130,8 +130,8 @@ void Acceptor::do_work()
                sockaddr_in6 addr;
                socklen_t addrlen = sizeof(addr);
 
                sockaddr_in6 addr;
                socklen_t addrlen = sizeof(addr);
 
-               // Get a new socket.
-               int sock = accept(server_sock, reinterpret_cast<sockaddr *>(&addr), &addrlen);
+               // Get a new socket, and set it as nonblocking.
+               int sock = accept4(server_sock, reinterpret_cast<sockaddr *>(&addr), &addrlen, SOCK_NONBLOCK);
                if (sock == -1 && errno == EINTR) {
                        continue;
                }
                if (sock == -1 && errno == EINTR) {
                        continue;
                }
@@ -141,16 +141,10 @@ void Acceptor::do_work()
                        continue;
                }
 
                        continue;
                }
 
-               // Set the socket as nonblocking.
-               int one = 1;
-               if (ioctl(sock, FIONBIO, &one) == -1) {
-                       log_perror("ioctl(FIONBIO)");
-                       exit(1);
-               }
-
                // Enable TCP_CORK for maximum throughput. In the rare case that the
                // stream stops entirely, this will cause a small delay (~200 ms)
                // before the last part is sent out, but that should be fine.
                // Enable TCP_CORK for maximum throughput. In the rare case that the
                // stream stops entirely, this will cause a small delay (~200 ms)
                // before the last part is sent out, but that should be fine.
+               int one = 1;
                if (setsockopt(sock, SOL_TCP, TCP_CORK, &one, sizeof(one)) == -1) {
                        log_perror("setsockopt(TCP_CORK)");
                        // Can still continue.
                if (setsockopt(sock, SOL_TCP, TCP_CORK, &one, sizeof(one)) == -1) {
                        log_perror("setsockopt(TCP_CORK)");
                        // Can still continue.