Chromium Code Reviews| Index: runtime/bin/socket_linux.cc |
| diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc |
| index 151ac5bb8a77fcabbfbf126954264c1fcff30d86..976bd0fb483aef539b8a06733c64cfb328c26d38 100644 |
| --- a/runtime/bin/socket_linux.cc |
| +++ b/runtime/bin/socket_linux.cc |
| @@ -28,18 +28,18 @@ namespace bin { |
| SocketAddress::SocketAddress(struct sockaddr* sa) { |
| ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| if (!Socket::FormatNumericAddress( |
| - reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { |
| + *reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { |
| as_string_[0] = 0; |
| } |
| - socklen_t salen = GetAddrLength(reinterpret_cast<RawAddr*>(sa)); |
| + socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa)); |
| memmove(reinterpret_cast<void *>(&addr_), sa, salen); |
| } |
| -bool Socket::FormatNumericAddress(RawAddr* addr, char* address, int len) { |
| +bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) { |
| socklen_t salen = SocketAddress::GetAddrLength(addr); |
| if (NO_RETRY_EXPECTED(getnameinfo( |
| - &addr->addr, salen, address, len, NULL, 0, NI_NUMERICHOST) != 0)) { |
| + &addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST) != 0)) { |
| return false; |
| } |
| return true; |
| @@ -52,7 +52,7 @@ bool Socket::Initialize() { |
| } |
| -static intptr_t Create(RawAddr addr) { |
| +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)); |
| @@ -63,10 +63,9 @@ static intptr_t Create(RawAddr addr) { |
| } |
| -static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| - SocketAddress::SetAddrPort(&addr, port); |
| +static intptr_t Connect(intptr_t fd, const RawAddr& addr) { |
| intptr_t result = TEMP_FAILURE_RETRY( |
| - connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); |
| + connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); |
| if (result == 0 || errno == EINPROGRESS) { |
| return fd; |
| } |
| @@ -75,17 +74,16 @@ static intptr_t Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| } |
| -intptr_t Socket::CreateConnect(const RawAddr& addr, const intptr_t port) { |
| +intptr_t Socket::CreateConnect(const RawAddr& addr) { |
| intptr_t fd = Create(addr); |
| if (fd < 0) { |
| return fd; |
| } |
| - return Connect(fd, addr, port); |
| + return Connect(fd, addr); |
| } |
| intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
| - const intptr_t port, |
| const RawAddr& source_addr) { |
| intptr_t fd = Create(addr); |
| if (fd < 0) { |
| @@ -93,13 +91,13 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr, |
| } |
| intptr_t result = TEMP_FAILURE_RETRY( |
| - bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(&source_addr))); |
| + bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr))); |
| if (result != 0 && errno != EINPROGRESS) { |
| VOID_TEMP_FAILURE_RETRY(close(fd)); |
| return -1; |
| } |
| - return Connect(fd, addr, port); |
| + return Connect(fd, addr); |
| } |
| @@ -121,8 +119,8 @@ 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( |
| @@ -149,12 +147,12 @@ 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, |
| - 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))); |
| + &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 |
| @@ -172,7 +170,7 @@ intptr_t Socket::GetPort(intptr_t fd) { |
| if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) { |
| return 0; |
| } |
| - return SocketAddress::GetAddrPort(&raw); |
| + return SocketAddress::GetAddrPort(raw); |
| } |
| @@ -183,7 +181,7 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
| if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) { |
| return NULL; |
| } |
| - *port = SocketAddress::GetAddrPort(&raw); |
| + *port = SocketAddress::GetAddrPort(raw); |
| return new SocketAddress(&raw.addr); |
| } |
| @@ -256,14 +254,14 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host, |
| } |
| -bool Socket::ReverseLookup(RawAddr addr, |
| +bool Socket::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), |
| + SocketAddress::GetAddrLength(addr), |
| host, |
| host_len, |
| NULL, |
| @@ -293,11 +291,10 @@ bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) { |
| } |
| -intptr_t Socket::CreateBindDatagram( |
| - RawAddr* addr, intptr_t port, bool reuseAddress) { |
| +intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) { |
| intptr_t fd; |
| - fd = NO_RETRY_EXPECTED(socket(addr->addr.sa_family, |
| + fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family, |
| SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, |
| IPPROTO_UDP)); |
| if (fd < 0) return -1; |
| @@ -308,9 +305,8 @@ intptr_t Socket::CreateBindDatagram( |
| setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
| } |
| - SocketAddress::SetAddrPort(addr, port); |
| 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; |
| } |
| @@ -369,8 +365,7 @@ AddressList<InterfaceSocketAddress>* Socket::ListInterfaces( |
| } |
| -intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
| - intptr_t port, |
| +intptr_t ServerSocket::CreateBindListen(const RawAddr& addr, |
| intptr_t backlog, |
| bool v6_only) { |
| intptr_t fd; |
| @@ -389,18 +384,17 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr, |
| setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval))); |
| } |
| - SocketAddress::SetAddrPort(&addr, port); |
| 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; |
| } |
| // Test for invalid socket port 65535 (some browsers disallow it). |
| - if (port == 0 && Socket::GetPort(fd) == 65535) { |
| + if (SocketAddress::GetAddrPort(addr) == 0 && Socket::GetPort(fd) == 65535) { |
| // Don't close the socket until we have created a new socket, ensuring |
| // that we do not get the bad port number again. |
| - intptr_t new_fd = CreateBindListen(addr, 0, backlog, v6_only); |
| + intptr_t new_fd = CreateBindListen(addr, backlog, v6_only); |
| int err = errno; |
| VOID_TEMP_FAILURE_RETRY(close(fd)); |
| errno = err; |
| @@ -554,22 +548,22 @@ bool Socket::SetBroadcast(intptr_t fd, bool enabled) { |
| bool Socket::JoinMulticast( |
| - intptr_t fd, RawAddr* addr, RawAddr*, int interfaceIndex) { |
| - int proto = addr->addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6; |
| + intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) { |
| + int proto = addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6; |
|
Bill Hesse
2015/02/12 12:28:00
These changes need to be made to JoinMulticast and
|
| struct group_req mreq; |
| mreq.gr_interface = interfaceIndex; |
| - memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| + memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); |
| return NO_RETRY_EXPECTED( |
| setsockopt(fd, proto, MCAST_JOIN_GROUP, &mreq, sizeof(mreq))) == 0; |
| } |
| bool Socket::LeaveMulticast( |
| - intptr_t fd, RawAddr* addr, RawAddr*, int interfaceIndex) { |
| - int proto = addr->addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6; |
| + 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)); |
| + memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr)); |
| return NO_RETRY_EXPECTED( |
| setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| } |