| Index: runtime/bin/socket_macos.cc
|
| diff --git a/runtime/bin/socket_macos.cc b/runtime/bin/socket_macos.cc
|
| index 22613d5e1890f48117840811262fe68cc4ac8b87..8306b56000162947fa27d60aac52615611c12bb1 100644
|
| --- a/runtime/bin/socket_macos.cc
|
| +++ b/runtime/bin/socket_macos.cc
|
| @@ -9,14 +9,14 @@
|
| #include "bin/socket_macos.h"
|
|
|
| #include <errno.h> // NOLINT
|
| +#include <ifaddrs.h> // NOLINT
|
| +#include <net/if.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 <net/if.h> // NOLINT
|
| -#include <netinet/tcp.h> // NOLINT
|
| -#include <ifaddrs.h> // NOLINT
|
|
|
| #include "bin/fdutils.h"
|
| #include "bin/file.h"
|
| @@ -38,16 +38,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
|
|
|
| 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) {
|
| - return false;
|
| - }
|
| - return true;
|
| + return (NO_RETRY_EXPECTED(getnameinfo(
|
| + &addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST)) == 0);
|
| }
|
|
|
|
|
| @@ -71,7 +63,7 @@ static intptr_t Create(const RawAddr& addr) {
|
| static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
|
| intptr_t result = TEMP_FAILURE_RETRY(
|
| connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
|
| - if (result == 0 || errno == EINPROGRESS) {
|
| + if ((result == 0) || (errno == EINPROGRESS)) {
|
| return fd;
|
| }
|
| VOID_TEMP_FAILURE_RETRY(close(fd));
|
| @@ -100,7 +92,7 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr,
|
|
|
| intptr_t result = TEMP_FAILURE_RETRY(
|
| bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
|
| - if (result != 0 && errno != EINPROGRESS) {
|
| + if ((result != 0) && (errno != EINPROGRESS)) {
|
| VOID_TEMP_FAILURE_RETRY(close(fd));
|
| return -1;
|
| }
|
| @@ -118,7 +110,7 @@ intptr_t 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));
|
| ASSERT(EAGAIN == EWOULDBLOCK);
|
| - if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
| + 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.
|
| read_bytes = 0;
|
| @@ -133,7 +125,7 @@ intptr_t Socket::RecvFrom(
|
| socklen_t addr_len = sizeof(addr->ss);
|
| ssize_t read_bytes = TEMP_FAILURE_RETRY(
|
| recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
|
| - if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
| + 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.
|
| read_bytes = 0;
|
| @@ -146,7 +138,7 @@ intptr_t 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));
|
| ASSERT(EAGAIN == EWOULDBLOCK);
|
| - if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
| + if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
| // If the would block we need to retry and therefore return 0 as
|
| // the number of bytes written.
|
| written_bytes = 0;
|
| @@ -162,7 +154,7 @@ intptr_t Socket::SendTo(
|
| sendto(fd, buffer, num_bytes, 0,
|
| &addr.addr, SocketAddress::GetAddrLength(addr)));
|
| ASSERT(EAGAIN == EWOULDBLOCK);
|
| - if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
| + if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
| // If the would block we need to retry and therefore return 0 as
|
| // the number of bytes written.
|
| written_bytes = 0;
|
| @@ -208,10 +200,18 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
|
| int Socket::GetType(intptr_t fd) {
|
| struct stat buf;
|
| int result = fstat(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;
|
| - if (S_ISREG(buf.st_mode)) return File::kFile;
|
| + if (result == -1) {
|
| + return -1;
|
| + }
|
| + if (S_ISCHR(buf.st_mode)) {
|
| + return File::kTerminal;
|
| + }
|
| + if (S_ISFIFO(buf.st_mode)) {
|
| + return File::kPipe;
|
| + }
|
| + if (S_ISREG(buf.st_mode)) {
|
| + return File::kFile;
|
| + }
|
| return File::kOther;
|
| }
|
|
|
| @@ -242,12 +242,14 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
| }
|
| intptr_t count = 0;
|
| for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
| - if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++;
|
| + if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
| + count++;
|
| + }
|
| }
|
| intptr_t i = 0;
|
| AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
|
| for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
| - if (c->ai_family == AF_INET || c->ai_family == AF_INET6) {
|
| + if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
| addresses->SetAt(i, new SocketAddress(c->ai_addr));
|
| i++;
|
| }
|
| @@ -289,7 +291,7 @@ bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
| ASSERT(type == SocketAddress::TYPE_IPV6);
|
| result = inet_pton(AF_INET6, address, &addr->in6.sin6_addr);
|
| }
|
| - return result == 1;
|
| + return (result == 1);
|
| }
|
|
|
|
|
| @@ -297,7 +299,9 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
|
| intptr_t fd;
|
|
|
| fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family, SOCK_DGRAM, IPPROTO_UDP));
|
| - if (fd < 0) return -1;
|
| + if (fd < 0) {
|
| + return -1;
|
| + }
|
|
|
| FDUtils::SetCloseOnExec(fd);
|
|
|
| @@ -324,12 +328,9 @@ static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) {
|
| return false;
|
| }
|
| int family = ifa->ifa_addr->sa_family;
|
| - if (lookup_family == family) return true;
|
| - if (lookup_family == AF_UNSPEC &&
|
| - (family == AF_INET || family == AF_INET6)) {
|
| - return true;
|
| - }
|
| - return false;
|
| + return ((lookup_family == family) ||
|
| + ((lookup_family == AF_UNSPEC) &&
|
| + ((family == AF_INET) || (family == AF_INET6))));
|
| }
|
|
|
|
|
| @@ -376,7 +377,9 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
| intptr_t fd;
|
|
|
| fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0));
|
| - if (fd < 0) return -1;
|
| + if (fd < 0) {
|
| + return -1;
|
| + }
|
|
|
| FDUtils::SetCloseOnExec(fd);
|
|
|
| @@ -397,7 +400,8 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
| }
|
|
|
| // Test for invalid socket port 65535 (some browsers disallow it).
|
| - if (SocketAddress::GetAddrPort(addr) == 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, backlog, v6_only);
|
| @@ -459,9 +463,9 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
| reinterpret_cast<void *>(&on),
|
| &len));
|
| if (err == 0) {
|
| - *enabled = on == 1;
|
| + *enabled = (on == 1);
|
| }
|
| - return err == 0;
|
| + return (err == 0);
|
| }
|
|
|
|
|
| @@ -546,9 +550,9 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
| reinterpret_cast<char *>(&on),
|
| &len));
|
| if (err == 0) {
|
| - *enabled = on == 1;
|
| + *enabled = (on == 1);
|
| }
|
| - return err == 0;
|
| + return (err == 0);
|
| }
|
|
|
|
|
|
|