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

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

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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 | « frog/tests/frog/src/FrogServerTest.dart ('k') | runtime/bin/directory.dart » ('j') | 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) 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 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.onClosed = _onClosed;
12 } 12 }
13 13
14 List<int> read() { 14 List<int> read() {
15 if (_closed) return null; 15 if (_closed) return null;
16 var result = _bufferList.readBytes(_chunkSize); 16 var result = _bufferList.readBytes(_chunkSize);
17 if (result == null) { 17 if (result == null) {
18 _readData(); 18 _readData();
19 result = _bufferList.readBytes(_chunkSize); 19 result = _bufferList.readBytes(_chunkSize);
20 } 20 }
21 if (result == null && _inputClosed) { 21 if (result == null && _inputClosed) {
(...skipping 10 matching lines...) Expand all
32 int get chunkSize() => _chunkSize; 32 int get chunkSize() => _chunkSize;
33 33
34 void set chunkSize(int chunkSize) { 34 void set chunkSize(int chunkSize) {
35 _chunkSize = chunkSize; 35 _chunkSize = chunkSize;
36 _checkInstallDataHandler(); 36 _checkInstallDataHandler();
37 _checkScheduleCallback(); 37 _checkScheduleCallback();
38 } 38 }
39 39
40 bool get closed() => _closed; 40 bool get closed() => _closed;
41 41
42 void set dataHandler(void callback()) { 42 void set onData(void callback()) {
43 _clientDataHandler = callback; 43 _clientDataHandler = callback;
44 _checkInstallDataHandler(); 44 _checkInstallDataHandler();
45 } 45 }
46 46
47 void set closeHandler(void callback()) { 47 void set onClosed(void callback()) {
48 _clientCloseHandler = callback; 48 _clientCloseHandler = callback;
49 } 49 }
50 50
51 void set errorHandler(void callback()) { 51 void set onError(void callback()) {
52 _input.errorHandler = callback; 52 _input.onError = callback;
53 } 53 }
54 54
55 void _dataHandler() { 55 void _onData() {
56 _readData(); 56 _readData();
57 if (_bufferList.length >= _chunkSize && _clientDataHandler !== null) { 57 if (_bufferList.length >= _chunkSize && _clientDataHandler !== null) {
58 _clientDataHandler(); 58 _clientDataHandler();
59 } 59 }
60 _checkScheduleCallback(); 60 _checkScheduleCallback();
61 _checkInstallDataHandler(); 61 _checkInstallDataHandler();
62 } 62 }
63 63
64 void _readData() { 64 void _readData() {
65 List<int> data = _input.read(); 65 List<int> data = _input.read();
66 if (data !== null) { 66 if (data !== null) {
67 _bufferList.add(data); 67 _bufferList.add(data);
68 } 68 }
69 } 69 }
70 70
71 void _closeHandler() { 71 void _onClosed() {
72 _inputClosed = true; 72 _inputClosed = true;
73 if (_bufferList.length == 0 && _clientCloseHandler !== null) { 73 if (_bufferList.length == 0 && _clientCloseHandler !== null) {
74 _clientCloseHandler(); 74 _clientCloseHandler();
75 _closed = true; 75 _closed = true;
76 } else { 76 } else {
77 _checkScheduleCallback(); 77 _checkScheduleCallback();
78 } 78 }
79 } 79 }
80 80
81 void _checkInstallDataHandler() { 81 void _checkInstallDataHandler() {
82 if (_clientDataHandler === null) { 82 if (_clientDataHandler === null) {
83 _input.dataHandler = null; 83 _input.onData = null;
84 } else { 84 } else {
85 if (_bufferList.length < _chunkSize && !_inputClosed) { 85 if (_bufferList.length < _chunkSize && !_inputClosed) {
86 _input.dataHandler = _dataHandler; 86 _input.onData = _onData;
87 } else { 87 } else {
88 _input.dataHandler = null; 88 _input.onData = null;
89 } 89 }
90 } 90 }
91 } 91 }
92 92
93 void _checkScheduleCallback() { 93 void _checkScheduleCallback() {
94 // TODO(sgjesse): Find a better way of scheduling callbacks from 94 // TODO(sgjesse): Find a better way of scheduling callbacks from
95 // the event loop. 95 // the event loop.
96 void issueDataCallback(Timer timer) { 96 void issueDataCallback(Timer timer) {
97 _scheduledDataCallback = null; 97 _scheduledDataCallback = null;
98 if (_clientDataHandler !== null) { 98 if (_clientDataHandler !== null) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 InputStream _input; 132 InputStream _input;
133 _BufferList _bufferList; 133 _BufferList _bufferList;
134 int _chunkSize; 134 int _chunkSize;
135 bool _inputClosed = false; // Is the underlying input stream closed? 135 bool _inputClosed = false; // Is the underlying input stream closed?
136 bool _closed = false; // Has the close handler been called?. 136 bool _closed = false; // Has the close handler been called?.
137 Timer _scheduledDataCallback; 137 Timer _scheduledDataCallback;
138 Timer _scheduledCloseCallback; 138 Timer _scheduledCloseCallback;
139 Function _clientDataHandler; 139 Function _clientDataHandler;
140 Function _clientCloseHandler; 140 Function _clientCloseHandler;
141 } 141 }
OLDNEW
« no previous file with comments | « frog/tests/frog/src/FrogServerTest.dart ('k') | runtime/bin/directory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698