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

Unified Diff: mojo/dart/embedder/mojo_natives.cc

Issue 1405103002: Dart: Merge message pipe query and read into one native call. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 | « examples/dart/mojo_rtt_benchmark/lib/main.dart ('k') | mojo/public/dart/mojo/lib/src/codec.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/dart/embedder/mojo_natives.cc
diff --git a/mojo/dart/embedder/mojo_natives.cc b/mojo/dart/embedder/mojo_natives.cc
index cd9bbd303f4eb9c7c666f792faa81620990ce10c..984c054de7b25d526134b55b665e1e89483c2e11 100644
--- a/mojo/dart/embedder/mojo_natives.cc
+++ b/mojo/dart/embedder/mojo_natives.cc
@@ -34,6 +34,7 @@ namespace dart {
V(MojoMessagePipe_Create, 1) \
V(MojoMessagePipe_Write, 5) \
V(MojoMessagePipe_Read, 5) \
+ V(MojoMessagePipe_QueryAndRead, 2) \
V(Mojo_GetTimeTicksNow, 0) \
V(MojoHandle_Close, 1) \
V(MojoHandle_Wait, 3) \
@@ -736,6 +737,68 @@ struct MojoWaitManyState {
DISALLOW_COPY_AND_ASSIGN(MojoWaitManyState);
};
+void MojoMessagePipe_QueryAndRead(Dart_NativeArguments arguments) {
+ int64_t dart_handle;
+ int64_t flags = 0;
+ CHECK_INTEGER_ARGUMENT(arguments, 0, &dart_handle, Null);
+ CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null);
+
+ // Query the number of bytes and handles available.
+ uint32_t blen = 0;
+ uint32_t hlen = 0;
+ MojoResult res =
+ MojoReadMessage(static_cast<MojoHandle>(dart_handle), nullptr, &blen,
+ nullptr, &hlen, static_cast<MojoReadMessageFlags>(flags));
+
+ if ((res != MOJO_RESULT_OK) && (res != MOJO_RESULT_RESOURCE_EXHAUSTED)) {
+ Dart_Handle list = Dart_NewList(3);
+ Dart_ListSetAt(list, 0, Dart_NewInteger(res));
+ Dart_SetReturnValue(arguments, list);
+ return;
+ }
+
+ Dart_Handle data = Dart_Null();
+ if (blen > 0) {
+ data = Dart_NewTypedData(Dart_TypedData_kByteData, blen);
+ }
+
+ Dart_Handle handles = Dart_Null();
+ if (hlen > 0) {
+ handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen);
+ }
+
+ Dart_TypedData_Type typ;
+ void* bytes = nullptr;
+ intptr_t byte_data_len = 0;
+ if (blen > 0) {
+ Dart_TypedDataAcquireData(data, &typ, &bytes, &byte_data_len);
+ }
+
+ void* handle_bytes = nullptr;
+ intptr_t handle_bytes_len = 0;
+ if (hlen > 0) {
+ Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handle_bytes_len);
+ }
+
+ res = MojoReadMessage(static_cast<MojoHandle>(dart_handle), bytes, &blen,
+ reinterpret_cast<MojoHandle*>(handle_bytes), &hlen,
+ static_cast<MojoReadMessageFlags>(flags));
+
+ if (byte_data_len > 0) {
+ Dart_TypedDataReleaseData(data);
+ }
+
+ if (handle_bytes_len > 0) {
+ Dart_TypedDataReleaseData(handles);
+ }
+
+ Dart_Handle list = Dart_NewList(3);
+ Dart_ListSetAt(list, 0, Dart_NewInteger(res));
+ Dart_ListSetAt(list, 1, data);
+ Dart_ListSetAt(list, 2, handles);
+ Dart_SetReturnValue(arguments, list);
+}
+
// This global is safe because it is only accessed by the single handle watcher
// isolate. If multiple handle watcher isolates are ever needed, it will need
// to be replicated.
« no previous file with comments | « examples/dart/mojo_rtt_benchmark/lib/main.dart ('k') | mojo/public/dart/mojo/lib/src/codec.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698