Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1722)

Unified Diff: runtime/bin/socket_linux.cc

Issue 165723007: Move signal_blocker to platform and use it by default in TEMP_FAILURE_RETRY. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tiny fix. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index 2c05324e9b5a4f91a87d6e67b24f1e58489a09e2..e650c681ed24535b9958c0ca63d0b16752614530 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -18,8 +18,8 @@
#include "bin/fdutils.h"
#include "bin/file.h"
#include "bin/log.h"
-#include "bin/signal_blocker.h"
#include "bin/socket.h"
+#include "platform/signal_blocker.h"
#include "vm/thread.h"
@@ -39,13 +39,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
bool Socket::FormatNumericAddress(RawAddr* addr, char* address, int len) {
socklen_t salen = SocketAddress::GetAddrLength(addr);
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getnameinfo(&addr->addr,
- salen,
- address,
- len,
- NULL,
- 0,
- NI_NUMERICHOST)) != 0) {
+ if (NO_RETRY_EXPECTED(getnameinfo(
+ &addr->addr, salen, address, len, NULL, 0, NI_NUMERICHOST) != 0)) {
return false;
}
return true;
@@ -60,8 +55,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 | SOCK_NONBLOCK | SOCK_CLOEXEC, 0));
+ fd = NO_RETRY_EXPECTED(
+ socket(addr.ss.ss_family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0));
if (fd < 0) {
const int kBufferSize = 1024;
char error_buf[kBufferSize];
@@ -75,14 +70,12 @@ intptr_t Socket::Create(RawAddr addr) {
intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
SocketAddress::SetAddrPort(&addr, port);
- intptr_t result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- connect(fd,
- &addr.addr,
- SocketAddress::GetAddrLength(&addr)));
+ intptr_t result = TEMP_FAILURE_RETRY(
+ connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr)));
if (result == 0 || errno == EINPROGRESS) {
return fd;
}
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
+ VOID_TEMP_FAILURE_RETRY(close(fd));
return -1;
}
@@ -103,8 +96,7 @@ intptr_t Socket::Available(intptr_t fd) {
int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
ASSERT(fd >= 0);
- ssize_t read_bytes = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(read(fd, buffer,
- num_bytes));
+ ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
ASSERT(EAGAIN == EWOULDBLOCK);
if (read_bytes == -1 && errno == EWOULDBLOCK) {
// If the read would block we need to retry and therefore return 0
@@ -119,9 +111,8 @@ int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes,
RawAddr* addr) {
ASSERT(fd >= 0);
socklen_t addr_len = sizeof(addr->ss);
- ssize_t read_bytes =
- TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
+ ssize_t read_bytes = TEMP_FAILURE_RETRY(
+ recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
if (read_bytes == -1 && errno == EWOULDBLOCK) {
// If the read would block we need to retry and therefore return 0
// as the number of bytes written.
@@ -133,8 +124,7 @@ int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes,
int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
ASSERT(fd >= 0);
- ssize_t written_bytes = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(write(fd, buffer,
- num_bytes));
+ ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
ASSERT(EAGAIN == EWOULDBLOCK);
if (written_bytes == -1 && errno == EWOULDBLOCK) {
// If the would block we need to retry and therefore return 0 as
@@ -148,10 +138,9 @@ int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes,
RawAddr addr) {
ASSERT(fd >= 0);
- ssize_t written_bytes =
- TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- sendto(fd, buffer, num_bytes, 0,
- &addr.addr, SocketAddress::GetAddrLength(&addr)));
+ ssize_t written_bytes = TEMP_FAILURE_RETRY(
+ sendto(fd, buffer, num_bytes, 0,
+ &addr.addr, SocketAddress::GetAddrLength(&addr)));
ASSERT(EAGAIN == EWOULDBLOCK);
if (written_bytes == -1 && errno == EWOULDBLOCK) {
// If the would block we need to retry and therefore return 0 as
@@ -166,10 +155,7 @@ intptr_t Socket::GetPort(intptr_t fd) {
ASSERT(fd >= 0);
RawAddr raw;
socklen_t size = sizeof(raw);
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- getsockname(fd,
- &raw.addr,
- &size))) {
+ if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) {
const int kBufferSize = 1024;
char error_buf[kBufferSize];
Log::PrintErr("Error getsockname: %s\n",
@@ -184,10 +170,7 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
ASSERT(fd >= 0);
RawAddr raw;
socklen_t size = sizeof(raw);
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- getpeername(fd,
- &raw.addr,
- &size))) {
+ if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) {
return NULL;
}
*port = SocketAddress::GetAddrPort(&raw);
@@ -198,11 +181,8 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
void Socket::GetError(intptr_t fd, OSError* os_error) {
int len = sizeof(errno);
int err = 0;
- getsockopt(fd,
- SOL_SOCKET,
- SO_ERROR,
- &err,
- reinterpret_cast<socklen_t*>(&len));
+ VOID_NO_RETRY_EXPECTED(getsockopt(
+ fd, SOL_SOCKET, SO_ERROR, &err, reinterpret_cast<socklen_t*>(&len)));
errno = err;
os_error->SetCodeAndMessage(OSError::kSystem, errno);
}
@@ -210,7 +190,7 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
int Socket::GetType(intptr_t fd) {
struct stat64 buf;
- int result = fstat64(fd, &buf);
+ int result = NO_RETRY_EXPECTED(fstat64(fd, &buf));
if (result == -1) return -1;
if (S_ISCHR(buf.st_mode)) return File::kTerminal;
if (S_ISFIFO(buf.st_mode)) return File::kPipe;
@@ -235,12 +215,12 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
hints.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
hints.ai_protocol = IPPROTO_TCP;
struct addrinfo* info = NULL;
- int status = getaddrinfo(host, 0, &hints, &info);
+ int status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info));
if (status != 0) {
// We failed, try without AI_ADDRCONFIG. This can happen when looking up
// e.g. '::1', when there are no global IPv6 addresses.
hints.ai_flags = AI_V4MAPPED;
- status = getaddrinfo(host, 0, &hints, &info);
+ status = NO_RETRY_EXPECTED(getaddrinfo(host, 0, &hints, &info));
if (status != 0) {
ASSERT(*os_error == NULL);
*os_error = new OSError(status,
@@ -271,7 +251,7 @@ bool Socket::ReverseLookup(RawAddr addr,
intptr_t host_len,
OSError** os_error) {
ASSERT(host_len >= NI_MAXHOST);
- int status = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getnameinfo(
+ int status = NO_RETRY_EXPECTED(getnameinfo(
&addr.addr,
SocketAddress::GetAddrLength(&addr),
host,
@@ -293,10 +273,11 @@ bool Socket::ReverseLookup(RawAddr addr,
bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
int result;
if (type == SocketAddress::TYPE_IPV4) {
- result = inet_pton(AF_INET, address, &addr->in.sin_addr);
+ result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr));
} else {
ASSERT(type == SocketAddress::TYPE_IPV6);
- result = inet_pton(AF_INET6, address, &addr->in6.sin6_addr);
+ result = NO_RETRY_EXPECTED(
+ inet_pton(AF_INET6, address, &addr->in6.sin6_addr));
}
return result == 1;
}
@@ -306,24 +287,21 @@ 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 | SOCK_CLOEXEC | SOCK_NONBLOCK,
- IPPROTO_UDP));
+ fd = NO_RETRY_EXPECTED(socket(addr->addr.sa_family,
+ SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ IPPROTO_UDP));
if (fd < 0) return -1;
if (reuseAddress) {
int optval = 1;
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
+ VOID_NO_RETRY_EXPECTED(
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
}
SocketAddress::SetAddrPort(addr, port);
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- bind(fd,
- &addr->addr,
- SocketAddress::GetAddrLength(addr))) < 0) {
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
+ if (NO_RETRY_EXPECTED(
+ bind(fd, &addr->addr, SocketAddress::GetAddrLength(addr))) < 0) {
+ VOID_TEMP_FAILURE_RETRY(close(fd));
return -1;
}
return fd;
@@ -350,7 +328,7 @@ AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
OSError** os_error) {
struct ifaddrs* ifaddr;
- int status = getifaddrs(&ifaddr);
+ int status = NO_RETRY_EXPECTED(getifaddrs(&ifaddr));
if (status != 0) {
ASSERT(*os_error == NULL);
*os_error = new OSError(status,
@@ -387,26 +365,24 @@ 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 | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
+ fd = NO_RETRY_EXPECTED(
+ socket(addr.ss.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
if (fd < 0) return -1;
int optval = 1;
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
+ VOID_NO_RETRY_EXPECTED(
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
if (addr.ss.ss_family == AF_INET6) {
optval = v6_only ? 1 : 0;
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
+ VOID_NO_RETRY_EXPECTED(
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)));
}
SocketAddress::SetAddrPort(&addr, port);
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- bind(fd,
- &addr.addr,
- SocketAddress::GetAddrLength(&addr))) < 0) {
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
+ if (NO_RETRY_EXPECTED(
+ bind(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))) < 0) {
+ VOID_TEMP_FAILURE_RETRY(close(fd));
return -1;
}
@@ -416,14 +392,13 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr,
// that we do not get the bad port number again.
intptr_t new_fd = CreateBindListen(addr, 0, backlog, v6_only);
int err = errno;
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
+ VOID_TEMP_FAILURE_RETRY(close(fd));
errno = err;
return new_fd;
}
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
- listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
- VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
+ if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
+ VOID_TEMP_FAILURE_RETRY(close(fd));
return -1;
}
@@ -445,8 +420,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(accept4(
- fd, &clientaddr, &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC));
+ socket = TEMP_FAILURE_RETRY(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
@@ -462,7 +437,7 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
void Socket::Close(intptr_t fd) {
ASSERT(fd >= 0);
- int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
+ int err = TEMP_FAILURE_RETRY(close(fd));
if (err != 0) {
const int kBufferSize = 1024;
char error_buf[kBufferSize];
@@ -474,11 +449,8 @@ void Socket::Close(intptr_t fd) {
bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
int on;
socklen_t len = sizeof(on);
- int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
- IPPROTO_TCP,
- TCP_NODELAY,
- reinterpret_cast<void *>(&on),
- &len));
+ int err = NO_RETRY_EXPECTED(getsockopt(
+ fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<void *>(&on), &len));
if (err == 0) {
*enabled = on == 1;
}
@@ -488,11 +460,11 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
bool Socket::SetNoDelay(intptr_t fd, bool enabled) {
int on = enabled ? 1 : 0;
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
- IPPROTO_TCP,
- TCP_NODELAY,
- reinterpret_cast<char *>(&on),
- sizeof(on))) == 0;
+ return NO_RETRY_EXPECTED(setsockopt(fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ reinterpret_cast<char *>(&on),
+ sizeof(on))) == 0;
}
@@ -502,11 +474,8 @@ bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) {
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6;
int optname = protocol == SocketAddress::TYPE_IPV4
? IP_MULTICAST_LOOP : IPV6_MULTICAST_LOOP;
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
- level,
- optname,
- reinterpret_cast<char *>(&on),
- &len)) == 0) {
+ if (NO_RETRY_EXPECTED(getsockopt(
+ fd, level, optname, reinterpret_cast<char *>(&on), &len)) == 0) {
*enabled = (on == 1);
return true;
}
@@ -519,11 +488,8 @@ bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) {
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6;
int optname = protocol == SocketAddress::TYPE_IPV4
? IP_MULTICAST_LOOP : IPV6_MULTICAST_LOOP;
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
- level,
- optname,
- reinterpret_cast<char *>(&on),
- sizeof(on))) == 0;
+ return NO_RETRY_EXPECTED(setsockopt(
+ fd, level, optname, reinterpret_cast<char *>(&on), sizeof(on))) == 0;
}
@@ -533,11 +499,8 @@ bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) {
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6;
int optname = protocol == SocketAddress::TYPE_IPV4
? IP_MULTICAST_TTL : IPV6_MULTICAST_HOPS;
- if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
- level,
- optname,
- reinterpret_cast<char *>(&v),
- &len)) == 0) {
+ if (NO_RETRY_EXPECTED(getsockopt(
+ fd, level, optname, reinterpret_cast<char *>(&v), &len)) == 0) {
*value = v;
return true;
}
@@ -550,22 +513,16 @@ bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) {
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6;
int optname = protocol == SocketAddress::TYPE_IPV4
? IP_MULTICAST_TTL : IPV6_MULTICAST_HOPS;
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
- level,
- optname,
- reinterpret_cast<char *>(&v),
- sizeof(v))) == 0;
+ return NO_RETRY_EXPECTED(setsockopt(
+ fd, level, optname, reinterpret_cast<char *>(&v), sizeof(v))) == 0;
}
bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
int on;
socklen_t len = sizeof(on);
- int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
- SOL_SOCKET,
- SO_BROADCAST,
- reinterpret_cast<char *>(&on),
- &len));
+ int err = NO_RETRY_EXPECTED(getsockopt(
+ fd, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char *>(&on), &len));
if (err == 0) {
*enabled = on == 1;
}
@@ -575,11 +532,11 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
bool Socket::SetBroadcast(intptr_t fd, bool enabled) {
int on = enabled ? 1 : 0;
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
- SOL_SOCKET,
- SO_BROADCAST,
- reinterpret_cast<char *>(&on),
- sizeof(on))) == 0;
+ return NO_RETRY_EXPECTED(setsockopt(fd,
+ SOL_SOCKET,
+ SO_BROADCAST,
+ reinterpret_cast<char *>(&on),
+ sizeof(on))) == 0;
}
@@ -589,8 +546,8 @@ bool Socket::JoinMulticast(
struct group_req mreq;
mreq.gr_interface = interfaceIndex;
memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
- fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0;
+ return NO_RETRY_EXPECTED(
+ setsockopt(fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0;
}
@@ -600,8 +557,8 @@ bool Socket::LeaveMulticast(
struct group_req mreq;
mreq.gr_interface = interfaceIndex;
memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
- return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
- fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
+ return NO_RETRY_EXPECTED(
+ setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
}
} // namespace bin
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698