Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: runtime/bin/socket_linux.cc

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index 575da3bebc38cd62fe1bbffa8d2f72aa05657222..b9068d770d57729cb6868a8c26535b3eeda4d810 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -9,14 +9,14 @@
#include "bin/socket_linux.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"
@@ -39,11 +39,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));
}
@@ -67,7 +64,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));
@@ -93,7 +90,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;
}
@@ -111,7 +108,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;
@@ -126,7 +123,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;
@@ -139,7 +136,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;
@@ -155,7 +152,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;
@@ -200,10 +197,18 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
int Socket::GetType(intptr_t fd) {
struct stat64 buf;
int result = TEMP_FAILURE_RETRY(fstat64(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;
}
@@ -240,12 +245,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++;
}
@@ -288,7 +295,7 @@ bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
result = NO_RETRY_EXPECTED(
inet_pton(AF_INET6, address, &addr->in6.sin6_addr));
}
- return result == 1;
+ return (result == 1);
}
@@ -298,7 +305,9 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family,
SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
IPPROTO_UDP));
- if (fd < 0) return -1;
+ if (fd < 0) {
+ return -1;
+ }
if (reuseAddress) {
int optval = 1;
@@ -321,12 +330,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)))));
}
@@ -348,7 +354,9 @@ AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
intptr_t count = 0;
for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
- if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++;
+ if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
+ count++;
+ }
}
AddressList<InterfaceSocketAddress>* addresses =
@@ -374,7 +382,9 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
fd = NO_RETRY_EXPECTED(
socket(addr.ss.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
- if (fd < 0) return -1;
+ if (fd < 0) {
+ return -1;
+ }
int optval = 1;
VOID_NO_RETRY_EXPECTED(
@@ -393,7 +403,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);
@@ -461,9 +472,9 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
int err = NO_RETRY_EXPECTED(getsockopt(
fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<void *>(&on), &len));
if (err == 0) {
- *enabled = on == 1;
+ *enabled = (on == 1);
}
- return err == 0;
+ return (err == 0);
}
@@ -533,9 +544,9 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
int err = NO_RETRY_EXPECTED(getsockopt(
fd, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char *>(&on), &len));
if (err == 0) {
- *enabled = on == 1;
+ *enabled = (on == 1);
}
- return err == 0;
+ return (err == 0);
}
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698