| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 const int FILE_EXISTS = 0; |
| 6 const int FILE_CREATE = 1; |
| 7 const int FILE_DELETE = 2; |
| 8 const int FILE_RENAME = 3; |
| 9 const int FILE_OPEN = 4; |
| 10 const int FILE_RESOLVE_SYMBOLIC_LINKS = 5; |
| 11 const int FILE_CLOSE = 6; |
| 12 const int FILE_POSITION = 7; |
| 13 const int FILE_SET_POSITION = 8; |
| 14 const int FILE_TRUNCATE = 9; |
| 15 const int FILE_LENGTH = 10; |
| 16 const int FILE_LENGTH_FROM_PATH = 11; |
| 17 const int FILE_LAST_MODIFIED = 12; |
| 18 const int FILE_FLUSH = 13; |
| 19 const int FILE_READ_BYTE = 14; |
| 20 const int FILE_WRITE_BYTE = 15; |
| 21 const int FILE_READ = 16; |
| 22 const int FILE_READ_INTO = 17; |
| 23 const int FILE_WRITE_FROM = 18; |
| 24 const int FILE_CREATE_LINK = 19; |
| 25 const int FILE_DELETE_LINK = 20; |
| 26 const int FILE_RENAME_LINK = 21; |
| 27 const int FILE_LINK_TARGET = 22; |
| 28 const int FILE_TYPE = 23; |
| 29 const int FILE_IDENTICAL = 24; |
| 30 const int FILE_STAT = 25; |
| 31 const int SOCKET_LOOKUP = 26; |
| 32 const int SOCKET_LIST_INTERFACES = 27; |
| 33 const int SOCKET_REVERSE_LOOKUP = 28; |
| 34 const int DIRECTORY_CREATE = 29; |
| 35 const int DIRECTORY_DELETE = 30; |
| 36 const int DIRECTORY_EXISTS = 31; |
| 37 const int DIRECTORY_CREATE_TEMP = 32; |
| 38 const int DIRECTORY_LIST_START = 33; |
| 39 const int DIRECTORY_LIST_NEXT = 34; |
| 40 const int DIRECTORY_LIST_STOP = 35; |
| 41 const int DIRECTORY_RENAME = 36; |
| 42 const int SSL_PROCESS_FILTER = 37; |
| 43 |
| 44 class IOService { |
| 45 // Lazy initialize service ports, 32 per isolate. |
| 46 static const int _SERVICE_PORT_COUNT = 32; |
| 47 static List<SendPort> _servicePort = new List(_SERVICE_PORT_COUNT); |
| 48 static ReceivePort _receivePort; |
| 49 static SendPort _replyToPort; |
| 50 static Map<int, Completer> _messageMap = {}; |
| 51 static int _id = 0; |
| 52 |
| 53 static Future dispatch(int request, List data) { |
| 54 int id; |
| 55 do { |
| 56 id = _getNextId(); |
| 57 } while (_messageMap.containsKey(id)); |
| 58 int index = id % _SERVICE_PORT_COUNT; |
| 59 _initialize(index); |
| 60 var completer = new Completer(); |
| 61 _messageMap[id] = completer; |
| 62 _servicePort[index].send([id, request, data], _replyToPort); |
| 63 return completer.future; |
| 64 } |
| 65 |
| 66 static void _initialize(int index) { |
| 67 if (_servicePort[index] == null) { |
| 68 _servicePort[index] = _newServicePort(); |
| 69 } |
| 70 if (_receivePort == null) { |
| 71 _receivePort = new ReceivePort(); |
| 72 _replyToPort = _receivePort.toSendPort(); |
| 73 _receivePort.receive((data, _) { |
| 74 assert(data is List && data.length == 2); |
| 75 _messageMap.remove(data[0]).complete(data[1]); |
| 76 if (_messageMap.length == 0) { |
| 77 _id = 0; |
| 78 _receivePort.close(); |
| 79 _receivePort = null; |
| 80 } |
| 81 }); |
| 82 } |
| 83 } |
| 84 |
| 85 static int _getNextId() { |
| 86 if (_id == 0x7FFFFFFF) _id = 0; |
| 87 return _id++; |
| 88 } |
| 89 |
| 90 static SendPort _newServicePort() native "IOService_NewServicePort"; |
| 91 } |
| OLD | NEW |