OLD | NEW |
---|---|
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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 #import("dart:io"); | 10 #import("dart:io"); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 // 3. Creates a temp file. | 61 // 3. Creates a temp file. |
62 // 4. Pipes the socket output stream to the temp file. | 62 // 4. Pipes the socket output stream to the temp file. |
63 // 5. Expects the original file and the temp file to be equal. | 63 // 5. Expects the original file and the temp file to be equal. |
64 class PipeServerGame { | 64 class PipeServerGame { |
65 int count = 0; | 65 int count = 0; |
66 | 66 |
67 PipeServerGame.start() | 67 PipeServerGame.start() |
68 : _receivePort = new ReceivePort(), | 68 : _receivePort = new ReceivePort(), |
69 _sendPort = null, | 69 _sendPort = null, |
70 _messages = 0 { | 70 _messages = 0 { |
71 new PipeServer().spawn().then((SendPort port) { | 71 _sendPort = spawnFunction(startPipeServer); |
72 _sendPort = port; | 72 start(); |
73 start(); | |
74 }); | |
75 } | 73 } |
76 | 74 |
77 void runTest() { | 75 void runTest() { |
78 | 76 |
79 void connectHandler() { | 77 void connectHandler() { |
80 String srcFileName = | 78 String srcFileName = |
81 getDataFilename("tests/standalone/io/readline_test1.dat"); | 79 getDataFilename("tests/standalone/io/readline_test1.dat"); |
82 | 80 |
83 SocketOutputStream socketOutput = _socket.outputStream; | 81 SocketOutputStream socketOutput = _socket.outputStream; |
84 InputStream fileInput = new File(srcFileName).openInputStream(); | 82 InputStream fileInput = new File(srcFileName).openInputStream(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 } | 138 } |
141 | 139 |
142 int _port; | 140 int _port; |
143 ReceivePort _receivePort; | 141 ReceivePort _receivePort; |
144 SendPort _sendPort; | 142 SendPort _sendPort; |
145 Socket _socket; | 143 Socket _socket; |
146 int _messages; | 144 int _messages; |
147 } | 145 } |
148 | 146 |
149 | 147 |
148 void startPipeServer() { | |
149 var server = new PipeServer(); | |
150 port.receive((message, replyTo) { | |
151 server.dispatch(message, replyTo); | |
kasperl
2012/08/03 05:20:27
!
| |
152 }); | |
153 } | |
154 | |
155 | |
150 // The testing server will simply pipe each connecting sockets input | 156 // The testing server will simply pipe each connecting sockets input |
151 // stream to its output stream. | 157 // stream to its output stream. |
152 class PipeServer extends TestingServer { | 158 class PipeServer extends TestingServer { |
153 void onConnection(Socket connection) { | 159 void onConnection(Socket connection) { |
154 connection.onError = (Exception e) { Expect.fail("Socket error $e"); }; | 160 connection.onError = (Exception e) { Expect.fail("Socket error $e"); }; |
155 connection.inputStream.pipe(connection.outputStream); | 161 connection.inputStream.pipe(connection.outputStream); |
156 } | 162 } |
157 } | 163 } |
158 | 164 |
159 | 165 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 srcStream.pipe(dstStream, close: false); | 287 srcStream.pipe(dstStream, close: false); |
282 } | 288 } |
283 | 289 |
284 | 290 |
285 main() { | 291 main() { |
286 testFileToFilePipe1(); | 292 testFileToFilePipe1(); |
287 testFileToFilePipe2(); | 293 testFileToFilePipe2(); |
288 testFileToFilePipe3(); | 294 testFileToFilePipe3(); |
289 PipeServerGame echoServerGame = new PipeServerGame.start(); | 295 PipeServerGame echoServerGame = new PipeServerGame.start(); |
290 } | 296 } |
OLD | NEW |