OLD | NEW |
1 // Copyright (c) 2012, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 abstract class _BaseDataInputStream { | 7 abstract class _BaseDataInputStream { |
8 int available(); | 8 int available(); |
9 | 9 |
10 List<int> read([int len]) { | 10 List<int> read([int len]) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 | 93 |
94 void _cancelScheduledDataCallback() { | 94 void _cancelScheduledDataCallback() { |
95 if (_scheduledDataCallback != null) { | 95 if (_scheduledDataCallback != null) { |
96 _scheduledDataCallback.cancel(); | 96 _scheduledDataCallback.cancel(); |
97 _scheduledDataCallback = null; | 97 _scheduledDataCallback = null; |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 void _checkScheduleCallbacks() { | 101 void _checkScheduleCallbacks() { |
102 void issueDataCallback(Timer timer) { | 102 void issueDataCallback() { |
103 _scheduledDataCallback = null; | 103 _scheduledDataCallback = null; |
104 if (_clientDataHandler != null) { | 104 if (_clientDataHandler != null) { |
105 _clientDataHandler(); | 105 _clientDataHandler(); |
106 _checkScheduleCallbacks(); | 106 _checkScheduleCallbacks(); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void issueCloseCallback(Timer timer) { | 110 void issueCloseCallback() { |
111 _scheduledCloseCallback = null; | 111 _scheduledCloseCallback = null; |
112 _closeCallbackCalled = true; | 112 _closeCallbackCalled = true; |
113 if (_clientCloseHandler != null) _clientCloseHandler(); | 113 if (_clientCloseHandler != null) _clientCloseHandler(); |
114 } | 114 } |
115 | 115 |
116 // Schedule data callback if there is more data to read. Schedule | 116 // Schedule data callback if there is more data to read. Schedule |
117 // close callback once when all data has been read. Only schedule | 117 // close callback once when all data has been read. Only schedule |
118 // a new callback if the previous one has actually been called. | 118 // a new callback if the previous one has actually been called. |
119 if (!_closeCallbackCalled) { | 119 if (!_closeCallbackCalled) { |
120 if (available() > 0) { | 120 if (available() > 0) { |
121 if (_scheduledDataCallback == null) { | 121 if (_scheduledDataCallback == null) { |
122 _scheduledDataCallback = new Timer(0, issueDataCallback); | 122 _scheduledDataCallback = Timer.run(issueDataCallback); |
123 } | 123 } |
124 } else if (_streamMarkedClosed && _scheduledCloseCallback == null) { | 124 } else if (_streamMarkedClosed && _scheduledCloseCallback == null) { |
125 _cancelScheduledDataCallback(); | 125 _cancelScheduledDataCallback(); |
126 _close(); | 126 _close(); |
127 _scheduledCloseCallback = new Timer(0, issueCloseCallback); | 127 _scheduledCloseCallback = Timer.run(issueCloseCallback); |
128 } | 128 } |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 // When this is set to true the stream is marked closed. When a | 132 // When this is set to true the stream is marked closed. When a |
133 // stream is marked closed no more data can arrive and the value | 133 // stream is marked closed no more data can arrive and the value |
134 // from available is now all remaining data. If this is true and the | 134 // from available is now all remaining data. If this is true and the |
135 // value of available is zero the close handler is called. | 135 // value of available is zero the close handler is called. |
136 bool _streamMarkedClosed = false; | 136 bool _streamMarkedClosed = false; |
137 | 137 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 void _reportError(e) { | 202 void _reportError(e) { |
203 if (_onError != null) { | 203 if (_onError != null) { |
204 _onError(e); | 204 _onError(e); |
205 } else { | 205 } else { |
206 throw e; | 206 throw e; |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 Function _onError; | 210 Function _onError; |
211 } | 211 } |
OLD | NEW |