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

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 48113028: Don't close the _FileStream until all operations are done. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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 part of dart.io; 5 part of dart.io;
6 6
7 // Read the file in blocks of size 64k. 7 // Read the file in blocks of size 64k.
8 const int _BLOCK_SIZE = 64 * 1024; 8 const int _BLOCK_SIZE = 64 * 1024;
9 9
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Don't start a new read if one is already in progress. 83 // Don't start a new read if one is already in progress.
84 if (_readInProgress) return; 84 if (_readInProgress) return;
85 _readInProgress = true; 85 _readInProgress = true;
86 int readBytes = _BLOCK_SIZE; 86 int readBytes = _BLOCK_SIZE;
87 if (_end != null) { 87 if (_end != null) {
88 readBytes = min(readBytes, _end - _position); 88 readBytes = min(readBytes, _end - _position);
89 if (readBytes < 0) { 89 if (readBytes < 0) {
90 _readInProgress = false; 90 _readInProgress = false;
91 if (!_unsubscribed) { 91 if (!_unsubscribed) {
92 _controller.addError(new RangeError("Bad end position: $_end")); 92 _controller.addError(new RangeError("Bad end position: $_end"));
93 _closeFile().then((_) { _controller.close(); }); 93 _closeFile();
94 _unsubscribed = true; 94 _unsubscribed = true;
95 } 95 }
96 return; 96 return;
97 } 97 }
98 } 98 }
99 _openedFile.read(readBytes) 99 _openedFile.read(readBytes)
100 .whenComplete(() { 100 .whenComplete(() {
101 _readInProgress = false; 101 _readInProgress = false;
102 }) 102 })
103 .then((block) { 103 .then((block) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 _controller.addError(new RangeError("Bad start position: $_position")); 136 _controller.addError(new RangeError("Bad start position: $_position"));
137 _controller.close(); 137 _controller.close();
138 return; 138 return;
139 } 139 }
140 Future<RandomAccessFile> openFuture; 140 Future<RandomAccessFile> openFuture;
141 if (_path != null) { 141 if (_path != null) {
142 openFuture = new File(_path).open(mode: FileMode.READ); 142 openFuture = new File(_path).open(mode: FileMode.READ);
143 } else { 143 } else {
144 openFuture = new Future.value(_File._openStdioSync(0)); 144 openFuture = new Future.value(_File._openStdioSync(0));
145 } 145 }
146 _readInProgress = true;
146 openFuture 147 openFuture
147 .then((RandomAccessFile opened) { 148 .then((RandomAccessFile opened) {
148 _openedFile = opened; 149 _openedFile = opened;
149 if (_position > 0) { 150 if (_position > 0) {
150 return opened.setPosition(_position); 151 return opened.setPosition(_position);
151 } 152 }
152 }) 153 })
154 .whenComplete(() {
155 _readInProgress = false;
156 })
153 .then((_) => _readBlock()) 157 .then((_) => _readBlock())
154 .catchError((e) { 158 .catchError((e) {
155 _controller.addError(e); 159 _controller.addError(e);
156 _controller.close(); 160 _closeFile();
157 }); 161 });
158 } 162 }
159 163
160 void _resume() { 164 void _resume() {
161 _paused = false; 165 _paused = false;
162 if (_currentBlock != null) { 166 if (_currentBlock != null) {
163 _controller.add(_currentBlock); 167 _controller.add(_currentBlock);
164 _currentBlock = null; 168 _currentBlock = null;
165 } 169 }
166 // Resume reading unless we are already done. 170 // Resume reading unless we are already done.
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 873
870 void _checkAvailable() { 874 void _checkAvailable() {
871 if (_asyncDispatched) { 875 if (_asyncDispatched) {
872 throw new FileSystemException("An async operation is currently pending", p ath); 876 throw new FileSystemException("An async operation is currently pending", p ath);
873 } 877 }
874 if (closed) { 878 if (closed) {
875 throw new FileSystemException("File closed", path); 879 throw new FileSystemException("File closed", path);
876 } 880 }
877 } 881 }
878 } 882 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698