Index: runtime/bin/socket_android.cc |
diff --git a/runtime/bin/socket_android.cc b/runtime/bin/socket_android.cc |
index caddb3a0de1384dabc768449e51060b2a815146d..ae83b47392a1f128b815be6e730054dbe8fd9310 100644 |
--- a/runtime/bin/socket_android.cc |
+++ b/runtime/bin/socket_android.cc |
@@ -10,13 +10,13 @@ |
#include "bin/socket.h" |
#include "bin/socket_android.h" |
-#include <errno.h> // NOLINT |
+#include <errno.h> // NOLINT |
#include <netinet/tcp.h> // NOLINT |
-#include <stdio.h> // NOLINT |
-#include <stdlib.h> // NOLINT |
-#include <string.h> // NOLINT |
-#include <sys/stat.h> // NOLINT |
-#include <unistd.h> // NOLINT |
+#include <stdio.h> // NOLINT |
+#include <stdlib.h> // NOLINT |
+#include <string.h> // NOLINT |
+#include <sys/stat.h> // NOLINT |
+#include <unistd.h> // NOLINT |
#include "bin/fdutils.h" |
#include "bin/file.h" |
@@ -27,19 +27,19 @@ namespace bin { |
SocketAddress::SocketAddress(struct sockaddr* sa) { |
ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
- if (!Socket::FormatNumericAddress( |
- *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { |
+ if (!Socket::FormatNumericAddress(*reinterpret_cast<RawAddr*>(sa), as_string_, |
+ INET6_ADDRSTRLEN)) { |
as_string_[0] = 0; |
} |
socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); |
- memmove(reinterpret_cast<void *>(&addr_), sa, salen); |
+ memmove(reinterpret_cast<void*>(&addr_), sa, salen); |
} |
bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { |
socklen_t salen = SocketAddress::GetAddrLength(addr); |
- return (NO_RETRY_EXPECTED(getnameinfo( |
- &addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST)) == 0); |
+ return (NO_RETRY_EXPECTED(getnameinfo(&addr.addr, salen, address, len, NULL, |
+ 0, NI_NUMERICHOST)) == 0); |
} |
@@ -103,7 +103,7 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
bool Socket::IsBindError(intptr_t error_number) { |
return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || |
- error_number == EINVAL; |
+ error_number == EINVAL; |
} |
@@ -125,8 +125,10 @@ intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
} |
-intptr_t Socket::RecvFrom( |
- intptr_t fd, void* buffer, intptr_t num_bytes, RawAddr* addr) { |
+intptr_t 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( |
@@ -153,12 +155,14 @@ intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
} |
-intptr_t Socket::SendTo( |
- intptr_t fd, const void* buffer, intptr_t num_bytes, const RawAddr& addr) { |
+intptr_t Socket::SendTo(intptr_t fd, |
+ const void* buffer, |
+ intptr_t num_bytes, |
+ const RawAddr& addr) { |
ASSERT(fd >= 0); |
- ssize_t written_bytes = TEMP_FAILURE_RETRY( |
- 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 |
@@ -195,10 +199,7 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
void Socket::GetError(intptr_t fd, OSError* os_error) { |
int errorNumber; |
socklen_t len = sizeof(errorNumber); |
- getsockopt(fd, |
- SOL_SOCKET, |
- SO_ERROR, |
- reinterpret_cast<void*>(&errorNumber), |
+ getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<void*>(&errorNumber), |
&len); |
os_error->SetCodeAndMessage(OSError::kSystem, errorNumber); |
} |
@@ -247,9 +248,8 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host, |
status = getaddrinfo(host, 0, &hints, &info); |
if (status != 0) { |
ASSERT(*os_error == NULL); |
- *os_error = new OSError(status, |
- gai_strerror(status), |
- OSError::kGetAddressInfo); |
+ *os_error = |
+ new OSError(status, gai_strerror(status), OSError::kGetAddressInfo); |
return NULL; |
} |
} |
@@ -277,19 +277,13 @@ bool Socket::ReverseLookup(const RawAddr& addr, |
intptr_t host_len, |
OSError** os_error) { |
ASSERT(host_len >= NI_MAXHOST); |
- int status = NO_RETRY_EXPECTED(getnameinfo( |
- &addr.addr, |
- SocketAddress::GetAddrLength(addr), |
- host, |
- host_len, |
- NULL, |
- 0, |
- NI_NAMEREQD)); |
+ int status = NO_RETRY_EXPECTED( |
+ getnameinfo(&addr.addr, SocketAddress::GetAddrLength(addr), host, |
+ host_len, NULL, 0, NI_NAMEREQD)); |
if (status != 0) { |
ASSERT(*os_error == NULL); |
- *os_error = new OSError(status, |
- gai_strerror(status), |
- OSError::kGetAddressInfo); |
+ *os_error = |
+ new OSError(status, gai_strerror(status), OSError::kGetAddressInfo); |
return false; |
} |
return true; |
@@ -325,9 +319,7 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { |
} |
if (NO_RETRY_EXPECTED( |
- bind(fd, |
- &addr.addr, |
- SocketAddress::GetAddrLength(addr))) < 0) { |
+ bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) { |
VOID_TEMP_FAILURE_RETRY(close(fd)); |
return -1; |
} |
@@ -379,9 +371,7 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, |
} |
if (NO_RETRY_EXPECTED( |
- bind(fd, |
- &addr.addr, |
- SocketAddress::GetAddrLength(addr))) < 0) { |
+ bind(fd, &addr.addr, SocketAddress::GetAddrLength(addr))) < 0) { |
VOID_TEMP_FAILURE_RETRY(close(fd)); |
return -1; |
} |
@@ -418,9 +408,9 @@ static bool IsTemporaryAcceptError(int error) { |
// On Android a number of protocol errors should be treated as EAGAIN. |
// These are the ones for TCP/IP. |
return (error == EAGAIN) || (error == ENETDOWN) || (error == EPROTO) || |
- (error == ENOPROTOOPT) || (error == EHOSTDOWN) || (error == ENONET) || |
- (error == EHOSTUNREACH) || (error == EOPNOTSUPP) || |
- (error == ENETUNREACH); |
+ (error == ENOPROTOOPT) || (error == EHOSTDOWN) || (error == ENONET) || |
+ (error == EHOSTUNREACH) || (error == EOPNOTSUPP) || |
+ (error == ENETUNREACH); |
} |
@@ -454,11 +444,8 @@ void Socket::Close(intptr_t fd) { |
bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { |
int on; |
socklen_t len = sizeof(on); |
- int err = NO_RETRY_EXPECTED(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); |
} |
@@ -468,10 +455,8 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { |
bool Socket::SetNoDelay(intptr_t fd, bool enabled) { |
int on = enabled ? 1 : 0; |
- return NO_RETRY_EXPECTED(setsockopt(fd, |
- IPPROTO_TCP, |
- TCP_NODELAY, |
- reinterpret_cast<char *>(&on), |
+ return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, |
+ reinterpret_cast<char*>(&on), |
sizeof(on))) == 0; |
} |
@@ -480,13 +465,10 @@ bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { |
uint8_t on; |
socklen_t len = sizeof(on); |
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6; |
- int optname = protocol == SocketAddress::TYPE_IPV4 |
- ? IP_MULTICAST_LOOP : IPV6_MULTICAST_LOOP; |
- if (NO_RETRY_EXPECTED(getsockopt(fd, |
- level, |
- optname, |
- reinterpret_cast<char *>(&on), |
- &len)) == 0) { |
+ int optname = protocol == SocketAddress::TYPE_IPV4 ? IP_MULTICAST_LOOP |
+ : IPV6_MULTICAST_LOOP; |
+ if (NO_RETRY_EXPECTED(getsockopt(fd, level, optname, |
+ reinterpret_cast<char*>(&on), &len)) == 0) { |
*enabled = (on == 1); |
return true; |
} |
@@ -497,26 +479,21 @@ bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) { |
bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) { |
int on = enabled ? 1 : 0; |
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6; |
- int optname = protocol == SocketAddress::TYPE_IPV4 |
- ? IP_MULTICAST_LOOP : IPV6_MULTICAST_LOOP; |
- return NO_RETRY_EXPECTED(setsockopt(fd, |
- level, |
- optname, |
- reinterpret_cast<char *>(&on), |
- sizeof(on))) == 0; |
+ int optname = protocol == SocketAddress::TYPE_IPV4 ? IP_MULTICAST_LOOP |
+ : IPV6_MULTICAST_LOOP; |
+ return NO_RETRY_EXPECTED(setsockopt( |
+ fd, level, optname, reinterpret_cast<char*>(&on), sizeof(on))) == |
+ 0; |
} |
bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) { |
uint8_t v; |
socklen_t len = sizeof(v); |
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6; |
- int optname = protocol == SocketAddress::TYPE_IPV4 |
- ? IP_MULTICAST_TTL : IPV6_MULTICAST_HOPS; |
- if (NO_RETRY_EXPECTED(getsockopt(fd, |
- level, |
- optname, |
- reinterpret_cast<char *>(&v), |
- &len)) == 0) { |
+ int optname = protocol == SocketAddress::TYPE_IPV4 ? IP_MULTICAST_TTL |
+ : IPV6_MULTICAST_HOPS; |
+ if (NO_RETRY_EXPECTED(getsockopt(fd, level, optname, |
+ reinterpret_cast<char*>(&v), &len)) == 0) { |
*value = v; |
return true; |
} |
@@ -527,24 +504,18 @@ bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) { |
bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) { |
int v = value; |
int level = protocol == SocketAddress::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6; |
- int optname = protocol == SocketAddress::TYPE_IPV4 |
- ? IP_MULTICAST_TTL : IPV6_MULTICAST_HOPS; |
- return NO_RETRY_EXPECTED(setsockopt(fd, |
- level, |
- optname, |
- reinterpret_cast<char *>(&v), |
- sizeof(v))) == 0; |
+ int optname = protocol == SocketAddress::TYPE_IPV4 ? IP_MULTICAST_TTL |
+ : IPV6_MULTICAST_HOPS; |
+ 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 = NO_RETRY_EXPECTED(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); |
} |
@@ -554,33 +525,35 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) { |
bool Socket::SetBroadcast(intptr_t fd, bool enabled) { |
int on = enabled ? 1 : 0; |
- return NO_RETRY_EXPECTED(setsockopt(fd, |
- SOL_SOCKET, |
- SO_BROADCAST, |
- reinterpret_cast<char *>(&on), |
+ return NO_RETRY_EXPECTED(setsockopt(fd, SOL_SOCKET, SO_BROADCAST, |
+ reinterpret_cast<char*>(&on), |
sizeof(on))) == 0; |
} |
-bool Socket::JoinMulticast( |
- intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { |
+bool Socket::JoinMulticast(intptr_t fd, |
+ const RawAddr& addr, |
+ const RawAddr&, |
+ int interfaceIndex) { |
int proto = (addr.addr.sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6; |
struct group_req mreq; |
mreq.gr_interface = interfaceIndex; |
memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); |
- return NO_RETRY_EXPECTED(setsockopt( |
- fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0; |
+ return NO_RETRY_EXPECTED( |
+ setsockopt(fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0; |
} |
-bool Socket::LeaveMulticast( |
- intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { |
+bool Socket::LeaveMulticast(intptr_t fd, |
+ const RawAddr& addr, |
+ const RawAddr&, |
+ int interfaceIndex) { |
int proto = (addr.addr.sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6; |
struct group_req mreq; |
mreq.gr_interface = interfaceIndex; |
memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); |
- return NO_RETRY_EXPECTED(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 |