Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A multiplexing [RawReceivePort]. | 6 * A multiplexing [RawReceivePort]. |
| 7 * | 7 * |
| 8 * Allows creating a number of [RawReceivePort] implementations that all send | 8 * Allows creating a number of [RawReceivePort] implementations that all send |
| 9 * messages through the same real `RawReceivePort`. | 9 * messages through the same real `RawReceivePort`. |
| 10 * | 10 * |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 void set handler(void handler(response)) { | 39 void set handler(void handler(response)) { |
| 40 this._handler = handler; | 40 this._handler = handler; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void close() { | 43 void close() { |
| 44 _multiplexer._closePort(_id); | 44 _multiplexer._closePort(_id); |
| 45 } | 45 } |
| 46 | 46 |
| 47 SendPort get sendPort => _multiplexer._createSendPort(_id); | 47 SendPort get sendPort => _multiplexer._createSendPort(_id); |
| 48 | 48 |
| 49 void _invokeHandler(message) { _handler(message); } | 49 void _invokeHandler(message) { |
| 50 _handler(message); | |
| 51 } | |
| 50 } | 52 } |
| 51 | 53 |
| 52 class _MultiplexSendPort implements SendPort { | 54 class _MultiplexSendPort implements SendPort { |
| 53 final SendPort _sendPort; | 55 final SendPort _sendPort; |
| 54 final int _id; | 56 final int _id; |
| 55 _MultiplexSendPort(this._id, this._sendPort); | 57 _MultiplexSendPort(this._id, this._sendPort); |
| 56 | 58 |
| 57 void send(message) { | 59 void send(message) { |
| 58 _sendPort.send(list2(_id, message)); | 60 _sendPort.send(list2(_id, message)); |
| 59 } | 61 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 82 void close() { | 84 void close() { |
| 83 _port.close(); | 85 _port.close(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void _multiplexResponse(list) { | 88 void _multiplexResponse(list) { |
| 87 int id = list[0]; | 89 int id = list[0]; |
| 88 var message = list[1]; | 90 var message = list[1]; |
| 89 _MultiplexRawReceivePort receivePort = _map[id]; | 91 _MultiplexRawReceivePort receivePort = _map[id]; |
| 90 // If the receive port is closed, messages are dropped, just as for | 92 // If the receive port is closed, messages are dropped, just as for |
| 91 // the normal ReceivePort. | 93 // the normal ReceivePort. |
| 92 if (receivePort == null) return; // Port closed. | 94 if (receivePort == null) return; // Port closed. |
|
Lasse Reichstein Nielsen
2015/02/26 10:59:15
Two spaces before //.
| |
| 93 receivePort._invokeHandler(message); | 95 receivePort._invokeHandler(message); |
| 94 } | 96 } |
| 95 | 97 |
| 96 SendPort _createSendPort(int id) { | 98 SendPort _createSendPort(int id) { |
| 97 return new _MultiplexSendPort(id, _port.sendPort); | 99 return new _MultiplexSendPort(id, _port.sendPort); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void _closePort(int id) { | 102 void _closePort(int id) { |
| 101 _map.remove(id); | 103 _map.remove(id); |
| 102 } | 104 } |
| 103 } | 105 } |
| OLD | NEW |