Index: sdk/lib/io/websocket_impl.dart |
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart |
index d593b58558962d77187f304a90e267c8c2674921..18d1cf22bc2407a2bce1ea4461cc9431ddebe43d 100644 |
--- a/sdk/lib/io/websocket_impl.dart |
+++ b/sdk/lib/io/websocket_impl.dart |
@@ -50,7 +50,7 @@ class _CompressionMaxWindowBits { |
/** |
* The web socket protocol transformer handles the protocol byte stream |
- * which is supplied through the `handleData`. As the protocol is processed, |
+ * which is supplied through the [:handleData:]. As the protocol is processed, |
* it'll output frame data as either a List<int> or String. |
* |
* Important information about usage: Be sure you use cancelOnError, so the |
@@ -59,8 +59,7 @@ class _CompressionMaxWindowBits { |
*/ |
// TODO(ajohnsen): make this transformer reusable? |
class _WebSocketProtocolTransformer |
- implements EventSink<List<int>>, StreamTransformer< |
- List<int>, dynamic/*List<int>|_WebSocketPing|_WebSocketPong>*/> { |
+ implements StreamTransformer<List<int>, dynamic>, EventSink<Uint8List> { |
static const int START = 0; |
static const int LEN_FIRST = 1; |
static const int LEN_REST = 2; |
@@ -88,7 +87,7 @@ class _WebSocketProtocolTransformer |
int closeCode = WebSocketStatus.NO_STATUS_RECEIVED; |
String closeReason = ""; |
- EventSink<dynamic/*List<int>|_WebSocketPing|_WebSocketPong>*/> _eventSink; |
+ EventSink _eventSink; |
final bool _serverSide; |
final List _maskingBytes = new List(4); |
@@ -97,8 +96,7 @@ class _WebSocketProtocolTransformer |
_WebSocketPerMessageDeflate _deflate; |
_WebSocketProtocolTransformer([this._serverSide = false, this._deflate]); |
- Stream<dynamic/*List<int>|_WebSocketPing|_WebSocketPong>*/> bind( |
- Stream<List<int>> stream) { |
+ Stream bind(Stream stream) { |
return new Stream.eventTransformed(stream, (EventSink eventSink) { |
if (_eventSink != null) { |
throw new StateError("WebSocket transformer already used."); |
@@ -396,12 +394,10 @@ class _WebSocketPong { |
_WebSocketPong([this.payload = null]); |
} |
-typedef /*String|Future<String>*/ _ProtocolSelector(List<String> protocols); |
- |
class _WebSocketTransformerImpl implements WebSocketTransformer { |
final StreamController<WebSocket> _controller = |
new StreamController<WebSocket>(sync: true); |
- final _ProtocolSelector _protocolSelector; |
+ final Function _protocolSelector; |
final CompressionOptions _compression; |
_WebSocketTransformerImpl(this._protocolSelector, this._compression); |
@@ -418,8 +414,8 @@ class _WebSocketTransformerImpl implements WebSocketTransformer { |
return _controller.stream; |
} |
- static Future<WebSocket> _upgrade(HttpRequest request, |
- _ProtocolSelector _protocolSelector, CompressionOptions compression) { |
+ static Future<WebSocket> _upgrade( |
+ HttpRequest request, _protocolSelector, CompressionOptions compression) { |
var response = request.response; |
if (!_isUpgradeRequest(request)) { |
// Send error response. |
@@ -430,7 +426,7 @@ class _WebSocketTransformerImpl implements WebSocketTransformer { |
new WebSocketException("Invalid WebSocket upgrade request")); |
} |
- Future<WebSocket> upgrade(String protocol) { |
+ Future upgrade(String protocol) { |
// Send the upgrade response. |
response |
..statusCode = HttpStatus.SWITCHING_PROTOCOLS |
@@ -448,7 +444,7 @@ class _WebSocketTransformerImpl implements WebSocketTransformer { |
var deflate = _negotiateCompression(request, response, compression); |
response.headers.contentLength = 0; |
- return response.detachSocket().then/*<WebSocket>*/((socket) => |
+ return response.detachSocket().then((socket) => |
new _WebSocketImpl._fromSocket( |
socket, protocol, compression, true, deflate)); |
} |
@@ -459,8 +455,7 @@ class _WebSocketTransformerImpl implements WebSocketTransformer { |
// consisting of multiple protocols. To unify all of them, first join |
// the lists with ', ' and then tokenize. |
protocols = _HttpParser._tokenizeFieldValue(protocols.join(', ')); |
- return new Future<String>(() => _protocolSelector(protocols)) |
- .then/*<String>*/((protocol) { |
+ return new Future(() => _protocolSelector(protocols)).then((protocol) { |
if (protocols.indexOf(protocol) < 0) { |
throw new WebSocketException( |
"Selected protocol is not in the list of available protocols"); |
@@ -471,7 +466,7 @@ class _WebSocketTransformerImpl implements WebSocketTransformer { |
..statusCode = HttpStatus.INTERNAL_SERVER_ERROR |
..close(); |
throw error; |
- }).then/*<WebSocket>*/(upgrade); |
+ }).then(upgrade); |
} else { |
return upgrade(null); |
} |
@@ -575,13 +570,13 @@ class _WebSocketPerMessageDeflate { |
Uint8List processIncomingMessage(List<int> msg) { |
_ensureDecoder(); |
- var data = <int>[]; |
+ var data = []; |
data.addAll(msg); |
data.addAll(const [0x00, 0x00, 0xff, 0xff]); |
decoder.process(data, 0, data.length); |
- var result = <int>[]; |
- List<int> out; |
+ var result = []; |
+ var out; |
while ((out = decoder.processed()) != null) { |
result.addAll(out); |
@@ -597,8 +592,9 @@ class _WebSocketPerMessageDeflate { |
List<int> processOutgoingMessage(List<int> msg) { |
_ensureEncoder(); |
- var result = <int>[]; |
+ var result = []; |
Uint8List buffer; |
+ var out; |
if (msg is! Uint8List) { |
for (var i = 0; i < msg.length; i++) { |
@@ -614,7 +610,6 @@ class _WebSocketPerMessageDeflate { |
encoder.process(buffer, 0, buffer.length); |
- List<int> out; |
while ((out = encoder.processed()) != null) { |
result.addAll(out); |
} |
@@ -645,8 +640,7 @@ class _WebSocketOutgoingTransformer |
} |
Stream<List<int>> bind(Stream stream) { |
- return new Stream<List<int>>.eventTransformed( |
- stream, (EventSink<List<int>> eventSink) { |
+ return new Stream.eventTransformed(stream, (eventSink) { |
if (_eventSink != null) { |
throw new StateError("WebSocket transformer already used"); |
} |
@@ -672,8 +666,8 @@ class _WebSocketOutgoingTransformer |
data = UTF8.encode(message); |
} else { |
if (message is List<int>) { |
- opcode = _WebSocketOpcode.BINARY; |
data = message; |
+ opcode = _WebSocketOpcode.BINARY; |
} else { |
throw new ArgumentError(message); |
} |
@@ -708,16 +702,15 @@ class _WebSocketOutgoingTransformer |
_eventSink.close(); |
} |
- void addFrame(int opcode, List<int> data) { |
- createFrame( |
- opcode, |
- data, |
- webSocket._serverSide, |
- _deflateHelper != null && |
- (opcode == _WebSocketOpcode.TEXT || |
- opcode == _WebSocketOpcode.BINARY)) |
- .forEach((e) { _eventSink.add(e); }); |
- } |
+ void addFrame(int opcode, List<int> data) => createFrame( |
+ opcode, |
+ data, |
+ webSocket._serverSide, |
+ _deflateHelper != null && |
+ (opcode == _WebSocketOpcode.TEXT || |
+ opcode == _WebSocketOpcode.BINARY)).forEach((e) { |
+ _eventSink.add(e); |
+ }); |
static Iterable<List<int>> createFrame( |
int opcode, List<int> data, bool serverSide, bool compressed) { |