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

Side by Side Diff: tests/standalone/src/EchoServerTest.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
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 // Echo server test program for testing sockets. 5 // Echo server test program for testing sockets.
6 // 6 //
7 // VMOptions= 7 // VMOptions=
8 // VMOptions=--short_socket_read 8 // VMOptions=--short_socket_read
9 // VMOptions=--short_socket_write 9 // VMOptions=--short_socket_write
10 // VMOptions=--short_socket_read --short_socket_write 10 // VMOptions=--short_socket_read --short_socket_write
11 11
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 int bytesRead = 0; 50 int bytesRead = 0;
51 51
52 void handleRead() { 52 void handleRead() {
53 bytesRead += _socket.readList( 53 bytesRead += _socket.readList(
54 bufferReceived, bytesRead, MSGSIZE - bytesRead); 54 bufferReceived, bytesRead, MSGSIZE - bytesRead);
55 if (bytesRead < MSGSIZE) { 55 if (bytesRead < MSGSIZE) {
56 // We check every time the whole buffer to verify data integrity. 56 // We check every time the whole buffer to verify data integrity.
57 for (int i = 0; i < bytesRead; i++) { 57 for (int i = 0; i < bytesRead; i++) {
58 Expect.equals(FIRSTCHAR + i, bufferReceived[i]); 58 Expect.equals(FIRSTCHAR + i, bufferReceived[i]);
59 } 59 }
60 _socket.dataHandler = handleRead; 60 _socket.onData = handleRead;
61 } else { 61 } else {
62 // We check every time the whole buffer to verify data integrity. 62 // We check every time the whole buffer to verify data integrity.
63 for (int i = 0; i < MSGSIZE; i++) { 63 for (int i = 0; i < MSGSIZE; i++) {
64 Expect.equals(FIRSTCHAR + i, bufferReceived[i]); 64 Expect.equals(FIRSTCHAR + i, bufferReceived[i]);
65 } 65 }
66 _messages++; 66 _messages++;
67 _socket.close(); 67 _socket.close();
68 if (_messages < MESSAGES) { 68 if (_messages < MESSAGES) {
69 sendData(); 69 sendData();
70 } else { 70 } else {
(...skipping 11 matching lines...) Expand all
82 82
83 void connectHandler() { 83 void connectHandler() {
84 84
85 void writeMessage() { 85 void writeMessage() {
86 int bytesWritten = 0; 86 int bytesWritten = 0;
87 87
88 void handleWrite() { 88 void handleWrite() {
89 bytesWritten += _socket.writeList( 89 bytesWritten += _socket.writeList(
90 _buffer, bytesWritten, MSGSIZE - bytesWritten); 90 _buffer, bytesWritten, MSGSIZE - bytesWritten);
91 if (bytesWritten < MSGSIZE) { 91 if (bytesWritten < MSGSIZE) {
92 _socket.writeHandler = handleWrite; 92 _socket.onWrite = handleWrite;
93 } 93 }
94 } 94 }
95 95
96 handleWrite(); 96 handleWrite();
97 } 97 }
98 98
99 _socket.dataHandler = messageHandler; 99 _socket.onData = messageHandler;
100 _socket.errorHandler = errorHandler; 100 _socket.onError = errorHandler;
101 writeMessage(); 101 writeMessage();
102 } 102 }
103 103
104 _socket = new Socket(TestingServer.HOST, _port); 104 _socket = new Socket(TestingServer.HOST, _port);
105 if (_socket !== null) { 105 if (_socket !== null) {
106 _socket.connectHandler = connectHandler; 106 _socket.onConnect = connectHandler;
107 } else { 107 } else {
108 Expect.fail("Socket creation failed"); 108 Expect.fail("Socket creation failed");
109 } 109 }
110 } 110 }
111 111
112 void start() { 112 void start() {
113 _receivePort.receive((var message, SendPort replyTo) { 113 _receivePort.receive((var message, SendPort replyTo) {
114 _port = message; 114 _port = message;
115 sendData(); 115 sendData();
116 }); 116 });
(...skipping 25 matching lines...) Expand all
142 142
143 void handleRead() { 143 void handleRead() {
144 int read = connection.readList(buffer, bytesRead, msgSize - bytesRead); 144 int read = connection.readList(buffer, bytesRead, msgSize - bytesRead);
145 if (read > 0) { 145 if (read > 0) {
146 bytesRead += read; 146 bytesRead += read;
147 if (bytesRead < msgSize) { 147 if (bytesRead < msgSize) {
148 // We check every time the whole buffer to verify data integrity. 148 // We check every time the whole buffer to verify data integrity.
149 for (int i = 0; i < bytesRead; i++) { 149 for (int i = 0; i < bytesRead; i++) {
150 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); 150 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
151 } 151 }
152 connection.dataHandler = handleRead; 152 connection.onData = handleRead;
153 } else { 153 } else {
154 // We check every time the whole buffer to verify data integrity. 154 // We check every time the whole buffer to verify data integrity.
155 for (int i = 0; i < msgSize; i++) { 155 for (int i = 0; i < msgSize; i++) {
156 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); 156 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
157 } 157 }
158 158
159 void writeMessage() { 159 void writeMessage() {
160 160
161 int bytesWritten = 0; 161 int bytesWritten = 0;
162 162
163 void handleWrite() { 163 void handleWrite() {
164 int written = connection.writeList( 164 int written = connection.writeList(
165 buffer, bytesWritten, msgSize - bytesWritten); 165 buffer, bytesWritten, msgSize - bytesWritten);
166 bytesWritten += written; 166 bytesWritten += written;
167 if (bytesWritten < msgSize) { 167 if (bytesWritten < msgSize) {
168 connection.writeHandler = handleWrite; 168 connection.onWrite = handleWrite;
169 } else { 169 } else {
170 connection.close(true); 170 connection.close(true);
171 } 171 }
172 } 172 }
173 handleWrite(); 173 handleWrite();
174 } 174 }
175 writeMessage(); 175 writeMessage();
176 } 176 }
177 } 177 }
178 } 178 }
179 179
180 handleRead(); 180 handleRead();
181 } 181 }
182 182
183 void closeHandler() { 183 void closeHandler() {
184 connection.close(); 184 connection.close();
185 } 185 }
186 186
187 void errorHandler() { 187 void errorHandler() {
188 Expect.fail("Socket error"); 188 Expect.fail("Socket error");
189 } 189 }
190 190
191 connection.dataHandler = messageHandler; 191 connection.onData = messageHandler;
192 connection.closeHandler = closeHandler; 192 connection.onClosed = closeHandler;
193 connection.errorHandler = errorHandler; 193 connection.onError = errorHandler;
194 } 194 }
195 } 195 }
196 196
197 main() { 197 main() {
198 EchoServerTest.testMain(); 198 EchoServerTest.testMain();
199 } 199 }
OLDNEW
« no previous file with comments | « tests/standalone/src/EchoServerStreamTest.dart ('k') | tests/standalone/src/FileInputStreamTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698