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

Unified Diff: mojo/public/dart/src/handle.dart

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 | « mojo/public/dart/src/data_pipe.dart ('k') | mojo/public/dart/src/message_pipe.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/dart/src/handle.dart
diff --git a/mojo/public/dart/src/handle.dart b/mojo/public/dart/src/handle.dart
new file mode 100644
index 0000000000000000000000000000000000000000..08a23aeaaafdfdaf9df7d8d1aa30fe35ab0e2245
--- /dev/null
+++ b/mojo/public/dart/src/handle.dart
@@ -0,0 +1,68 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+part of core;
+
+
+class _MojoHandleNatives {
+ static int close(int handle) native "MojoHandle_Close";
+ static int wait(int handle, int signals, int deadline)
+ native "MojoHandle_Wait";
+ static int waitMany(
+ List handles, List signals, int num_handles, int deadline)
+ native "MojoHandle_WaitMany";
+}
+
+
+class RawMojoHandle {
+ static const int INVALID = 0;
+ static const int DEADLINE_INDEFINITE = -1;
+
+ RawMojoHandle(this.h);
+
+ MojoResult close() {
+ int result = _MojoHandleNatives.close(h);
+ h = INVALID;
+ return new MojoResult(result);
+ }
+
+ MojoResult wait(int signals, int deadline) {
+ int result = _MojoHandleNatives.wait(h, signals, deadline);
+ return new MojoResult(result);
+ }
+
+ bool _ready(int signal) {
+ MojoResult res = wait(signal, 0);
+ switch (res) {
+ case MojoResult.OK:
+ return true;
+ case MojoResult.DEADLINE_EXCEEDED:
+ case MojoResult.CANCELLED:
+ case MojoResult.INVALID_ARGUMENT:
+ case MojoResult.FAILED_PRECONDITION:
+ return false;
+ default:
+ // Should be unreachable.
+ throw new Exception("Unreachable");
+ }
+ }
+
+ bool readyRead() => _ready(MojoHandleSignals.READABLE);
+ bool readyWrite() => _ready(MojoHandleSignals.WRITABLE);
+
+ static MojoResult waitMany(List<int> handles,
+ List<int> signals,
+ int deadline) {
+ if (handles.length != signals.length) {
+ return MojoResult.INVALID_ARGUMENT;
+ }
+ int result = _MojoHandleNatives.waitMany(
+ handles, signals, handles.length, deadline);
+ return new MojoResult(result);
+ }
+
+ static bool isValid(RawMojoHandle h) => (h.h != INVALID);
+
+ int h;
+}
« no previous file with comments | « mojo/public/dart/src/data_pipe.dart ('k') | mojo/public/dart/src/message_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698