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

Unified Diff: runtime/bin/io_service.cc

Issue 24395013: Merge services into a shared IOService in dart:io, and use a native port. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Finish off native_service Created 7 years, 3 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/io_service.h ('k') | runtime/bin/io_service_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/io_service.cc
diff --git a/runtime/bin/io_service.cc b/runtime/bin/io_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..922b98c14192a53e4e5ff4daa8a866294b8aadfd
--- /dev/null
+++ b/runtime/bin/io_service.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "bin/dartutils.h"
+#include "bin/directory.h"
+#include "bin/file.h"
+#include "bin/io_buffer.h"
+#include "bin/io_service.h"
+#include "bin/secure_socket.h"
+#include "bin/socket.h"
+#include "bin/thread.h"
+#include "bin/utils.h"
+
+#include "platform/globals.h"
+#include "platform/thread.h"
+#include "platform/utils.h"
+
+#include "include/dart_api.h"
+
+
+namespace dart {
+namespace bin {
+
+#define CASE_REQUEST(type, method, id) \
+ case IOService::k##type##method##Request: \
+ response = type::method##Request(data); \
+ break;
+
+void IOServiceCallback(Dart_Port dest_port_id,
+ Dart_Port reply_port_id,
+ Dart_CObject* message) {
+ CObject* response = CObject::IllegalArgumentError();
+ CObjectArray request(message);
+ if (message->type == Dart_CObject_kArray &&
+ request.Length() == 3 &&
+ request[0]->IsInt32() &&
+ request[1]->IsInt32() &&
+ request[2]->IsArray()) {
+ CObjectInt32 message_id(request[0]);
+ CObjectInt32 request_id(request[1]);
+ CObjectArray data(request[2]);
+ switch (request_id.Value()) {
+ IO_SERVICE_REQUEST_LIST(CASE_REQUEST);
+ default:
+ UNREACHABLE();
+ }
+ }
+
+ CObjectArray result(CObject::NewArray(2));
+ result.SetAt(0, request[0]);
+ result.SetAt(1, response);
+ Dart_PostCObject(reply_port_id, result.AsApiCObject());
+}
+
+
+Dart_Port IOService::GetServicePort() {
+ Dart_Port result = Dart_NewNativePort("IOService",
+ IOServiceCallback,
+ true);
+ return result;
+}
+
+
+void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) {
+ Dart_SetReturnValue(args, Dart_Null());
+ Dart_Port service_port = IOService::GetServicePort();
+ if (service_port != ILLEGAL_PORT) {
+ // Return a send port for the service port.
+ Dart_Handle send_port = Dart_NewSendPort(service_port);
+ Dart_SetReturnValue(args, send_port);
+ }
+}
+
+
+} // namespace bin
+} // namespace dart
+
« no previous file with comments | « runtime/bin/io_service.h ('k') | runtime/bin/io_service_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698