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 /** | 7 /** |
8 * Default implementation of [ListInputStream]. | 8 * Default implementation of [ListInputStream]. |
9 */ | 9 */ |
10 class _ListInputStream extends _BaseDataInputStream implements ListInputStream { | 10 class _ListInputStream extends _BaseDataInputStream implements ListInputStream { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 void set onClosed(void callback()) { | 93 void set onClosed(void callback()) { |
94 _clientCloseHandler = callback; | 94 _clientCloseHandler = callback; |
95 } | 95 } |
96 | 96 |
97 void set onError(void callback(e)) { | 97 void set onError(void callback(e)) { |
98 // No errors emitted. | 98 // No errors emitted. |
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 issueNoPendingWriteCallback(Timer timer) { | 110 void issueNoPendingWriteCallback() { |
111 _scheduledNoPendingWriteCallback = null; | 111 _scheduledNoPendingWriteCallback = null; |
112 if (_clientNoPendingWriteHandler != null && | 112 if (_clientNoPendingWriteHandler != null && |
113 !_streamMarkedClosed) { | 113 !_streamMarkedClosed) { |
114 _clientNoPendingWriteHandler(); | 114 _clientNoPendingWriteHandler(); |
115 _checkScheduleCallbacks(); | 115 _checkScheduleCallbacks(); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 void issueCloseCallback(Timer timer) { | 119 void issueCloseCallback() { |
120 _scheduledCloseCallback = null; | 120 _scheduledCloseCallback = null; |
121 if (_clientCloseHandler != null) _clientCloseHandler(); | 121 if (_clientCloseHandler != null) _clientCloseHandler(); |
122 } | 122 } |
123 | 123 |
124 // Schedule no pending callback if there is a callback set as this | 124 // Schedule no pending callback if there is a callback set as this |
125 // output stream does not wait for any transmission. Schedule | 125 // output stream does not wait for any transmission. Schedule |
126 // close callback once when the stream is closed. Only schedule a | 126 // close callback once when the stream is closed. Only schedule a |
127 // new callback if the previous one has actually been called. | 127 // new callback if the previous one has actually been called. |
128 if (_closeCallbackCalled) return; | 128 if (_closeCallbackCalled) return; |
129 | 129 |
130 if (!_streamMarkedClosed) { | 130 if (!_streamMarkedClosed) { |
131 if (!_bufferList.isEmpty && | 131 if (!_bufferList.isEmpty && |
132 _clientDataHandler != null && | 132 _clientDataHandler != null && |
133 _scheduledDataCallback == null) { | 133 _scheduledDataCallback == null) { |
134 _scheduledDataCallback = new Timer(0, issueDataCallback); | 134 _scheduledDataCallback = Timer.run(issueDataCallback); |
135 } | 135 } |
136 | 136 |
137 if (_clientNoPendingWriteHandler != null && | 137 if (_clientNoPendingWriteHandler != null && |
138 _scheduledNoPendingWriteCallback == null && | 138 _scheduledNoPendingWriteCallback == null && |
139 _scheduledDataCallback == null) { | 139 _scheduledDataCallback == null) { |
140 _scheduledNoPendingWriteCallback = | 140 _scheduledNoPendingWriteCallback = |
141 new Timer(0, issueNoPendingWriteCallback); | 141 Timer.run(issueNoPendingWriteCallback); |
142 } | 142 } |
143 | 143 |
144 } else if (_clientCloseHandler != null) { | 144 } else if (_clientCloseHandler != null) { |
145 _scheduledCloseCallback = new Timer(0, issueCloseCallback); | 145 _scheduledCloseCallback = Timer.run(issueCloseCallback); |
146 _closeCallbackCalled = true; | 146 _closeCallbackCalled = true; |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 bool get closed => _streamMarkedClosed; | 150 bool get closed => _streamMarkedClosed; |
151 | 151 |
152 _BufferList _bufferList; | 152 _BufferList _bufferList; |
153 bool _streamMarkedClosed = false; | 153 bool _streamMarkedClosed = false; |
154 bool _closeCallbackCalled = false; | 154 bool _closeCallbackCalled = false; |
155 Timer _scheduledDataCallback; | 155 Timer _scheduledDataCallback; |
156 Timer _scheduledNoPendingWriteCallback; | 156 Timer _scheduledNoPendingWriteCallback; |
157 Timer _scheduledCloseCallback; | 157 Timer _scheduledCloseCallback; |
158 Function _clientDataHandler; | 158 Function _clientDataHandler; |
159 Function _clientNoPendingWriteHandler; | 159 Function _clientNoPendingWriteHandler; |
160 Function _clientCloseHandler; | 160 Function _clientCloseHandler; |
161 } | 161 } |
OLD | NEW |