Index: mojo/public/platform/dart/mojo_natives.cc |
diff --git a/mojo/public/platform/dart/mojo_natives.cc b/mojo/public/platform/dart/mojo_natives.cc |
index 8739db4034b7fc39a619534d8d9f988ec9327bd8..8bde166ce1d21a5e83832e3a49ffd7418f47e99b 100644 |
--- a/mojo/public/platform/dart/mojo_natives.cc |
+++ b/mojo/public/platform/dart/mojo_natives.cc |
@@ -37,6 +37,7 @@ namespace dart { |
V(MojoMessagePipe_Create, 1) \ |
V(MojoMessagePipe_Write, 5) \ |
V(MojoMessagePipe_Read, 5) \ |
+ V(MojoMessagePipe_QueryAndRead, 5) \ |
V(Mojo_GetTimeTicksNow, 0) \ |
V(MojoHandle_Close, 1) \ |
V(MojoHandle_Wait, 3) \ |
@@ -718,6 +719,93 @@ void MojoMessagePipe_Read(Dart_NativeArguments arguments) { |
Dart_SetReturnValue(arguments, list); |
} |
+void MojoMessagePipe_QueryAndRead(Dart_NativeArguments arguments) { |
+ Dart_Handle err; |
+ int64_t dart_handle; |
+ int64_t flags = 0; |
+ CHECK_INTEGER_ARGUMENT(arguments, 0, &dart_handle, Null); |
+ CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null); |
+ |
+ Dart_Handle data = Dart_GetNativeArgument(arguments, 2); |
+ Dart_Handle handles = Dart_GetNativeArgument(arguments, 3); |
+ Dart_Handle result = Dart_GetNativeArgument(arguments, 4); |
+ |
+ // 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_ListSetAt(result, 0, Dart_NewInteger(res)); |
+ Dart_ListSetAt(result, 1, data); |
+ Dart_ListSetAt(result, 2, handles); |
+ Dart_ListSetAt(result, 3, Dart_NewInteger(0)); |
+ Dart_ListSetAt(result, 4, Dart_NewInteger(0)); |
+ return; |
+ } |
+ |
+ Dart_TypedData_Type typ; |
+ void* bytes = nullptr; |
+ intptr_t bytes_len = 0; |
+ if ((blen > 0) && Dart_IsNull(data)) { |
+ data = Dart_NewTypedData(Dart_TypedData_kByteData, blen); |
Cutch
2015/11/06 21:59:15
Make this external to avoid a copy at every acquir
zra
2015/11/06 23:35:42
Done.
|
+ } else if (blen > 0) { |
+ err = Dart_TypedDataAcquireData(data, &typ, &bytes, &bytes_len); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ err = Dart_TypedDataReleaseData(data); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ if (static_cast<uintptr_t>(bytes_len) < blen) { |
+ data = Dart_NewTypedData(Dart_TypedData_kByteData, blen); |
+ } |
+ } |
+ |
+ void* handle_bytes = nullptr; |
+ intptr_t handles_len = 0; |
+ if ((hlen > 0) && Dart_IsNull(handles)) { |
+ handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen); |
Cutch
2015/11/06 21:59:15
Make this external to avoid a copy at every acquir
zra
2015/11/06 23:35:42
Done.
|
+ } else if (hlen > 0) { |
+ err = Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handles_len); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ err = Dart_TypedDataReleaseData(handles); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ if (static_cast<uintptr_t>(handles_len) < hlen) { |
+ handles = Dart_NewTypedData(Dart_TypedData_kUint32, hlen); |
+ } |
+ } |
+ |
+ if (blen > 0) { |
+ err = Dart_TypedDataAcquireData(data, &typ, &bytes, &bytes_len); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ } |
+ |
+ if (hlen > 0) { |
+ err = Dart_TypedDataAcquireData(handles, &typ, &handle_bytes, &handles_len); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ } |
+ |
+ res = MojoReadMessage(static_cast<MojoHandle>(dart_handle), bytes, &blen, |
+ reinterpret_cast<MojoHandle*>(handle_bytes), &hlen, |
+ static_cast<MojoReadMessageFlags>(flags)); |
+ |
+ if (blen > 0) { |
+ err = Dart_TypedDataReleaseData(data); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ } |
+ |
+ if (hlen > 0) { |
+ err = Dart_TypedDataReleaseData(handles); |
+ MOJO_DCHECK(!Dart_IsError(err)); |
+ } |
+ |
+ Dart_ListSetAt(result, 0, Dart_NewInteger(res)); |
+ Dart_ListSetAt(result, 1, data); |
+ Dart_ListSetAt(result, 2, handles); |
+ Dart_ListSetAt(result, 3, Dart_NewInteger(blen)); |
+ Dart_ListSetAt(result, 4, Dart_NewInteger(hlen)); |
+} |
+ |
struct MojoWaitManyState { |
MojoWaitManyState() {} |