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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 | 8 |
9 void sendData(List<int> data, int port) { | 9 void sendData(List<int> data, int port) { |
10 Socket socket = new Socket("127.0.0.1", port); | 10 Socket socket = new Socket("127.0.0.1", port); |
(...skipping 30 matching lines...) Expand all Loading... |
41 Expect.isFalse(calledOnError); | 41 Expect.isFalse(calledOnError); |
42 Expect.equals(exception, error.message); | 42 Expect.equals(exception, error.message); |
43 Expect.equals(expectRequest, calledOnRequest); | 43 Expect.equals(expectRequest, calledOnRequest); |
44 calledOnError = true; | 44 calledOnError = true; |
45 port.close(); | 45 port.close(); |
46 c.complete(null); | 46 c.complete(null); |
47 }; | 47 }; |
48 | 48 |
49 List<int> d; | 49 List<int> d; |
50 if (data is List<int>) d = data; | 50 if (data is List<int>) d = data; |
51 if (data is String) d = data.charCodes; | 51 if (data is String) d = data.codeUnits; |
52 if (d == null) Expect.fail("Invalid data"); | 52 if (d == null) Expect.fail("Invalid data"); |
53 sendData(d, server.port); | 53 sendData(d, server.port); |
54 | 54 |
55 return c.future; | 55 return c.future; |
56 } | 56 } |
57 | 57 |
58 final data; | 58 final data; |
59 final String exception; | 59 final String exception; |
60 final bool expectRequest; | 60 final bool expectRequest; |
61 } | 61 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 server.defaultRequestHandler = (request, response) { | 102 server.defaultRequestHandler = (request, response) { |
103 String name = new Options().script; | 103 String name = new Options().script; |
104 new File(name).openInputStream().pipe(response.outputStream); | 104 new File(name).openInputStream().pipe(response.outputStream); |
105 }; | 105 }; |
106 | 106 |
107 var count = 0; | 107 var count = 0; |
108 var makeRequest; | 108 var makeRequest; |
109 makeRequest = () { | 109 makeRequest = () { |
110 Socket socket = new Socket("127.0.0.1", server.port); | 110 Socket socket = new Socket("127.0.0.1", server.port); |
111 socket.onConnect = () { | 111 socket.onConnect = () { |
112 var data = "GET / HTTP/1.1\r\nContent-Length: 0\r\n\r\n".charCodes; | 112 var data = "GET / HTTP/1.1\r\nContent-Length: 0\r\n\r\n".codeUnits; |
113 socket.writeList(data, 0, data.length); | 113 socket.writeList(data, 0, data.length); |
114 socket.close(); | 114 socket.close(); |
115 if (++count < 10) { | 115 if (++count < 10) { |
116 makeRequest(); | 116 makeRequest(); |
117 } else { | 117 } else { |
118 server.close(); | 118 server.close(); |
119 } | 119 } |
120 }; | 120 }; |
121 }; | 121 }; |
122 | 122 |
123 makeRequest(); | 123 makeRequest(); |
124 } | 124 } |
125 | 125 |
126 void main() { | 126 void main() { |
127 testEarlyClose1(); | 127 testEarlyClose1(); |
128 testEarlyClose2(); | 128 testEarlyClose2(); |
129 } | 129 } |
OLD | NEW |