| Index: sdk/lib/io/file_impl.dart
|
| diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
|
| index 8ed6c58b89b8b0d07327ac5c6c030bde19de9851..78c895dee39cd8c9c600d2193c9a9180dc94968f 100644
|
| --- a/sdk/lib/io/file_impl.dart
|
| +++ b/sdk/lib/io/file_impl.dart
|
| @@ -568,54 +568,42 @@ class _File extends FileSystemEntity implements File {
|
| class _RandomAccessFile
|
| extends Object with _ServiceObject
|
| implements RandomAccessFile {
|
| - // Use default Map so we keep order.
|
| - static Map<int, _RandomAccessFile> _files = new Map<int, _RandomAccessFile>();
|
| + static bool _connectedResourceHandler = false;
|
|
|
| final String path;
|
| int _id;
|
| bool _asyncDispatched = false;
|
| SendPort _fileService;
|
|
|
| - int _totalRead = 0;
|
| - int _totalWritten = 0;
|
| - int _readCount = 0;
|
| - int _writeCount = 0;
|
| -
|
| + _FileResourceInfo _resourceInfo;
|
|
|
| _RandomAccessFile(this._id, this.path) {
|
| - _files[_serviceId] = this;
|
| - }
|
| -
|
| - String get _serviceTypePath => 'io/file/randomaccessfiles';
|
| - String get _serviceTypeName => 'RandomAccessFile';
|
| -
|
| - Map _toJSON(bool ref) {
|
| - var r = {
|
| - 'id': _servicePath,
|
| - 'type': _serviceType(ref),
|
| - 'name': '$path',
|
| - 'user_name': '$path',
|
| - };
|
| - if (ref) {
|
| - return r;
|
| - }
|
| - r['asyncDispatched'] = _asyncDispatched;
|
| - r['fd'] = _getFD(_id);
|
| - r['totalRead'] = _totalRead;
|
| - r['totalWritten'] = _totalWritten;
|
| - r['readCount'] = _totalWritten;
|
| - r['writeCount'] = _writeCount;
|
| - return r;
|
| + _resourceInfo = new _FileResourceInfo(this);
|
| + _maybeConnectHandler();
|
| }
|
|
|
| void _maybePerformCleanup() {
|
| if (closed) {
|
| - _files.remove(_serviceId);
|
| + _FileResourceInfo.FileClosed(_resourceInfo);
|
| }
|
| }
|
|
|
| external static int _getFD(int id);
|
|
|
| + _maybeConnectHandler() {
|
| + if (!_connectedResourceHandler) {
|
| + // TODO(ricow): we probably need set these in some initialization code.
|
| + // We need to make sure that these are always awailable from the
|
| + // observatory even if no files (or sockets for the socket ones) are
|
| + // open.
|
| + registerExtension('__getOpenFiles',
|
| + _FileResourceInfo.getOpenFiles);
|
| + registerExtension('__getFileByID',
|
| + _FileResourceInfo.getFileInfoMapByID);
|
| + _connectedResourceHandler = true;
|
| + }
|
| + }
|
| +
|
| Future<RandomAccessFile> close() {
|
| return _dispatch(_FILE_CLOSE, [_id], markClosed: true).then((result) {
|
| if (result != -1) {
|
| @@ -645,8 +633,8 @@ class _RandomAccessFile
|
| if (_isErrorResponse(response)) {
|
| throw _exceptionFromResponse(response, "readByte failed", path);
|
| }
|
| - _readCount++;
|
| - _totalRead++;
|
| + _resourceInfo.readCount++;
|
| + _resourceInfo.totalRead++;
|
| return response;
|
| });
|
| }
|
| @@ -659,8 +647,8 @@ class _RandomAccessFile
|
| if (result is OSError) {
|
| throw new FileSystemException("readByte failed", path, result);
|
| }
|
| - _readCount++;
|
| - _totalRead++;
|
| + _resourceInfo.readCount++;
|
| + _resourceInfo.totalRead++;
|
| return result;
|
| }
|
|
|
| @@ -672,8 +660,8 @@ class _RandomAccessFile
|
| if (_isErrorResponse(response)) {
|
| throw _exceptionFromResponse(response, "read failed", path);
|
| }
|
| - _readCount++;
|
| - _totalRead += response[1].length;
|
| + _resourceInfo.readCount++;
|
| + _resourceInfo.totalRead += response[1].length;
|
| return response[1];
|
| });
|
| }
|
| @@ -689,8 +677,8 @@ class _RandomAccessFile
|
| if (result is OSError) {
|
| throw new FileSystemException("readSync failed", path, result);
|
| }
|
| - _readCount++;
|
| - _totalRead += result.length;
|
| + _resourceInfo.readCount++;
|
| + _resourceInfo.totalRead += result.length;
|
| return result;
|
| }
|
|
|
| @@ -710,8 +698,8 @@ class _RandomAccessFile
|
| var read = response[1];
|
| var data = response[2];
|
| buffer.setRange(start, start + read, data);
|
| - _readCount++;
|
| - _totalRead += read;
|
| + _resourceInfo.readCount++;
|
| + _resourceInfo.totalRead += read;
|
| return read;
|
| });
|
| }
|
| @@ -731,8 +719,8 @@ class _RandomAccessFile
|
| if (result is OSError) {
|
| throw new FileSystemException("readInto failed", path, result);
|
| }
|
| - _readCount++;
|
| - _totalRead += result;
|
| + _resourceInfo.readCount++;
|
| + _resourceInfo.totalRead += result;
|
| return result;
|
| }
|
|
|
| @@ -744,8 +732,8 @@ class _RandomAccessFile
|
| if (_isErrorResponse(response)) {
|
| throw _exceptionFromResponse(response, "writeByte failed", path);
|
| }
|
| - _writeCount++;
|
| - _totalWritten++;
|
| + _resourceInfo.writeCount++;
|
| + _resourceInfo.totalWritten++;
|
| return this;
|
| });
|
| }
|
| @@ -761,8 +749,8 @@ class _RandomAccessFile
|
| if (result is OSError) {
|
| throw new FileSystemException("writeByte failed", path, result);
|
| }
|
| - _writeCount++;
|
| - _totalWritten++;
|
| + _resourceInfo.writeCount++;
|
| + _resourceInfo.totalWritten++;
|
| return result;
|
| }
|
|
|
| @@ -791,8 +779,8 @@ class _RandomAccessFile
|
| if (_isErrorResponse(response)) {
|
| throw _exceptionFromResponse(response, "writeFrom failed", path);
|
| }
|
| - _writeCount++;
|
| - _totalWritten += end - (start - result.start);
|
| + _resourceInfo.writeCount++;
|
| + _resourceInfo.totalWritten += end - (start - result.start);
|
| return this;
|
| });
|
| }
|
| @@ -817,8 +805,8 @@ class _RandomAccessFile
|
| if (result is OSError) {
|
| throw new FileSystemException("writeFrom failed", path, result);
|
| }
|
| - _writeCount++;
|
| - _totalWritten += end - (start - bufferAndStart.start);
|
| + _resourceInfo.writeCount++;
|
| + _resourceInfo.totalWritten += end - (start - bufferAndStart.start);
|
| }
|
|
|
| Future<RandomAccessFile> writeString(String string,
|
|
|