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

Side by Side Diff: tests/standalone/src/EchoServerTest.dart

Issue 8726031: Change handling of accepting socket connections (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
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 // 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
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ReceivePort _receivePort; 123 ReceivePort _receivePort;
124 SendPort _sendPort; 124 SendPort _sendPort;
125 List<int> _buffer; 125 List<int> _buffer;
126 int _messages; 126 int _messages;
127 } 127 }
128 128
129 class EchoServer extends TestingServer { 129 class EchoServer extends TestingServer {
130 130
131 static final msgSize = EchoServerGame.MSGSIZE; 131 static final msgSize = EchoServerGame.MSGSIZE;
132 132
133 void connectionHandler() { 133 void connectionHandler(Socket connection) {
134 Socket _client;
135 134
136 void messageHandler() { 135 void messageHandler() {
137 136
138 List<int> buffer = new List<int>(msgSize); 137 List<int> buffer = new List<int>(msgSize);
139 int bytesRead = 0; 138 int bytesRead = 0;
140 139
141 void handleRead() { 140 void handleRead() {
142 int read = _client.readList(buffer, bytesRead, msgSize - bytesRead); 141 int read = connection.readList(buffer, bytesRead, msgSize - bytesRead);
143 if (read > 0) { 142 if (read > 0) {
144 bytesRead += read; 143 bytesRead += read;
145 if (bytesRead < msgSize) { 144 if (bytesRead < msgSize) {
146 // We check every time the whole buffer to verify data integrity. 145 // We check every time the whole buffer to verify data integrity.
147 for (int i = 0; i < bytesRead; i++) { 146 for (int i = 0; i < bytesRead; i++) {
148 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); 147 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
149 } 148 }
150 _client.dataHandler = handleRead; 149 connection.dataHandler = handleRead;
151 } else { 150 } else {
152 // We check every time the whole buffer to verify data integrity. 151 // We check every time the whole buffer to verify data integrity.
153 for (int i = 0; i < msgSize; i++) { 152 for (int i = 0; i < msgSize; i++) {
154 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); 153 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
155 } 154 }
156 155
157 void writeMessage() { 156 void writeMessage() {
158 157
159 int bytesWritten = 0; 158 int bytesWritten = 0;
160 159
161 void handleWrite() { 160 void handleWrite() {
162 int written = _client.writeList( 161 int written = connection.writeList(
163 buffer, bytesWritten, msgSize - bytesWritten); 162 buffer, bytesWritten, msgSize - bytesWritten);
164 bytesWritten += written; 163 bytesWritten += written;
165 if (bytesWritten < msgSize) { 164 if (bytesWritten < msgSize) {
166 _client.writeHandler = handleWrite; 165 connection.writeHandler = handleWrite;
167 } else { 166 } else {
168 _client.close(true); 167 connection.close(true);
169 } 168 }
170 } 169 }
171 handleWrite(); 170 handleWrite();
172 } 171 }
173 writeMessage(); 172 writeMessage();
174 } 173 }
175 } 174 }
176 } 175 }
177 176
178 handleRead(); 177 handleRead();
179 } 178 }
180 179
181 void closeHandler() { 180 void closeHandler() {
182 _client.close(); 181 connection.close();
183 } 182 }
184 183
185 void errorHandler() { 184 void errorHandler() {
186 Expect.fail("Socket error"); 185 Expect.fail("Socket error");
187 } 186 }
188 187
189 _client = _server.accept(); 188 connection.dataHandler = messageHandler;
190 _client.dataHandler = messageHandler; 189 connection.closeHandler = closeHandler;
191 _client.closeHandler = closeHandler; 190 connection.errorHandler = errorHandler;
192 _client.errorHandler = errorHandler;
193 } 191 }
194 } 192 }
195 193
196 main() { 194 main() {
197 EchoServerTest.testMain(); 195 EchoServerTest.testMain();
198 } 196 }
OLDNEW
« no previous file with comments | « tests/standalone/src/EchoServerStreamTest.dart ('k') | tests/standalone/src/SocketCloseTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698