Commit b01a8cac authored by topjohnwu's avatar topjohnwu

Always try native accept4

parent 72db5b4f
...@@ -172,16 +172,27 @@ int xlisten(int sockfd, int backlog) { ...@@ -172,16 +172,27 @@ 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)
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (flags & SOCK_NONBLOCK) {
int i = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, i | O_NONBLOCK);
}
} }
if (flags & SOCK_CLOEXEC) return fd;
fcntl(fd, F_SETFD, FD_CLOEXEC); }
if (flags & SOCK_NONBLOCK) {
int i = fcntl(fd, F_GETFL); int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
fcntl(fd, F_SETFL, i | O_NONBLOCK); 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;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment