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

Side by Side Diff: tests/standalone/io/echo_server_stream_test.dart

Issue 10837070: Remove old isolate API and update all code in the repository to use (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix namespace comment. Created 8 years, 4 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) 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 // Echo server test program to test socket streams. 5 // Echo server test program to test socket streams.
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
12 #import("dart:io"); 12 #import("dart:io");
13 #import("dart:isolate"); 13 #import("dart:isolate");
14 #source("testing_server.dart"); 14 #source("testing_server.dart");
15 15
16 class EchoServerGame { 16 class EchoServerGame {
17 17
18 static final MSGSIZE = 10; 18 static final MSGSIZE = 10;
19 static final MESSAGES = 100; 19 static final MESSAGES = 100;
20 static final FIRSTCHAR = 65; 20 static final FIRSTCHAR = 65;
21 21
22 EchoServerGame.start() 22 EchoServerGame.start()
23 : _receivePort = new ReceivePort(), 23 : _receivePort = new ReceivePort(),
24 _sendPort = null, 24 _sendPort = null,
25 _buffer = new List<int>(MSGSIZE), 25 _buffer = new List<int>(MSGSIZE),
26 _messages = 0 { 26 _messages = 0 {
27 for (int i = 0; i < MSGSIZE; i++) { 27 for (int i = 0; i < MSGSIZE; i++) {
28 _buffer[i] = FIRSTCHAR + i; 28 _buffer[i] = FIRSTCHAR + i;
29 } 29 }
30 new EchoServer().spawn().then((SendPort port) { 30 _sendPort = spawnFunction(startEchoServer);
31 _sendPort = port; 31 start();
32 start();
33 });
34 } 32 }
35 33
36 void sendData() { 34 void sendData() {
37 35
38 void errorHandler(Exception e) { 36 void errorHandler(Exception e) {
39 Expect.fail("Socket error $e"); 37 Expect.fail("Socket error $e");
40 } 38 }
41 39
42 void connectHandler() { 40 void connectHandler() {
43 41
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 126
129 int _port; 127 int _port;
130 ReceivePort _receivePort; 128 ReceivePort _receivePort;
131 SendPort _sendPort; 129 SendPort _sendPort;
132 Socket _socket; 130 Socket _socket;
133 List<int> _buffer; 131 List<int> _buffer;
134 int _messages; 132 int _messages;
135 } 133 }
136 134
137 135
136 void startEchoServer() {
137 var server = new EchoServer();
138 port.receive((message, SendPort replyTo) {
139 server.dispatch(message, replyTo);
140 });
141 }
142
143
138 class EchoServer extends TestingServer { 144 class EchoServer extends TestingServer {
139 145
140 static final int MSGSIZE = EchoServerGame.MSGSIZE; 146 static final int MSGSIZE = EchoServerGame.MSGSIZE;
141 147
142 void onConnection(Socket connection) { 148 void onConnection(Socket connection) {
143 InputStream inputStream; 149 InputStream inputStream;
144 List<int> buffer = new List<int>(MSGSIZE); 150 List<int> buffer = new List<int>(MSGSIZE);
145 int offset = 0; 151 int offset = 0;
146 152
147 void dataReceived() { 153 void dataReceived() {
(...skipping 19 matching lines...) Expand all
167 173
168 inputStream = connection.inputStream; 174 inputStream = connection.inputStream;
169 inputStream.onData = dataReceived; 175 inputStream.onData = dataReceived;
170 connection.onError = errorHandler; 176 connection.onError = errorHandler;
171 } 177 }
172 } 178 }
173 179
174 main() { 180 main() {
175 EchoServerGame echoServerGame = new EchoServerGame.start(); 181 EchoServerGame echoServerGame = new EchoServerGame.start();
176 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698