| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 part of core; | |
| 6 | |
| 7 | |
| 8 class _MojoHandleNatives { | |
| 9 static int close(int handle) native "MojoHandle_Close"; | |
| 10 static int wait(int handle, int signals, int deadline) | |
| 11 native "MojoHandle_Wait"; | |
| 12 static int waitMany( | |
| 13 List handles, List signals, int num_handles, int deadline) | |
| 14 native "MojoHandle_WaitMany"; | |
| 15 } | |
| 16 | |
| 17 | |
| 18 class RawMojoHandle { | |
| 19 static const int INVALID = 0; | |
| 20 static const int DEADLINE_INDEFINITE = -1; | |
| 21 | |
| 22 RawMojoHandle(this.h); | |
| 23 | |
| 24 MojoResult close() { | |
| 25 int result = _MojoHandleNatives.close(h); | |
| 26 h = INVALID; | |
| 27 return new MojoResult(result); | |
| 28 } | |
| 29 | |
| 30 MojoResult wait(int signals, int deadline) { | |
| 31 int result = _MojoHandleNatives.wait(h, signals, deadline); | |
| 32 return new MojoResult(result); | |
| 33 } | |
| 34 | |
| 35 bool _ready(int signal) { | |
| 36 MojoResult res = wait(signal, 0); | |
| 37 switch (res) { | |
| 38 case MojoResult.OK: | |
| 39 return true; | |
| 40 case MojoResult.DEADLINE_EXCEEDED: | |
| 41 case MojoResult.CANCELLED: | |
| 42 case MojoResult.INVALID_ARGUMENT: | |
| 43 case MojoResult.FAILED_PRECONDITION: | |
| 44 return false; | |
| 45 default: | |
| 46 // Should be unreachable. | |
| 47 throw new Exception("Unreachable"); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 bool readyRead() => _ready(MojoHandleSignals.READABLE); | |
| 52 bool readyWrite() => _ready(MojoHandleSignals.WRITABLE); | |
| 53 | |
| 54 static MojoResult waitMany(List<int> handles, | |
| 55 List<int> signals, | |
| 56 int deadline) { | |
| 57 if (handles.length != signals.length) { | |
| 58 return MojoResult.INVALID_ARGUMENT; | |
| 59 } | |
| 60 int result = _MojoHandleNatives.waitMany( | |
| 61 handles, signals, handles.length, deadline); | |
| 62 return new MojoResult(result); | |
| 63 } | |
| 64 | |
| 65 static bool isValid(RawMojoHandle h) => (h.h != INVALID); | |
| 66 | |
| 67 int h; | |
| 68 } | |
| OLD | NEW |