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

Side by Side Diff: runtime/bin/chunked_stream.dart

Issue 9474004: Make FileInputStream and FileOutputStream actually asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove accidental edit Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/file.dart » ('j') | runtime/bin/file_impl.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _ChunkedInputStream implements ChunkedInputStream { 5 class _ChunkedInputStream implements ChunkedInputStream {
6 _ChunkedInputStream(InputStream this._input, [int chunkSize]) 6 _ChunkedInputStream(InputStream this._input, [int chunkSize])
7 : _chunkSize = chunkSize, _bufferList = new _BufferList() { 7 : _chunkSize = chunkSize, _bufferList = new _BufferList() {
8 if (_chunkSize === null) { 8 if (_chunkSize === null) {
9 _chunkSize = 0; 9 _chunkSize = 0;
10 } 10 }
11 _input.closeHandler = _closeHandler; 11 _input.closeHandler = _closeHandler;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 void issueCloseCallback(Timer timer) { 104 void issueCloseCallback(Timer timer) {
105 _scheduledCloseCallback = null; 105 _scheduledCloseCallback = null;
106 if (!_closed) { 106 if (!_closed) {
107 if (_clientCloseHandler !== null) _clientCloseHandler(); 107 if (_clientCloseHandler !== null) _clientCloseHandler();
108 _closed = true; 108 _closed = true;
109 } 109 }
110 } 110 }
111 111
112 // Schedule data callback if enough data in buffer. 112 // Schedule data callback if enough data in buffer.
113 if ((_bufferList.length >=_chunkSize || 113 if ((_bufferList.length >= _chunkSize ||
114 (_bufferList.length > 0 && _inputClosed)) && 114 (_bufferList.length > 0 && _inputClosed)) &&
115 _clientDataHandler !== null && 115 _clientDataHandler !== null &&
116 _scheduledDataCallback == null) { 116 _scheduledDataCallback == null) {
117 _scheduledDataCallback = new Timer(issueDataCallback, 0); 117 _scheduledDataCallback = new Timer(issueDataCallback, 0);
118 } 118 }
119 119
120 // Schedule close callback if no more data and input is closed. 120 // Schedule close callback if no more data and input is closed.
121 if (_bufferList.length == 0 && 121 if (_bufferList.length == 0 &&
122 _inputClosed && 122 _inputClosed &&
123 !_closed && 123 !_closed &&
124 _scheduledCloseCallback == null) { 124 _scheduledCloseCallback == null) {
125 if (_scheduledDataCallback != null) {
Søren Gjesse 2012/02/28 07:40:25 Woops!
126 _scheduledDataCallback.cancel();
127 }
125 _scheduledCloseCallback = new Timer(issueCloseCallback, 0); 128 _scheduledCloseCallback = new Timer(issueCloseCallback, 0);
126 } 129 }
127 } 130 }
128 131
129 InputStream _input; 132 InputStream _input;
130 _BufferList _bufferList; 133 _BufferList _bufferList;
131 int _chunkSize; 134 int _chunkSize;
132 bool _inputClosed = false; // Is the underlying input stream closed? 135 bool _inputClosed = false; // Is the underlying input stream closed?
133 bool _closed = false; // Has the close handler been called?. 136 bool _closed = false; // Has the close handler been called?.
134 Timer _scheduledDataCallback; 137 Timer _scheduledDataCallback;
135 Timer _scheduledCloseCallback; 138 Timer _scheduledCloseCallback;
136 Function _clientDataHandler; 139 Function _clientDataHandler;
137 Function _clientCloseHandler; 140 Function _clientCloseHandler;
138 } 141 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/file.dart » ('j') | runtime/bin/file_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698