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

Side by Side Diff: runtime/bin/eventhandler.cc

Issue 2760293002: [dart:io] Adds a finalizer to _NativeSocket to avoid socket leaks (Closed)
Patch Set: Address comments Created 3 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/eventhandler.h ('k') | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "bin/eventhandler.h" 7 #include "bin/eventhandler.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 106
107 EventHandlerImplementation* EventHandler::delegate() { 107 EventHandlerImplementation* EventHandler::delegate() {
108 if (event_handler == NULL) { 108 if (event_handler == NULL) {
109 return NULL; 109 return NULL;
110 } 110 }
111 return &event_handler->delegate_; 111 return &event_handler->delegate_;
112 } 112 }
113 113
114 114
115 void EventHandler::SendFromNative(intptr_t id, Dart_Port port, int64_t data) {
116 event_handler->SendData(id, port, data);
117 }
118
119
115 /* 120 /*
116 * Send data to the EventHandler thread to register for a given instance 121 * Send data to the EventHandler thread to register for a given instance
117 * args[0] a ReceivePort args[1] with a notification event args[2]. 122 * args[0] a ReceivePort args[1] with a notification event args[2].
118 */ 123 */
119 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) { 124 void FUNCTION_NAME(EventHandler_SendData)(Dart_NativeArguments args) {
120 Dart_Handle sender = Dart_GetNativeArgument(args, 0);
121 intptr_t id;
122 if (Dart_IsNull(sender)) {
123 id = kTimerId;
124 } else {
125 id = Socket::GetSocketIdNativeField(sender);
126 }
127 // Get the id out of the send port. If the handle is not a send port 125 // Get the id out of the send port. If the handle is not a send port
128 // we will get an error and propagate that out. 126 // we will get an error and propagate that out.
129 Dart_Handle handle = Dart_GetNativeArgument(args, 1); 127 Dart_Handle handle = Dart_GetNativeArgument(args, 1);
130 Dart_Port dart_port; 128 Dart_Port dart_port;
131 handle = Dart_SendPortGetId(handle, &dart_port); 129 handle = Dart_SendPortGetId(handle, &dart_port);
132 if (Dart_IsError(handle)) { 130 if (Dart_IsError(handle)) {
133 Dart_PropagateError(handle); 131 Dart_PropagateError(handle);
134 UNREACHABLE(); 132 UNREACHABLE();
135 } 133 }
134 Dart_Handle sender = Dart_GetNativeArgument(args, 0);
135 intptr_t id;
136 if (Dart_IsNull(sender)) {
137 id = kTimerId;
138 } else {
139 Socket* socket = Socket::GetSocketIdNativeField(sender);
140 ASSERT(dart_port != ILLEGAL_PORT);
141 socket->set_port(dart_port);
142 socket->Retain(); // inc refcount before sending to the eventhandler.
143 id = reinterpret_cast<intptr_t>(socket);
144 }
136 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 145 int64_t data = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
137 event_handler->SendData(id, dart_port, data); 146 event_handler->SendData(id, dart_port, data);
138 } 147 }
139 148
140 149
141 void FUNCTION_NAME(EventHandler_TimerMillisecondClock)( 150 void FUNCTION_NAME(EventHandler_TimerMillisecondClock)(
142 Dart_NativeArguments args) { 151 Dart_NativeArguments args) {
143 int64_t now = TimerUtils::GetCurrentMonotonicMillis(); 152 int64_t now = TimerUtils::GetCurrentMonotonicMillis();
144 Dart_SetReturnValue(args, Dart_NewInteger(now)); 153 Dart_SetReturnValue(args, Dart_NewInteger(now));
145 } 154 }
146 155
147 } // namespace bin 156 } // namespace bin
148 } // namespace dart 157 } // namespace dart
149 158
150 #endif // !defined(DART_IO_DISABLED) 159 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler.h ('k') | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698