cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 44c538a541c19122a6bcaaef64af21ddb8ed4e65 1097 bytes (raw)
$ git show HEAD:compat_accept.h	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
/*
 * accept()/accept4() wrappers
 *
 * It's tricky for gnulib to work with SOCK_CLOEXEC/SOCK_NONBLOCK,
 * and any emulation would not be thread-safe.  So we'll handle
 * accept4()-compatibility for ourselves.
 *
 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */

#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK)
#define MOG_ACCEPT_FN "accept4()"
static inline int
mog_accept_fn(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
	return accept4(sockfd, addr, addrlen, SOCK_CLOEXEC|SOCK_NONBLOCK);
}
#else
#define MOG_ACCEPT_FN "accept()"
static inline int
mog_accept_fn(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
	int fd = accept(sockfd, addr, addrlen);

	/*
	 * If we don't have a real accept4() syscall, don't
	 * bother setting O_CLOEXEC here.  Systems without
	 * accept4() will end up calling mog_cloexec_from()
	 * anyways in a fork()-ed child
	 */
	if (fd >= 0)
		CHECK(int, 0, mog_set_nonblocking(fd, true));
	return fd;
}
#endif /* HAVE_ACCEPT4 */

git clone https://yhbt.net/cmogstored.git