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

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

Issue 8839012: Only schedule one data callback at the time for chunked input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } else { 82 } else {
83 _input.dataHandler = null; 83 _input.dataHandler = null;
84 } 84 }
85 } 85 }
86 } 86 }
87 87
88 void _checkScheduleCallback() { 88 void _checkScheduleCallback() {
89 // TODO(sgjesse): Find a better way of scheduling callbacks from 89 // TODO(sgjesse): Find a better way of scheduling callbacks from
90 // the event loop. 90 // the event loop.
91 void issueDataCallback(Timer timer) { 91 void issueDataCallback(Timer timer) {
92 _scheduledDataCallback = null;
92 if (_clientDataHandler !== null) { 93 if (_clientDataHandler !== null) {
93 _clientDataHandler(); 94 _clientDataHandler();
94 _checkScheduleCallback(); 95 _checkScheduleCallback();
95 } 96 }
96 } 97 }
97 98
98 void issueCloseCallback(Timer timer) { 99 void issueCloseCallback(Timer timer) {
100 _scheduledCloseCallback = null;
99 if (!_closed) { 101 if (!_closed) {
100 if (_clientCloseHandler !== null) _clientCloseHandler(); 102 if (_clientCloseHandler !== null) _clientCloseHandler();
101 _closed = true; 103 _closed = true;
102 } 104 }
103 } 105 }
104 106
105 // Schedule data callback if enough data in buffer. 107 // Schedule data callback if enough data in buffer.
106 if ((_bufferList.length >=_chunkSize || 108 if ((_bufferList.length >=_chunkSize ||
107 (_bufferList.length > 0 && _inputClosed)) && 109 (_bufferList.length > 0 && _inputClosed)) &&
108 _clientDataHandler !== null) { 110 _clientDataHandler !== null &&
109 new Timer(issueDataCallback, 0, false); 111 _scheduledDataCallback == null) {
112 _scheduledDataCallback = new Timer(issueDataCallback, 0, false);
110 } 113 }
111 114
112 // Schedule close callback if no more data and input is closed. 115 // Schedule close callback if no more data and input is closed.
113 if (_bufferList.length == 0 && _inputClosed && !_closed) { 116 if (_bufferList.length == 0 &&
114 new Timer(issueCloseCallback, 0, false); 117 _inputClosed &&
118 !_closed &&
119 _scheduledCloseCallback == null) {
120 _scheduledCloseCallback = new Timer(issueCloseCallback, 0, false);
115 } 121 }
116 } 122 }
117 123
118 InputStream _input; 124 InputStream _input;
119 _BufferList _bufferList; 125 _BufferList _bufferList;
120 int _chunkSize; 126 int _chunkSize;
121 bool _inputClosed = false; // Is the underlying input stream closed? 127 bool _inputClosed = false; // Is the underlying input stream closed?
122 bool _closed = false; // Has the close handler been called?. 128 bool _closed = false; // Has the close handler been called?.
123 var _clientDataHandler; 129 Timer _scheduledDataCallback;
124 var _clientCloseHandler; 130 Timer _scheduledCloseCallback;
131 Function _clientDataHandler;
132 Function _clientCloseHandler;
125 } 133 }
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