| Index: runtime/bin/socket_common_linux.cc
|
| diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_common_linux.cc
|
| similarity index 83%
|
| rename from runtime/bin/socket_linux.cc
|
| rename to runtime/bin/socket_common_linux.cc
|
| index af5387879c25dc2264d90a96fc3c33a0b4ca245c..8856aaf46d947a12a0a3ae47803b0bd04775eb9b 100644
|
| --- a/runtime/bin/socket_linux.cc
|
| +++ b/runtime/bin/socket_common_linux.cc
|
| @@ -8,7 +8,7 @@
|
| #if defined(TARGET_OS_LINUX)
|
|
|
| #include "bin/socket.h"
|
| -#include "bin/socket_linux.h"
|
| +#include "bin/socket_common_linux.h"
|
|
|
| #include <errno.h> // NOLINT
|
| #include <ifaddrs.h> // NOLINT
|
| @@ -39,14 +39,16 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
|
| }
|
|
|
|
|
| -bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) {
|
| +bool BaseSocket::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));
|
| }
|
|
|
|
|
| -bool Socket::Initialize() {
|
| +bool BaseSocket::Initialize() {
|
| // Nothing to do on Linux.
|
| return true;
|
| }
|
| @@ -54,8 +56,8 @@ bool Socket::Initialize() {
|
|
|
| static intptr_t Create(const RawAddr& addr) {
|
| intptr_t fd;
|
| - fd = NO_RETRY_EXPECTED(
|
| - socket(addr.ss.ss_family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0));
|
| + intptr_t type = SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC;
|
| + fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0));
|
| if (fd < 0) {
|
| return -1;
|
| }
|
| @@ -101,18 +103,18 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr,
|
| }
|
|
|
|
|
| -bool Socket::IsBindError(intptr_t error_number) {
|
| +bool BaseSocket::IsBindError(intptr_t error_number) {
|
| return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL ||
|
| error_number == EINVAL;
|
| }
|
|
|
|
|
| -intptr_t Socket::Available(intptr_t fd) {
|
| +intptr_t BaseSocket::Available(intptr_t fd) {
|
| return FDUtils::AvailableBytes(fd);
|
| }
|
|
|
|
|
| -intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
|
| +intptr_t BaseSocket::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));
|
| ASSERT(EAGAIN == EWOULDBLOCK);
|
| @@ -125,10 +127,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 BaseSocket::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(
|
| @@ -142,7 +144,9 @@ intptr_t Socket::RecvFrom(intptr_t fd,
|
| }
|
|
|
|
|
| -intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
|
| +intptr_t BaseSocket::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));
|
| ASSERT(EAGAIN == EWOULDBLOCK);
|
| @@ -155,10 +159,10 @@ 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 BaseSocket::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,
|
| @@ -173,7 +177,7 @@ intptr_t Socket::SendTo(intptr_t fd,
|
| }
|
|
|
|
|
| -intptr_t Socket::GetPort(intptr_t fd) {
|
| +intptr_t BaseSocket::GetPort(intptr_t fd) {
|
| ASSERT(fd >= 0);
|
| RawAddr raw;
|
| socklen_t size = sizeof(raw);
|
| @@ -184,7 +188,7 @@ intptr_t Socket::GetPort(intptr_t fd) {
|
| }
|
|
|
|
|
| -SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
| +SocketAddress* BaseSocket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
| ASSERT(fd >= 0);
|
| RawAddr raw;
|
| socklen_t size = sizeof(raw);
|
| @@ -196,7 +200,7 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
| }
|
|
|
|
|
| -void Socket::GetError(intptr_t fd, OSError* os_error) {
|
| +void BaseSocket::GetError(intptr_t fd, OSError* os_error) {
|
| int len = sizeof(errno);
|
| int err = 0;
|
| VOID_NO_RETRY_EXPECTED(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err,
|
| @@ -206,7 +210,7 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
|
| }
|
|
|
|
|
| -int Socket::GetType(intptr_t fd) {
|
| +int BaseSocket::GetType(intptr_t fd) {
|
| struct stat64 buf;
|
| int result = TEMP_FAILURE_RETRY(fstat64(fd, &buf));
|
| if (result == -1) {
|
| @@ -225,14 +229,14 @@ int Socket::GetType(intptr_t fd) {
|
| }
|
|
|
|
|
| -intptr_t Socket::GetStdioHandle(intptr_t num) {
|
| +intptr_t BaseSocket::GetStdioHandle(intptr_t num) {
|
| return num;
|
| }
|
|
|
|
|
| -AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
| - int type,
|
| - OSError** os_error) {
|
| +AddressList<SocketAddress>* BaseSocket::LookupAddress(const char* host,
|
| + int type,
|
| + OSError** os_error) {
|
| // Perform a name lookup for a host name.
|
| struct addrinfo hints;
|
| memset(&hints, 0, sizeof(hints));
|
| @@ -273,10 +277,10 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
| }
|
|
|
|
|
| -bool Socket::ReverseLookup(const RawAddr& addr,
|
| - char* host,
|
| - intptr_t host_len,
|
| - OSError** os_error) {
|
| +bool BaseSocket::ReverseLookup(const RawAddr& addr,
|
| + char* host,
|
| + intptr_t host_len,
|
| + OSError** os_error) {
|
| ASSERT(host_len >= NI_MAXHOST);
|
| int status = NO_RETRY_EXPECTED(
|
| getnameinfo(&addr.addr, SocketAddress::GetAddrLength(addr), host,
|
| @@ -291,7 +295,7 @@ bool Socket::ReverseLookup(const RawAddr& addr,
|
| }
|
|
|
|
|
| -bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
| +bool BaseSocket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
| int result;
|
| if (type == SocketAddress::TYPE_IPV4) {
|
| result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr));
|
| @@ -341,12 +345,12 @@ static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) {
|
| }
|
|
|
|
|
| -bool Socket::ListInterfacesSupported() {
|
| +bool BaseSocket::ListInterfacesSupported() {
|
| return true;
|
| }
|
|
|
|
|
| -AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
|
| +AddressList<InterfaceSocketAddress>* BaseSocket::ListInterfaces(
|
| int type,
|
| OSError** os_error) {
|
| struct ifaddrs* ifaddr;
|
| @@ -474,13 +478,13 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
|
| }
|
|
|
|
|
| -void Socket::Close(intptr_t fd) {
|
| +void BaseSocket::Close(intptr_t fd) {
|
| ASSERT(fd >= 0);
|
| VOID_TEMP_FAILURE_RETRY(close(fd));
|
| }
|
|
|
|
|
| -bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
| +bool BaseSocket::GetNoDelay(intptr_t fd, bool* enabled) {
|
| int on;
|
| socklen_t len = sizeof(on);
|
| int err = NO_RETRY_EXPECTED(getsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
|
| @@ -492,7 +496,7 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
| }
|
|
|
|
|
| -bool Socket::SetNoDelay(intptr_t fd, bool enabled) {
|
| +bool BaseSocket::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),
|
| @@ -500,7 +504,9 @@ bool Socket::SetNoDelay(intptr_t fd, bool enabled) {
|
| }
|
|
|
|
|
| -bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) {
|
| +bool BaseSocket::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;
|
| @@ -515,7 +521,9 @@ bool Socket::GetMulticastLoop(intptr_t fd, intptr_t protocol, bool* enabled) {
|
| }
|
|
|
|
|
| -bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) {
|
| +bool BaseSocket::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
|
| @@ -526,7 +534,7 @@ bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) {
|
| }
|
|
|
|
|
| -bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) {
|
| +bool BaseSocket::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;
|
| @@ -541,7 +549,7 @@ bool Socket::GetMulticastHops(intptr_t fd, intptr_t protocol, int* value) {
|
| }
|
|
|
|
|
| -bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) {
|
| +bool BaseSocket::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
|
| @@ -551,7 +559,7 @@ bool Socket::SetMulticastHops(intptr_t fd, intptr_t protocol, int value) {
|
| }
|
|
|
|
|
| -bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
| +bool BaseSocket::GetBroadcast(intptr_t fd, bool* enabled) {
|
| int on;
|
| socklen_t len = sizeof(on);
|
| int err = NO_RETRY_EXPECTED(getsockopt(fd, SOL_SOCKET, SO_BROADCAST,
|
| @@ -563,7 +571,7 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
| }
|
|
|
|
|
| -bool Socket::SetBroadcast(intptr_t fd, bool enabled) {
|
| +bool BaseSocket::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),
|
| @@ -571,10 +579,10 @@ bool Socket::SetBroadcast(intptr_t fd, bool enabled) {
|
| }
|
|
|
|
|
| -bool Socket::JoinMulticast(intptr_t fd,
|
| - const RawAddr& addr,
|
| - const RawAddr&,
|
| - int interfaceIndex) {
|
| +bool BaseSocket::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;
|
| @@ -584,10 +592,10 @@ bool Socket::JoinMulticast(intptr_t fd,
|
| }
|
|
|
|
|
| -bool Socket::LeaveMulticast(intptr_t fd,
|
| - const RawAddr& addr,
|
| - const RawAddr&,
|
| - int interfaceIndex) {
|
| +bool BaseSocket::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;
|
|
|