diff options
| -rw-r--r-- | configure.ac | 3 | ||||
| -rw-r--r-- | src/proxy.cc | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 71452a9..753af8a 100644 --- a/configure.ac +++ b/configure.ac @@ -60,6 +60,9 @@ AX_GCC_FUNC_ATTRIBUTE([format]) AC_CHECK_HEADERS([sys/ioctl.h]) +# accept +AC_CHECK_FUNCS([accept4]) + # Thread THREAD_CFLAGS=-pthread 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) { |
