summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2017-02-28 22:24:09 +0100
committerJoel Klinghed <the_jk@yahoo.com>2017-02-28 22:24:09 +0100
commit537ed164ae1875a8d38e06dbc214ef4f91bc4642 (patch)
tree6c165e76e099270b8c885828be46d1d4a978365a /src
parentb5143b28554608102d1ddce8aa08c37e11c858d8 (diff)
Check for accept4() and provide alternative
Diffstat (limited to 'src')
-rw-r--r--src/proxy.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/proxy.cc b/src/proxy.cc
index a567dcc..2d84208 100644
--- a/src/proxy.cc
+++ b/src/proxy.cc
@@ -15,6 +15,7 @@
#include <signal.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
#include <vector>
#include "buffer.hh"
@@ -1211,6 +1212,25 @@ void ProxyImpl::new_base(BaseClient* client, int fd) {
}
}
+#ifndef HAVE_ACCEPT4
+# define accept4 my_accept4
+# ifdef SOCK_NONBLOCK
+# undef SOCK_NONBLOCK
+# endif
+# define SOCK_NONBLOCK 1
+int my_accept4(int sockfd, struct sockaddr* addr, socklen_t* addrlen,
+ int flags) {
+ auto ret = accept(sockfd, addr, addrlen);
+ if (ret != -1 && (flags & SOCK_NONBLOCK)) {
+ if (fcntl(ret, F_SETFL, O_NONBLOCK)) {
+ close(ret);
+ return -1;
+ }
+ }
+ return ret;
+}
+#endif // HAVE_ACCEPT4
+
void ProxyImpl::new_client(int fd, uint8_t events) {
assert(fd == accept_socket_.get());
if (events == Looper::EVENT_READ) {