| Index: runtime/bin/socket_macos.cc
|
| diff --git a/runtime/bin/socket_macos.cc b/runtime/bin/socket_macos.cc
|
| index f626dff6057f735a6d1efe4dd7cfdbc710093337..b1a35f086fadfce913b4f71ccfe30e132b7e9e53 100644
|
| --- a/runtime/bin/socket_macos.cc
|
| +++ b/runtime/bin/socket_macos.cc
|
| @@ -18,6 +18,7 @@
|
| #include "bin/fdutils.h"
|
| #include "bin/file.h"
|
| #include "bin/log.h"
|
| +#include "bin/signal_blocker.h"
|
| #include "bin/socket.h"
|
|
|
|
|
| @@ -37,7 +38,7 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
|
|
|
| bool Socket::FormatNumericAddress(RawAddr* addr, char* address, int len) {
|
| socklen_t salen = SocketAddress::GetAddrLength(addr);
|
| - if (TEMP_FAILURE_RETRY(getnameinfo(&addr->addr,
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getnameinfo(&addr->addr,
|
| salen,
|
| address,
|
| len,
|
| @@ -58,8 +59,8 @@ bool Socket::Initialize() {
|
|
|
| intptr_t Socket::Create(RawAddr addr) {
|
| intptr_t fd;
|
| -
|
| - fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0));
|
| + fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket(addr.ss.ss_family, SOCK_STREAM,
|
| + 0));
|
| if (fd < 0) {
|
| const int kBufferSize = 1024;
|
| char error_message[kBufferSize];
|
| @@ -75,14 +76,14 @@ 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(
|
| + intptr_t result = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| connect(fd,
|
| &addr.addr,
|
| SocketAddress::GetAddrLength(&addr)));
|
| if (result == 0 || errno == EINPROGRESS) {
|
| return fd;
|
| }
|
| - VOID_TEMP_FAILURE_RETRY(close(fd));
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
|
| return -1;
|
| }
|
|
|
| @@ -106,7 +107,8 @@ 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(read(fd, buffer, num_bytes));
|
| + ssize_t read_bytes = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(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
|
| @@ -122,7 +124,7 @@ int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes,
|
| ASSERT(fd >= 0);
|
| socklen_t addr_len = sizeof(addr->ss);
|
| ssize_t read_bytes =
|
| - TEMP_FAILURE_RETRY(
|
| + TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| 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
|
| @@ -135,7 +137,8 @@ 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(write(fd, buffer, num_bytes));
|
| + ssize_t written_bytes = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(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
|
| @@ -150,7 +153,7 @@ 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(
|
| + TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| sendto(fd, buffer, num_bytes, 0,
|
| &addr.addr, SocketAddress::GetAddrLength(&addr)));
|
| ASSERT(EAGAIN == EWOULDBLOCK);
|
| @@ -167,7 +170,7 @@ intptr_t Socket::GetPort(intptr_t fd) {
|
| ASSERT(fd >= 0);
|
| RawAddr raw;
|
| socklen_t size = sizeof(raw);
|
| - if (TEMP_FAILURE_RETRY(
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| getsockname(fd,
|
| &raw.addr,
|
| &size))) {
|
| @@ -185,7 +188,7 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
| ASSERT(fd >= 0);
|
| RawAddr raw;
|
| socklen_t size = sizeof(raw);
|
| - if (TEMP_FAILURE_RETRY(
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| getpeername(fd,
|
| &raw.addr,
|
| &size))) {
|
| @@ -269,7 +272,7 @@ bool Socket::ReverseLookup(RawAddr addr,
|
| intptr_t host_len,
|
| OSError** os_error) {
|
| ASSERT(host_len >= NI_MAXHOST);
|
| - int status = TEMP_FAILURE_RETRY(getnameinfo(
|
| + int status = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getnameinfo(
|
| &addr.addr,
|
| SocketAddress::GetAddrLength(&addr),
|
| host,
|
| @@ -304,7 +307,7 @@ intptr_t Socket::CreateBindDatagram(
|
| RawAddr* addr, intptr_t port, bool reuseAddress) {
|
| intptr_t fd;
|
|
|
| - fd = TEMP_FAILURE_RETRY(
|
| + fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| socket(addr->addr.sa_family, SOCK_DGRAM, IPPROTO_UDP));
|
| if (fd < 0) return -1;
|
|
|
| @@ -312,16 +315,16 @@ intptr_t Socket::CreateBindDatagram(
|
|
|
| if (reuseAddress) {
|
| int optval = 1;
|
| - VOID_TEMP_FAILURE_RETRY(
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
|
| }
|
|
|
| SocketAddress::SetAddrPort(addr, port);
|
| - if (TEMP_FAILURE_RETRY(
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| bind(fd,
|
| &addr->addr,
|
| SocketAddress::GetAddrLength(addr))) < 0) {
|
| - VOID_TEMP_FAILURE_RETRY(close(fd));
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
|
| return -1;
|
| }
|
|
|
| @@ -387,27 +390,28 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr,
|
| bool v6_only) {
|
| intptr_t fd;
|
|
|
| - fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0));
|
| + fd = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(socket(addr.ss.ss_family, SOCK_STREAM,
|
| + 0));
|
| if (fd < 0) return -1;
|
|
|
| FDUtils::SetCloseOnExec(fd);
|
|
|
| int optval = 1;
|
| - VOID_TEMP_FAILURE_RETRY(
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| 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(
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)));
|
| }
|
|
|
| SocketAddress::SetAddrPort(&addr, port);
|
| - if (TEMP_FAILURE_RETRY(
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| bind(fd,
|
| &addr.addr,
|
| SocketAddress::GetAddrLength(&addr))) < 0) {
|
| - VOID_TEMP_FAILURE_RETRY(close(fd));
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
|
| return -1;
|
| }
|
|
|
| @@ -417,13 +421,14 @@ 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(close(fd));
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
|
| errno = err;
|
| return new_fd;
|
| }
|
|
|
| - if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
|
| - VOID_TEMP_FAILURE_RETRY(close(fd));
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(
|
| + listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
|
| + VOID_TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
|
| return -1;
|
| }
|
|
|
| @@ -436,7 +441,7 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
|
| intptr_t socket;
|
| struct sockaddr clientaddr;
|
| socklen_t addrlen = sizeof(clientaddr);
|
| - socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen));
|
| + socket = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(accept(fd, &clientaddr, &addrlen));
|
| if (socket == -1) {
|
| if (errno == EAGAIN) {
|
| // We need to signal to the caller that this is actually not an
|
| @@ -454,7 +459,7 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
|
|
|
| void Socket::Close(intptr_t fd) {
|
| ASSERT(fd >= 0);
|
| - int err = TEMP_FAILURE_RETRY(close(fd));
|
| + int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(close(fd));
|
| if (err != 0) {
|
| const int kBufferSize = 1024;
|
| char error_message[kBufferSize];
|
| @@ -477,7 +482,7 @@ bool Socket::SetBlocking(intptr_t fd) {
|
| bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
| int on;
|
| socklen_t len = sizeof(on);
|
| - int err = TEMP_FAILURE_RETRY(getsockopt(fd,
|
| + int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
|
| IPPROTO_TCP,
|
| TCP_NODELAY,
|
| reinterpret_cast<void *>(&on),
|
| @@ -491,7 +496,7 @@ 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(setsockopt(fd,
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
|
| IPPROTO_TCP,
|
| TCP_NODELAY,
|
| reinterpret_cast<char *>(&on),
|
| @@ -505,7 +510,7 @@ 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(getsockopt(fd,
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
|
| level,
|
| optname,
|
| reinterpret_cast<char *>(&on),
|
| @@ -522,7 +527,7 @@ 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(setsockopt(fd,
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
|
| level,
|
| optname,
|
| reinterpret_cast<char *>(&on),
|
| @@ -536,7 +541,7 @@ 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(getsockopt(fd,
|
| + if (TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
|
| level,
|
| optname,
|
| reinterpret_cast<char *>(&v),
|
| @@ -553,7 +558,7 @@ 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(setsockopt(fd,
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
|
| level,
|
| optname,
|
| reinterpret_cast<char *>(&v),
|
| @@ -564,7 +569,7 @@ bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) {
|
| bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
| int on;
|
| socklen_t len = sizeof(on);
|
| - int err = TEMP_FAILURE_RETRY(getsockopt(fd,
|
| + int err = TEMP_FAILURE_RETRY_BLOCK_SIGNALS(getsockopt(fd,
|
| SOL_SOCKET,
|
| SO_BROADCAST,
|
| reinterpret_cast<char *>(&on),
|
| @@ -578,7 +583,7 @@ 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(setsockopt(fd,
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(fd,
|
| SOL_SOCKET,
|
| SO_BROADCAST,
|
| reinterpret_cast<char *>(&on),
|
| @@ -601,10 +606,10 @@ static bool JoinOrLeaveMulticast(intptr_t fd,
|
| &interface->in.sin_addr,
|
| SocketAddress::GetAddrLength(interface));
|
| if (join) {
|
| - return TEMP_FAILURE_RETRY(setsockopt(
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
|
| fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) == 0;
|
| } else {
|
| - return TEMP_FAILURE_RETRY(setsockopt(
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
|
| fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq))) == 0;
|
| }
|
| } else {
|
| @@ -615,10 +620,10 @@ static bool JoinOrLeaveMulticast(intptr_t fd,
|
| SocketAddress::GetAddrLength(addr));
|
| mreq.ipv6mr_interface = interfaceIndex;
|
| if (join) {
|
| - return TEMP_FAILURE_RETRY(setsockopt(
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
|
| fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq))) == 0;
|
| } else {
|
| - return TEMP_FAILURE_RETRY(setsockopt(
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
|
| fd, IPPROTO_IPV6, IPV6_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
|
| }
|
| }
|
| @@ -636,7 +641,7 @@ bool Socket::JoinMulticast(
|
| memmove(&mreq.imr_interface,
|
| &interface->in.sin_addr,
|
| SocketAddress::GetAddrLength(interface));
|
| - return TEMP_FAILURE_RETRY(setsockopt(
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
|
| fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) == 0;
|
| } else {
|
| ASSERT(addr->addr.sa_family == AF_INET6);
|
| @@ -646,7 +651,7 @@ bool Socket::JoinMulticast(
|
| &addr->in6.sin6_addr,
|
| SocketAddress::GetAddrLength(addr));
|
| mreq.ipv6mr_interface = interfaceIndex;
|
| - return TEMP_FAILURE_RETRY(setsockopt(
|
| + return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
|
| fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq))) == 0;
|
| }
|
| }
|
|
|