cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / compat_accept.h
blob44c538a541c19122a6bcaaef64af21ddb8ed4e65
1 /*
2 * accept()/accept4() wrappers
4 * It's tricky for gnulib to work with SOCK_CLOEXEC/SOCK_NONBLOCK,
5 * and any emulation would not be thread-safe. So we'll handle
6 * accept4()-compatibility for ourselves.
8 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
9 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
12 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
13 #define MOG_ACCEPT_FN "accept4()"
14 static inline int
15 mog_accept_fn(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
17 return accept4(sockfd, addr, addrlen, SOCK_CLOEXEC|SOCK_NONBLOCK);
19 #else
20 #define MOG_ACCEPT_FN "accept()"
21 static inline int
22 mog_accept_fn(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
24 int fd = accept(sockfd, addr, addrlen);
27 * If we don't have a real accept4() syscall, don't
28 * bother setting O_CLOEXEC here. Systems without
29 * accept4() will end up calling mog_cloexec_from()
30 * anyways in a fork()-ed child
32 if (fd >= 0)
33 CHECK(int, 0, mog_set_nonblocking(fd, true));
34 return fd;
36 #endif /* HAVE_ACCEPT4 */