diff options
Diffstat (limited to 'src/core/iomgr/socket_utils_posix.c')
-rw-r--r-- | src/core/iomgr/socket_utils_posix.c | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/src/core/iomgr/socket_utils_posix.c b/src/core/iomgr/socket_utils_posix.c index 1e32d7461f..3c56b46744 100644 --- a/src/core/iomgr/socket_utils_posix.c +++ b/src/core/iomgr/socket_utils_posix.c @@ -43,35 +43,27 @@ #include <grpc/support/log.h> -int -grpc_accept4 (int sockfd, struct sockaddr *addr, socklen_t * addrlen, int nonblock, int cloexec) -{ +int grpc_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, + int nonblock, int cloexec) { int fd, flags; - fd = accept (sockfd, addr, addrlen); - if (fd >= 0) - { - if (nonblock) - { - flags = fcntl (fd, F_GETFL, 0); - if (flags < 0) - goto close_and_error; - if (fcntl (fd, F_SETFL, flags | O_NONBLOCK) != 0) - goto close_and_error; - } - if (cloexec) - { - flags = fcntl (fd, F_GETFD, 0); - if (flags < 0) - goto close_and_error; - if (fcntl (fd, F_SETFD, flags | FD_CLOEXEC) != 0) - goto close_and_error; - } + fd = accept(sockfd, addr, addrlen); + if (fd >= 0) { + if (nonblock) { + flags = fcntl(fd, F_GETFL, 0); + if (flags < 0) goto close_and_error; + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) != 0) goto close_and_error; } + if (cloexec) { + flags = fcntl(fd, F_GETFD, 0); + if (flags < 0) goto close_and_error; + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) != 0) goto close_and_error; + } + } return fd; close_and_error: - close (fd); + close(fd); return -1; } |