Wrap accept4 since some device does not have it

This commit is contained in:
topjohnwu 2018-07-17 06:52:23 +08:00
parent 18d0fd9d2a
commit 3c1aca114f

View File

@ -174,15 +174,16 @@ int xlisten(int sockfd, int backlog) {
} }
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) { int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
#ifndef __NR_accept4 int fd = accept(sockfd, addr, addrlen);
#ifdef __i386__
#define __NR_accept4 364
#endif
#endif
int fd = (int) syscall(__NR_accept4, sockfd, addr, addrlen, flags);
if (fd == -1) { if (fd == -1) {
PLOGE("accept4"); PLOGE("accept4");
} }
if (flags & SOCK_CLOEXEC)
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (flags & SOCK_NONBLOCK) {
int i = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, i | O_NONBLOCK);
}
return fd; return fd;
} }