mirror of
https://github.com/dart-lang/sdk
synced 2024-10-05 05:17:31 +00:00
Change the WebSocket implementation to use Socket.read instead of Socket.readList
This removes the need for Socket.available which is not implemented for SecureSocket. R=ager@google.com BUG= Review URL: https://codereview.chromium.org//11886038 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17047 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
707ab317cf
commit
947177049c
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
|
@ -62,9 +62,9 @@ class _WebSocketProtocolProcessor {
|
|||
/**
|
||||
* Process data received from the underlying communication channel.
|
||||
*/
|
||||
void update(List<int> buffer, int offset, int count) {
|
||||
int index = offset;
|
||||
int lastIndex = offset + count;
|
||||
void update(List<int> buffer) {
|
||||
int index = 0;
|
||||
int lastIndex = buffer.length;
|
||||
try {
|
||||
if (_state == CLOSED) {
|
||||
throw new WebSocketException("Data on closed connection");
|
||||
|
@ -375,13 +375,10 @@ class _WebSocketConnectionBase {
|
|||
processor.onPong = _onWebSocketPong;
|
||||
processor.onClosed = _onWebSocketClosed;
|
||||
if (unparsedData != null) {
|
||||
processor.update(unparsedData, 0, unparsedData.length);
|
||||
processor.update(unparsedData);
|
||||
}
|
||||
_socket.onData = () {
|
||||
int available = _socket.available();
|
||||
List<int> data = new List<int>.fixedLength(available);
|
||||
int read = _socket.readList(data, 0, available);
|
||||
processor.update(data, 0, read);
|
||||
processor.update(_socket.read());
|
||||
};
|
||||
_socket.onClosed = () {
|
||||
processor.closed();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
|
@ -107,7 +107,7 @@ void testFullMessages() {
|
|||
|
||||
// Update the processor with one big chunk.
|
||||
messageCount++;
|
||||
processor.update(frame, 0, frame.length);
|
||||
processor.update(frame);
|
||||
Expect.isNull(mc.data);
|
||||
Expect.equals(0, processor._state);
|
||||
|
||||
|
@ -116,7 +116,7 @@ void testFullMessages() {
|
|||
// Update the processor one byte at the time.
|
||||
messageCount++;
|
||||
for (int i = 0; i < frame.length; i++) {
|
||||
processor.update(frame, i, 1);
|
||||
processor.update(frame.getRange(i, 1));
|
||||
}
|
||||
Expect.equals(0, processor._state);
|
||||
Expect.isNull(mc.data);
|
||||
|
@ -124,7 +124,7 @@ void testFullMessages() {
|
|||
// Update the processor two bytes at the time.
|
||||
messageCount++;
|
||||
for (int i = 0; i < frame.length; i += 2) {
|
||||
processor.update(frame, i, i + 1 < frame.length ? 2 : 1);
|
||||
processor.update(frame.getRange(i, i + 1 < frame.length ? 2 : 1));
|
||||
}
|
||||
Expect.equals(0, processor._state);
|
||||
Expect.isNull(mc.data);
|
||||
|
@ -177,7 +177,7 @@ void testFragmentedMessages() {
|
|||
payloadSize);
|
||||
frameCount++;
|
||||
messageIndex += payloadSize;
|
||||
processor.update(frame, 0, frame.length);
|
||||
processor.update(frame);
|
||||
remaining -= payloadSize;
|
||||
firstFrame = false;
|
||||
}
|
||||
|
|
63
tests/standalone/io/web_socket_secure_test.dart
Normal file
63
tests/standalone/io/web_socket_secure_test.dart
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "dart:io";
|
||||
import "dart:uri";
|
||||
import "dart:isolate";
|
||||
|
||||
const SERVER_ADDRESS = "127.0.0.1";
|
||||
const HOST_NAME = "localhost";
|
||||
|
||||
void test() {
|
||||
HttpsServer server = new HttpsServer();
|
||||
var client = new HttpClient();
|
||||
|
||||
// Create a web socket handler and set is as the HTTP server default
|
||||
// handler.
|
||||
WebSocketHandler wsHandler = new WebSocketHandler();
|
||||
wsHandler.onOpen = (WebSocketConnection conn) {
|
||||
conn.onMessage = (Object message) => conn.send(message);
|
||||
conn.onClosed = (status, reason) {
|
||||
conn.close();
|
||||
server.close();
|
||||
client.shutdown();
|
||||
};
|
||||
};
|
||||
server.defaultRequestHandler = wsHandler.onRequest;
|
||||
|
||||
server.onError = (Exception e) {
|
||||
Expect.fail("Unexpected error in Https Server: $e");
|
||||
};
|
||||
|
||||
server.listen(SERVER_ADDRESS,
|
||||
0,
|
||||
backlog: 5,
|
||||
certificate_name: "CN=$HOST_NAME");
|
||||
|
||||
// Connect web socket over HTTPS.
|
||||
var conn = new WebSocketClientConnection(
|
||||
client.getUrl(
|
||||
new Uri.fromString("https://$HOST_NAME:${server.port}/")));
|
||||
conn.onOpen = () {
|
||||
conn.send("hello");
|
||||
};
|
||||
conn.onMessage = (msg) {
|
||||
Expect.equals("hello", msg);
|
||||
print(msg);
|
||||
conn.close();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void InitializeSSL() {
|
||||
var testPkcertDatabase =
|
||||
new Path(new Options().script).directoryPath.append("pkcert/");
|
||||
SecureSocket.initialize(database: testPkcertDatabase.toNativePath(),
|
||||
password: "dartdart");
|
||||
}
|
||||
|
||||
void main() {
|
||||
InitializeSSL();
|
||||
test();
|
||||
}
|
Loading…
Reference in a new issue