Index: runtime/bin/socket_linux.cc |
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc |
index db7704b211e3a2d47e29d38c32678992bfbef3b3..133e3335ec939fa747935b487fc2eaef7b159324 100644 |
--- a/runtime/bin/socket_linux.cc |
+++ b/runtime/bin/socket_linux.cc |
@@ -60,8 +60,8 @@ bool Socket::Initialize() { |
intptr_t Socket::Create(RawAddr addr) { |
intptr_t fd; |
- fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket(addr.ss.ss_family, SOCK_STREAM, |
- 0)); |
+ fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket( |
+ addr.ss.ss_family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)); |
if (fd < 0) { |
const int kBufferSize = 1024; |
char error_buf[kBufferSize]; |
@@ -69,8 +69,6 @@ intptr_t Socket::Create(RawAddr addr) { |
strerror_r(errno, error_buf, kBufferSize)); |
return -1; |
} |
- |
- FDUtils::SetCloseOnExec(fd); |
return fd; |
} |
@@ -94,9 +92,6 @@ intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { |
if (fd < 0) { |
return fd; |
} |
- |
- Socket::SetNonBlocking(fd); |
- |
return Socket::Connect(fd, addr, port); |
} |
@@ -315,12 +310,12 @@ intptr_t Socket::CreateBindDatagram( |
RawAddr* addr, intptr_t port, bool reuseAddress) { |
intptr_t fd; |
- fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
- socket(addr->addr.sa_family, SOCK_DGRAM, IPPROTO_UDP)); |
+ fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket( |
+ addr->addr.sa_family, |
+ SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, |
+ IPPROTO_UDP)); |
if (fd < 0) return -1; |
- FDUtils::SetCloseOnExec(fd); |
- |
if (reuseAddress) { |
int optval = 1; |
VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
@@ -335,8 +330,6 @@ intptr_t Socket::CreateBindDatagram( |
TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd)); |
return -1; |
} |
- |
- Socket::SetNonBlocking(fd); |
return fd; |
} |
@@ -398,12 +391,10 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
bool v6_only) { |
intptr_t fd; |
- fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket(addr.ss.ss_family, SOCK_STREAM, |
- 0)); |
+ fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket( |
+ addr.ss.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)); |
if (fd < 0) return -1; |
- FDUtils::SetCloseOnExec(fd); |
- |
int optval = 1; |
TEMP_FAILURE_RETRY_BLOCK_SIGNALS( |
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
@@ -440,7 +431,6 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
return -1; |
} |
- Socket::SetNonBlocking(fd); |
return fd; |
} |
@@ -459,7 +449,8 @@ intptr_t ServerSocket::Accept(intptr_t fd) { |
intptr_t socket; |
struct sockaddr clientaddr; |
socklen_t addrlen = sizeof(clientaddr); |
- socket = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(accept(fd, &clientaddr, &addrlen)); |
+ socket = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(accept4( |
+ fd, &clientaddr, &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC)); |
if (socket == -1) { |
if (IsTemporaryAcceptError(errno)) { |
// We need to signal to the caller that this is actually not an |
@@ -468,8 +459,6 @@ intptr_t ServerSocket::Accept(intptr_t fd) { |
ASSERT(kTemporaryFailure != -1); |
socket = kTemporaryFailure; |
} |
- } else { |
- Socket::SetNonBlocking(socket); |
} |
return socket; |
} |
@@ -486,16 +475,6 @@ void Socket::Close(intptr_t fd) { |
} |
-bool Socket::SetNonBlocking(intptr_t fd) { |
- return FDUtils::SetNonBlocking(fd); |
-} |
- |
- |
-bool Socket::SetBlocking(intptr_t fd) { |
- return FDUtils::SetBlocking(fd); |
-} |
- |
- |
bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { |
int on; |
socklen_t len = sizeof(on); |