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

Unified Diff: runtime/bin/file_impl.dart

Issue 10533110: Make sure that _FileInputStream._fillBuffer is not entered again before it finishes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 5671f358949e1d2fd3990bbb461f8ab6f8559d8f..d53c35be6d5a9996a7e7d6db3417a939126ba5c2 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -4,7 +4,7 @@
class _FileInputStream extends _BaseDataInputStream implements InputStream {
_FileInputStream(String name)
- : _data = [],
+ : _data = const [],
_position = 0,
_filePosition = 0 {
var file = new File(name);
@@ -17,7 +17,7 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
}
_FileInputStream.fromStdio(int fd)
- : _data = [],
+ : _data = const [],
_position = 0,
_filePosition = 0 {
assert(fd == 0);
@@ -65,8 +65,14 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
_closeFile();
return;
}
+ // If there is currently a _fillBuffer call waiting on readList,
+ // let it fill the buffer instead of us.
+ if (_activeFillBufferCall) return;
+ _activeFillBufferCall = true;
if (_data.length != size) {
_data = new Uint8List(size);
+ // Maintain the invariant signalling that the buffer is empty.
+ _position = _data.length;
}
var future = _openedFile.readList(_data, 0, _data.length);
future.then((read) {
@@ -75,12 +81,18 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
_data = _data.getRange(0, read);
}
_position = 0;
+ _activeFillBufferCall = false;
if (_fileLength == _filePosition) {
_closeFile();
}
_checkScheduleCallbacks();
});
+ future.handleException((e) {
+ _activeFillBufferCall = false;
+ _reportError(e);
+ return true;
+ });
}
int available() {
@@ -103,7 +115,7 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
List<int> result;
if (_position == 0 && bytesToRead == _data.length) {
result = _data;
- _data = [];
+ _data = const [];
} else {
result = new Uint8List(bytesToRead);
result.setRange(0, bytesToRead, _data, _position);
@@ -121,7 +133,7 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
}
void _close() {
- _data = [];
+ _data = const [];
_position = 0;
_filePosition = 0;
_fileLength = 0;
@@ -135,6 +147,7 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
int _position;
int _filePosition;
int _fileLength;
+ bool _activeFillBufferCall = false;
}
« 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