Always try native accept4

This commit is contained in:
topjohnwu 2018-11-26 02:57:34 -05:00
parent 72db5b4fac
commit b01a8cace6

View File

@ -172,17 +172,28 @@ int xlisten(int sockfd, int backlog) {
return ret; return ret;
} }
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) { static int accept4_compat(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
int fd = accept(sockfd, addr, addrlen); int fd = accept(sockfd, addr, addrlen);
if (fd == -1) { if (fd == -1) {
PLOGE("accept4"); PLOGE("accept");
} } else {
if (flags & SOCK_CLOEXEC) if (flags & SOCK_CLOEXEC)
fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFD, FD_CLOEXEC);
if (flags & SOCK_NONBLOCK) { if (flags & SOCK_NONBLOCK) {
int i = fcntl(fd, F_GETFL); int i = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, i | O_NONBLOCK); fcntl(fd, F_SETFL, i | O_NONBLOCK);
} }
}
return fd;
}
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
int fd = (int) syscall(__NR_accept4, sockfd, addr, addrlen, flags);
if (fd == -1) {
if (errno == ENOSYS)
return accept4_compat(sockfd, addr, addrlen, flags);
PLOGE("accept4");
}
return fd; return fd;
} }