OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 void onClosed() { | 48 void onClosed() { |
49 Expect.equals(MSGSIZE, offset); | 49 Expect.equals(MSGSIZE, offset); |
50 _messages++; | 50 _messages++; |
51 if (_messages < MESSAGES) { | 51 if (_messages < MESSAGES) { |
52 sendData(); | 52 sendData(); |
53 } else { | 53 } else { |
54 shutdown(); | 54 shutdown(); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void errorHandler(e) { | 58 void errorHandler(e, trace) { |
59 String msg = "Socket error $e"; | 59 String msg = "Socket error $e"; |
60 var trace = getAttachedStackTrace(e); | |
61 if (trace != null) msg += "\nStackTrace: $trace"; | 60 if (trace != null) msg += "\nStackTrace: $trace"; |
62 Expect.fail(msg); | 61 Expect.fail(msg); |
63 } | 62 } |
64 | 63 |
65 void connectHandler() { | 64 void connectHandler() { |
66 _socket.listen(onData, | 65 _socket.listen(onData, |
67 onError: errorHandler, | 66 onError: errorHandler, |
68 onDone: onClosed); | 67 onDone: onClosed); |
69 _socket.add(_buffer); | 68 _socket.add(_buffer); |
70 _socket.close(); | 69 _socket.close(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 for (int i = 0; i < offset; i++) { | 124 for (int i = 0; i < offset; i++) { |
126 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); | 125 Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]); |
127 } | 126 } |
128 if (offset == MSGSIZE) { | 127 if (offset == MSGSIZE) { |
129 connection.add(buffer); | 128 connection.add(buffer); |
130 connection.close(); | 129 connection.close(); |
131 } | 130 } |
132 } | 131 } |
133 } | 132 } |
134 | 133 |
135 void errorHandler(e) { | 134 void errorHandler(e, trace) { |
136 String msg = "Socket error $e"; | 135 String msg = "Socket error $e"; |
137 var trace = getAttachedStackTrace(e); | |
138 if (trace != null) msg += "\nStackTrace: $trace"; | 136 if (trace != null) msg += "\nStackTrace: $trace"; |
139 Expect.fail(msg); | 137 Expect.fail(msg); |
140 } | 138 } |
141 | 139 |
142 connection.listen(dataReceived, onError: errorHandler); | 140 connection.listen(dataReceived, onError: errorHandler); |
143 } | 141 } |
144 } | 142 } |
145 | 143 |
146 main() { | 144 main() { |
147 asyncStart(); | 145 asyncStart(); |
148 EchoServerGame echoServerGame = new EchoServerGame.start(); | 146 EchoServerGame echoServerGame = new EchoServerGame.start(); |
149 } | 147 } |
OLD | NEW |