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

Unified Diff: runtime/bin/socket.cc

Issue 2480793002: clang-format runtime/bin (Closed)
Patch Set: Created 4 years, 1 month 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.h ('k') | runtime/bin/socket_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket.cc
diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
index 687b773bc0379980aaa11891ce4d088bc0ead32e..17f56417ccb4d517a4195b98a51577f20a219a87 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -23,7 +23,7 @@ namespace bin {
static const int kSocketIdNativeField = 0;
-ListeningSocketRegistry *globalTcpListeningSocketRegistry = NULL;
+ListeningSocketRegistry* globalTcpListeningSocketRegistry = NULL;
bool short_socket_read = false;
@@ -35,7 +35,7 @@ void ListeningSocketRegistry::Initialize() {
}
-ListeningSocketRegistry *ListeningSocketRegistry::Instance() {
+ListeningSocketRegistry* ListeningSocketRegistry::Instance() {
return globalTcpListeningSocketRegistry;
}
@@ -48,9 +48,8 @@ void ListeningSocketRegistry::Cleanup() {
ListeningSocketRegistry::OSSocket* ListeningSocketRegistry::LookupByPort(
intptr_t port) {
- HashMap::Entry* entry =
- sockets_by_port_.Lookup(GetHashmapKeyFromIntptr(port),
- GetHashmapHashFromIntptr(port), false);
+ HashMap::Entry* entry = sockets_by_port_.Lookup(
+ GetHashmapKeyFromIntptr(port), GetHashmapHashFromIntptr(port), false);
if (entry == NULL) {
return NULL;
}
@@ -59,25 +58,23 @@ ListeningSocketRegistry::OSSocket* ListeningSocketRegistry::LookupByPort(
void ListeningSocketRegistry::InsertByPort(intptr_t port, OSSocket* socket) {
- HashMap::Entry* entry =
- sockets_by_port_.Lookup(GetHashmapKeyFromIntptr(port),
- GetHashmapHashFromIntptr(port), true);
+ HashMap::Entry* entry = sockets_by_port_.Lookup(
+ GetHashmapKeyFromIntptr(port), GetHashmapHashFromIntptr(port), true);
ASSERT(entry != NULL);
entry->value = reinterpret_cast<void*>(socket);
}
void ListeningSocketRegistry::RemoveByPort(intptr_t port) {
- sockets_by_port_.Remove(
- GetHashmapKeyFromIntptr(port), GetHashmapHashFromIntptr(port));
+ sockets_by_port_.Remove(GetHashmapKeyFromIntptr(port),
+ GetHashmapHashFromIntptr(port));
}
ListeningSocketRegistry::OSSocket* ListeningSocketRegistry::LookupByFd(
intptr_t fd) {
- HashMap::Entry* entry =
- sockets_by_fd_.Lookup(GetHashmapKeyFromIntptr(fd),
- GetHashmapHashFromIntptr(fd), false);
+ HashMap::Entry* entry = sockets_by_fd_.Lookup(
+ GetHashmapKeyFromIntptr(fd), GetHashmapHashFromIntptr(fd), false);
if (entry == NULL) {
return NULL;
}
@@ -86,17 +83,16 @@ ListeningSocketRegistry::OSSocket* ListeningSocketRegistry::LookupByFd(
void ListeningSocketRegistry::InsertByFd(intptr_t fd, OSSocket* socket) {
- HashMap::Entry* entry =
- sockets_by_fd_.Lookup(GetHashmapKeyFromIntptr(fd),
- GetHashmapHashFromIntptr(fd), true);
+ HashMap::Entry* entry = sockets_by_fd_.Lookup(
+ GetHashmapKeyFromIntptr(fd), GetHashmapHashFromIntptr(fd), true);
ASSERT(entry != NULL);
entry->value = reinterpret_cast<void*>(socket);
}
void ListeningSocketRegistry::RemoveByFd(intptr_t fd) {
- sockets_by_fd_.Remove(
- GetHashmapKeyFromIntptr(fd), GetHashmapHashFromIntptr(fd));
+ sockets_by_fd_.Remove(GetHashmapKeyFromIntptr(fd),
+ GetHashmapHashFromIntptr(fd));
}
@@ -113,8 +109,8 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
// There is already a socket listening on this port. We need to ensure
// that if there is one also listening on the same address, it was created
// with `shared = true`, ...
- OSSocket *os_socket = first_os_socket;
- OSSocket *os_socket_same_addr = findOSSocketWithAddress(os_socket, addr);
+ OSSocket* os_socket = first_os_socket;
+ OSSocket* os_socket_same_addr = findOSSocketWithAddress(os_socket, addr);
if (os_socket_same_addr != NULL) {
if (!os_socket_same_addr->shared || !shared) {
@@ -122,7 +118,7 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
"The shared flag to bind() needs to be `true` if "
"binding multiple times on the same (address, port) "
"combination.",
- OSError::kUnknown);
+ OSError::kUnknown);
return DartUtils::NewDartOSError(&os_error);
}
if (os_socket_same_addr->v6_only != v6_only) {
@@ -130,7 +126,7 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
"The v6Only flag to bind() needs to be the same if "
"binding multiple times on the same (address, port) "
"combination.",
- OSError::kUnknown);
+ OSError::kUnknown);
return DartUtils::NewDartOSError(&os_error);
}
@@ -163,7 +159,7 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
intptr_t allocated_port = Socket::GetPort(socketfd);
ASSERT(allocated_port > 0);
- OSSocket *os_socket =
+ OSSocket* os_socket =
new OSSocket(addr, allocated_port, v6_only, shared, socketfd);
os_socket->ref_count = 1;
os_socket->next = first_os_socket;
@@ -216,8 +212,7 @@ bool ListeningSocketRegistry::CloseOneSafe(OSSocket* os_socket) {
void ListeningSocketRegistry::CloseAllSafe() {
MutexLocker ml(mutex_);
- for (HashMap::Entry* p = sockets_by_fd_.Start();
- p != NULL;
+ for (HashMap::Entry* p = sockets_by_fd_.Start(); p != NULL;
p = sockets_by_fd_.Next(p)) {
CloseOneSafe(reinterpret_cast<OSSocket*>(p->value));
}
@@ -440,16 +435,12 @@ void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) {
Dart_PropagateError(dart_args[3]);
}
// TODO(sgjesse): Cache the _makeDatagram function somewhere.
- Dart_Handle io_lib =
- Dart_LookupLibrary(DartUtils::NewString("dart:io"));
+ Dart_Handle io_lib = Dart_LookupLibrary(DartUtils::NewString("dart:io"));
if (Dart_IsError(io_lib)) {
Dart_PropagateError(io_lib);
}
- Dart_Handle result =
- Dart_Invoke(io_lib,
- DartUtils::NewString("_makeDatagram"),
- kNumArgs,
- dart_args);
+ Dart_Handle result = Dart_Invoke(
+ io_lib, DartUtils::NewString("_makeDatagram"), kNumArgs, dart_args);
Dart_SetReturnValue(args, result);
}
@@ -459,10 +450,8 @@ void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
ASSERT(Dart_IsList(buffer_obj));
- intptr_t offset =
- DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
- intptr_t length =
- DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3));
+ intptr_t offset = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
+ intptr_t length = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3));
bool short_write = false;
if (short_socket_write) {
if (length > 1) {
@@ -503,18 +492,14 @@ void FUNCTION_NAME(Socket_SendTo)(Dart_NativeArguments args) {
intptr_t socket =
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
- intptr_t offset =
- DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
- intptr_t length =
- DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3));
+ intptr_t offset = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
+ intptr_t length = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3));
Dart_Handle address_obj = Dart_GetNativeArgument(args, 4);
ASSERT(Dart_IsList(address_obj));
RawAddr addr;
SocketAddress::GetSockAddr(address_obj, &addr);
int64_t port = DartUtils::GetInt64ValueCheckRange(
- Dart_GetNativeArgument(args, 5),
- 0,
- 65535);
+ Dart_GetNativeArgument(args, 5), 0, 65535);
SocketAddress::SetAddrPort(&addr, port);
Dart_TypedData_Type type;
uint8_t* buffer = NULL;
@@ -604,8 +589,8 @@ void FUNCTION_NAME(Socket_GetType)(Dart_NativeArguments args) {
void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) {
- int64_t num = DartUtils::GetInt64ValueCheckRange(
- Dart_GetNativeArgument(args, 1), 0, 2);
+ int64_t num =
+ DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 1), 0, 2);
intptr_t socket = Socket::GetStdioHandle(num);
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket);
Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0));
@@ -628,14 +613,10 @@ void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) {
RawAddr addr;
SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr);
int64_t port = DartUtils::GetInt64ValueCheckRange(
- Dart_GetNativeArgument(args, 2),
- 0,
- 65535);
+ Dart_GetNativeArgument(args, 2), 0, 65535);
SocketAddress::SetAddrPort(&addr, port);
int64_t backlog = DartUtils::GetInt64ValueCheckRange(
- Dart_GetNativeArgument(args, 3),
- 0,
- 65535);
+ Dart_GetNativeArgument(args, 3), 0, 65535);
bool v6_only = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 4));
bool shared = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 5));
@@ -662,8 +643,7 @@ void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) {
CObject* Socket::LookupRequest(const CObjectArray& request) {
- if ((request.Length() == 2) &&
- request[0]->IsString() &&
+ if ((request.Length() == 2) && request[0]->IsString() &&
request[1]->IsInt32()) {
CObjectString host(request[0]);
CObjectInt32 type(request[1]);
@@ -672,19 +652,19 @@ CObject* Socket::LookupRequest(const CObjectArray& request) {
AddressList<SocketAddress>* addresses =
Socket::LookupAddress(host.CString(), type.Value(), &os_error);
if (addresses != NULL) {
- CObjectArray* array = new CObjectArray(
- CObject::NewArray(addresses->count() + 1));
+ CObjectArray* array =
+ new CObjectArray(CObject::NewArray(addresses->count() + 1));
array->SetAt(0, new CObjectInt32(CObject::NewInt32(0)));
for (intptr_t i = 0; i < addresses->count(); i++) {
SocketAddress* addr = addresses->GetAt(i);
CObjectArray* entry = new CObjectArray(CObject::NewArray(3));
- CObjectInt32* type = new CObjectInt32(
- CObject::NewInt32(addr->GetType()));
+ CObjectInt32* type =
+ new CObjectInt32(CObject::NewInt32(addr->GetType()));
entry->SetAt(0, type);
- CObjectString* as_string = new CObjectString(CObject::NewString(
- addr->as_string()));
+ CObjectString* as_string =
+ new CObjectString(CObject::NewString(addr->as_string()));
entry->SetAt(1, as_string);
RawAddr raw = addr->addr();
@@ -706,23 +686,20 @@ CObject* Socket::LookupRequest(const CObjectArray& request) {
CObject* Socket::ReverseLookupRequest(const CObjectArray& request) {
- if ((request.Length() == 1) &&
- request[0]->IsTypedData()) {
+ if ((request.Length() == 1) && request[0]->IsTypedData()) {
CObjectUint8Array addr_object(request[0]);
RawAddr addr;
int len = addr_object.Length();
memset(reinterpret_cast<void*>(&addr), 0, sizeof(RawAddr));
if (len == sizeof(in_addr)) {
addr.in.sin_family = AF_INET;
- memmove(reinterpret_cast<void*>(&addr.in.sin_addr),
- addr_object.Buffer(),
+ memmove(reinterpret_cast<void*>(&addr.in.sin_addr), addr_object.Buffer(),
len);
} else {
ASSERT(len == sizeof(in6_addr));
addr.in6.sin6_family = AF_INET6;
memmove(reinterpret_cast<void*>(&addr.in6.sin6_addr),
- addr_object.Buffer(),
- len);
+ addr_object.Buffer(), len);
}
OSError* os_error = NULL;
@@ -741,40 +718,39 @@ CObject* Socket::ReverseLookupRequest(const CObjectArray& request) {
CObject* Socket::ListInterfacesRequest(const CObjectArray& request) {
- if ((request.Length() == 1) &&
- request[0]->IsInt32()) {
+ if ((request.Length() == 1) && request[0]->IsInt32()) {
CObjectInt32 type(request[0]);
CObject* result = NULL;
OSError* os_error = NULL;
- AddressList<InterfaceSocketAddress>* addresses = Socket::ListInterfaces(
- type.Value(), &os_error);
+ AddressList<InterfaceSocketAddress>* addresses =
+ Socket::ListInterfaces(type.Value(), &os_error);
if (addresses != NULL) {
- CObjectArray* array = new CObjectArray(
- CObject::NewArray(addresses->count() + 1));
+ CObjectArray* array =
+ new CObjectArray(CObject::NewArray(addresses->count() + 1));
array->SetAt(0, new CObjectInt32(CObject::NewInt32(0)));
for (intptr_t i = 0; i < addresses->count(); i++) {
InterfaceSocketAddress* interface = addresses->GetAt(i);
SocketAddress* addr = interface->socket_address();
CObjectArray* entry = new CObjectArray(CObject::NewArray(5));
- CObjectInt32* type = new CObjectInt32(
- CObject::NewInt32(addr->GetType()));
+ CObjectInt32* type =
+ new CObjectInt32(CObject::NewInt32(addr->GetType()));
entry->SetAt(0, type);
- CObjectString* as_string = new CObjectString(CObject::NewString(
- addr->as_string()));
+ CObjectString* as_string =
+ new CObjectString(CObject::NewString(addr->as_string()));
entry->SetAt(1, as_string);
RawAddr raw = addr->addr();
CObjectUint8Array* data = SocketAddress::ToCObject(raw);
entry->SetAt(2, data);
- CObjectString* interface_name = new CObjectString(CObject::NewString(
- interface->interface_name()));
+ CObjectString* interface_name =
+ new CObjectString(CObject::NewString(interface->interface_name()));
entry->SetAt(3, interface_name);
- CObjectInt64* interface_index = new CObjectInt64(CObject::NewInt64(
- interface->interface_index()));
+ CObjectInt64* interface_index =
+ new CObjectInt64(CObject::NewInt64(interface->interface_index()));
entry->SetAt(4, interface_index);
array->SetAt(i + 1, entry);
@@ -795,9 +771,8 @@ void FUNCTION_NAME(Socket_GetOption)(Dart_NativeArguments args) {
intptr_t socket =
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
int64_t option = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
- intptr_t protocol =
- static_cast<intptr_t>(
- DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)));
+ intptr_t protocol = static_cast<intptr_t>(
+ DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)));
bool ok = false;
switch (option) {
case 0: { // TCP_NODELAY.
@@ -853,8 +828,7 @@ void FUNCTION_NAME(Socket_SetOption)(Dart_NativeArguments args) {
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
int64_t option = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
int64_t protocol = DartUtils::GetInt64ValueCheckRange(
- Dart_GetNativeArgument(args, 2),
- SocketAddress::TYPE_IPV4,
+ Dart_GetNativeArgument(args, 2), SocketAddress::TYPE_IPV4,
SocketAddress::TYPE_IPV6);
switch (option) {
case 0: // TCP_NODELAY.
@@ -863,14 +837,12 @@ void FUNCTION_NAME(Socket_SetOption)(Dart_NativeArguments args) {
break;
case 1: // IP_MULTICAST_LOOP.
result = Socket::SetMulticastLoop(
- socket,
- protocol,
+ socket, protocol,
DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)));
break;
case 2: // IP_MULTICAST_TTL.
result = Socket::SetMulticastHops(
- socket,
- protocol,
+ socket, protocol,
DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)));
break;
case 3: { // IP_MULTICAST_IF.
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698