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

Unified Diff: runtime/bin/socket.cc

Issue 2791423002: [dart:io] Don't close stdin with a socket finalizer (Closed)
Patch Set: Address comments Created 3 years, 8 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.h ('k') | runtime/bin/socket_win.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 500252487edf67b8a9766a6683d96ae65d04b51b..a208613d07c1006e8c62db7236729fcac556a779 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -147,7 +147,7 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
// We set as a side-effect the file descriptor on the dart
// socket_object.
Socket::ReuseSocketIdNativeField(socket_object, os_socket->socketfd,
- true);
+ Socket::kFinalizerListening);
return Dart_True();
}
@@ -199,7 +199,8 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
InsertByFd(socketfd, os_socket);
// We set as a side-effect the port on the dart socket_object.
- Socket::ReuseSocketIdNativeField(socket_object, socketfd, true);
+ Socket::ReuseSocketIdNativeField(socket_object, socketfd,
+ Socket::kFinalizerListening);
return Dart_True();
}
@@ -305,7 +306,7 @@ void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) {
OSError error;
if (socket >= 0) {
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket,
- false);
+ Socket::kFinalizerNormal);
Dart_SetReturnValue(args, Dart_True());
} else {
Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error));
@@ -325,7 +326,7 @@ void FUNCTION_NAME(Socket_CreateBindConnect)(Dart_NativeArguments args) {
OSError error;
if (socket >= 0) {
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket,
- false);
+ Socket::kFinalizerNormal);
Dart_SetReturnValue(args, Dart_True());
} else {
Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error));
@@ -349,7 +350,7 @@ void FUNCTION_NAME(Socket_CreateBindDatagram)(Dart_NativeArguments args) {
intptr_t socket = Socket::CreateBindDatagram(addr, reuse_addr);
if (socket >= 0) {
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket,
- false);
+ Socket::kFinalizerNormal);
Dart_SetReturnValue(args, Dart_True());
} else {
OSError error;
@@ -628,7 +629,7 @@ void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) {
DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 1), 0, 2);
intptr_t socket = Socket::GetStdioHandle(num);
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket,
- false);
+ Socket::kFinalizerStdio);
Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0));
}
@@ -643,7 +644,8 @@ void FUNCTION_NAME(Socket_GetSocketId)(Dart_NativeArguments args) {
void FUNCTION_NAME(Socket_SetSocketId)(Dart_NativeArguments args) {
intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
- Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), id, false);
+ Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), id,
+ Socket::kFinalizerNormal);
}
@@ -671,7 +673,7 @@ void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) {
intptr_t new_socket = ServerSocket::Accept(socket->fd());
if (new_socket >= 0) {
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 1), new_socket,
- false);
+ Socket::kFinalizerNormal);
Dart_SetReturnValue(args, Dart_True());
} else if (new_socket == ServerSocket::kTemporaryFailure) {
Dart_SetReturnValue(args, Dart_False());
@@ -944,9 +946,9 @@ void FUNCTION_NAME(Socket_LeaveMulticast)(Dart_NativeArguments args) {
}
-static void SocketFinalizer(void* isolate_data,
- Dart_WeakPersistentHandle handle,
- void* data) {
+static void NormalSocketFinalizer(void* isolate_data,
+ Dart_WeakPersistentHandle handle,
+ void* data) {
Socket* socket = reinterpret_cast<Socket*>(data);
if (socket->fd() >= 0) {
const int64_t flags = 1 << kCloseCommand;
@@ -972,29 +974,53 @@ static void ListeningSocketFinalizer(void* isolate_data,
}
+static void StdioSocketFinalizer(void* isolate_data,
+ Dart_WeakPersistentHandle handle,
+ void* data) {
+ Socket* socket = reinterpret_cast<Socket*>(data);
+ if (socket->fd() >= 0) {
+ socket->SetClosedFd();
+ }
+ socket->Release();
+}
+
+
void Socket::ReuseSocketIdNativeField(Dart_Handle handle,
Socket* socket,
- bool listening) {
+ SocketFinalizer finalizer) {
Dart_Handle err = Dart_SetNativeInstanceField(
handle, kSocketIdNativeField, reinterpret_cast<intptr_t>(socket));
if (Dart_IsError(err)) {
Dart_PropagateError(err);
}
- if (listening) {
- Dart_NewWeakPersistentHandle(handle, reinterpret_cast<void*>(socket),
- sizeof(Socket), ListeningSocketFinalizer);
- } else {
+ Dart_WeakPersistentHandleFinalizer callback;
+ switch (finalizer) {
+ case kFinalizerNormal:
+ callback = NormalSocketFinalizer;
+ break;
+ case kFinalizerListening:
+ callback = ListeningSocketFinalizer;
+ break;
+ case kFinalizerStdio:
+ callback = StdioSocketFinalizer;
+ break;
+ default:
+ callback = NULL;
+ UNREACHABLE();
+ break;
+ }
+ if (callback != NULL) {
Dart_NewWeakPersistentHandle(handle, reinterpret_cast<void*>(socket),
- sizeof(Socket), SocketFinalizer);
+ sizeof(Socket), callback);
}
}
void Socket::SetSocketIdNativeField(Dart_Handle handle,
intptr_t id,
- bool listening) {
+ SocketFinalizer finalizer) {
Socket* socket = new Socket(id);
- ReuseSocketIdNativeField(handle, socket, listening);
+ ReuseSocketIdNativeField(handle, socket, finalizer);
}
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698