Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enable travis, dartfmt, other cleanup #8

Merged
merged 5 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
.buildlog
.DS_Store
.idea
.pub/
.settings/
build/
packages
.packages
.pub/
pubspec.lock
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: dart
sudo: false
dart:
- dev
- stable

dart_task:
- test: --platform vm
- test: --platform firefox -j 1
- test: --platform dartium
install_dartium: true
- dartanalyzer

matrix:
include:
- dart: dev
dart_task: dartfmt

# Only building master means that we don't run two builds for each pull request.
branches:
only: [master]

cache:
directories:
- $HOME/.pub-cache
10 changes: 5 additions & 5 deletions lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class HtmlWebSocketChannel extends StreamChannelMixin
String _localCloseReason;

Stream get stream => _controller.foreign.stream;
final _controller = new StreamChannelController(
sync: true, allowForeignErrors: false);
final _controller =
new StreamChannelController(sync: true, allowForeignErrors: false);

WebSocketSink get sink => _sink;
WebSocketSink _sink;
Expand All @@ -62,13 +62,13 @@ class HtmlWebSocketChannel extends StreamChannelMixin
/// received by this socket. It defaults to [BinaryType.list], which causes
/// binary messages to be delivered as [Uint8List]s. If it's
/// [BinaryType.blob], they're delivered as [Blob]s instead.
HtmlWebSocketChannel.connect(url, {Iterable<String> protocols,
BinaryType binaryType})
HtmlWebSocketChannel.connect(url,
{Iterable<String> protocols, BinaryType binaryType})
: this(new WebSocket(url.toString(), protocols)
..binaryType = (binaryType ?? BinaryType.list).value);

/// Creates a channel wrapping [webSocket].
HtmlWebSocketChannel(this._webSocket){
HtmlWebSocketChannel(this._webSocket) {
_sink = new _HtmlWebSocketSink(this);

if (_webSocket.readyState == WebSocket.OPEN) {
Expand Down
14 changes: 8 additions & 6 deletions lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class IOWebSocketChannel extends StreamChannelMixin
///
/// If there's an error connecting, the channel's stream emits a
/// [WebSocketChannelException] wrapping that error and then closes.
factory IOWebSocketChannel.connect(url, {Iterable<String> protocols,
Map<String, dynamic> headers, Duration pingInterval}) {
factory IOWebSocketChannel.connect(url,
{Iterable<String> protocols,
Map<String, dynamic> headers,
Duration pingInterval}) {
var channel;
var sinkCompleter = new WebSocketSinkCompleter();
var stream = StreamCompleter.fromFuture(
Expand All @@ -67,8 +69,8 @@ class IOWebSocketChannel extends StreamChannelMixin
/// Creates a channel wrapping [socket].
IOWebSocketChannel(WebSocket socket)
: _webSocket = socket,
stream = socket.handleError((error) =>
throw new WebSocketChannelException.from(error)),
stream = socket.handleError(
(error) => throw new WebSocketChannelException.from(error)),
sink = new _IOWebSocketSink(socket);

/// Creates a channel without a socket.
Expand All @@ -77,8 +79,8 @@ class IOWebSocketChannel extends StreamChannelMixin
/// has a socket added.
IOWebSocketChannel._withoutSocket(Stream stream, this.sink)
: _webSocket = null,
stream = stream.handleError((error) =>
throw new WebSocketChannelException.from(error));
stream = stream.handleError(
(error) => throw new WebSocketChannelException.from(error));
}

/// A [WebSocketSink] that forwards [close] calls to a `dart:io` [WebSocket].
Expand Down
6 changes: 3 additions & 3 deletions lib/src/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class WebSocketChannel extends StreamChannelMixin {
static String signKey(String key) {
// We use [codeUnits] here rather than UTF-8-decoding the string because
// [key] is expected to be base64 encoded, and so will be pure ASCII.
return convert.BASE64.encode(
sha1.convert((key + webSocketGUID).codeUnits).bytes);
return convert.BASE64
.encode(sha1.convert((key + webSocketGUID).codeUnits).bytes);
}

/// Creates a new WebSocket handling messaging across an existing [channel].
Expand All @@ -90,7 +90,7 @@ class WebSocketChannel extends StreamChannelMixin {
///
/// [WebSocket handshake]: https://tools.ietf.org/html/rfc6455#section-4
WebSocketChannel(StreamChannel<List<int>> channel,
{String protocol, Duration pingInterval, bool serverSide: true})
{String protocol, Duration pingInterval, bool serverSide: true})
: _webSocket = new WebSocketImpl.fromSocket(
channel.stream, channel.sink, protocol, serverSide)
..pingInterval = pingInterval;
Expand Down
86 changes: 34 additions & 52 deletions lib/src/copy/bytes_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@
import 'dart:math';
import 'dart:typed_data';

/**
* Builds a list of bytes, allowing bytes and lists of bytes to be added at the
* end.
*
* Used to efficiently collect bytes and lists of bytes.
*/
/// Builds a list of bytes, allowing bytes and lists of bytes to be added at the
/// end.
///
/// Used to efficiently collect bytes and lists of bytes.
abstract class BytesBuilder {
/**
* Construct a new empty [BytesBuilder].
*
* If [copy] is true, the data is always copied when added to the list. If
* it [copy] is false, the data is only copied if needed. That means that if
* the lists are changed after added to the [BytesBuilder], it may effect the
* output. Default is `true`.
*/
/// Construct a new empty [BytesBuilder].
///
/// If [copy] is true, the data is always copied when added to the list. If
/// it [copy] is false, the data is only copied if needed. That means that if
/// the lists are changed after added to the [BytesBuilder], it may effect the
/// output. Default is `true`.
factory BytesBuilder({bool copy: true}) {
if (copy) {
return new _CopyingBytesBuilder();
Expand All @@ -37,58 +33,41 @@ abstract class BytesBuilder {
}
}

/**
* Appends [bytes] to the current contents of the builder.
*
* Each value of [bytes] will be bit-representation truncated to the range
* 0 .. 255.
*/
/// Appends [bytes] to the current contents of the builder.
///
/// Each value of [bytes] will be bit-representation truncated to the range
/// 0 .. 255.
void add(List<int> bytes);

/**
* Append [byte] to the current contents of the builder.
*
* The [byte] will be bit-representation truncated to the range 0 .. 255.
*/
/// Append [byte] to the current contents of the builder.
///
/// The [byte] will be bit-representation truncated to the range 0 .. 255.
void addByte(int byte);

/**
* Returns the contents of `this` and clears `this`.
*
* The list returned is a view of the the internal buffer, limited to the
* [length].
*/
/// Returns the contents of `this` and clears `this`.
///
/// The list returned is a view of the the internal buffer, limited to the
/// [length].
List<int> takeBytes();

/**
* Returns a copy of the current contents of the builder.
*
* Leaves the contents of the builder intact.
*/
/// Returns a copy of the current contents of the builder.
///
/// Leaves the contents of the builder intact.
List<int> toBytes();

/**
* The number of bytes in the builder.
*/
/// The number of bytes in the builder.
int get length;

/**
* Returns `true` if the buffer is empty.
*/
/// Returns `true` if the buffer is empty.
bool get isEmpty;

/**
* Returns `true` if the buffer is not empty.
*/
/// Returns `true` if the buffer is not empty.
bool get isNotEmpty;

/**
* Clear the contents of the builder.
*/
/// Clear the contents of the builder.
void clear();
}


class _CopyingBytesBuilder implements BytesBuilder {
// Start with 1024 bytes.
static const int _INIT_SIZE = 1024;
Expand Down Expand Up @@ -123,7 +102,9 @@ class _CopyingBytesBuilder implements BytesBuilder {
_length = required;
}

void addByte(int byte) { add([byte]); }
void addByte(int byte) {
add([byte]);
}

List<int> takeBytes() {
if (_buffer == null) return new Uint8List(0);
Expand Down Expand Up @@ -160,7 +141,6 @@ class _CopyingBytesBuilder implements BytesBuilder {
}
}


class _BytesBuilder implements BytesBuilder {
int _length = 0;
final _chunks = <List<int>>[];
Expand All @@ -173,7 +153,9 @@ class _BytesBuilder implements BytesBuilder {
_length += bytes.length;
}

void addByte(int byte) { add([byte]); }
void addByte(int byte) {
add([byte]);
}

List<int> takeBytes() {
if (_chunks.length == 0) return new Uint8List(0);
Expand Down
10 changes: 5 additions & 5 deletions lib/src/copy/io_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class StreamSinkImpl<T> implements StreamSink<T> {
if (_hasError) return done;
// Wait for any sync operations to complete.
Future targetAddStream() {
return _target.addStream(stream)
.whenComplete(() {
_isBound = false;
});
return _target.addStream(stream).whenComplete(() {
_isBound = false;
});
}

if (_controllerInstance == null) return targetAddStream();
var future = _controllerCompleter.future;
_controllerInstance.close();
Expand Down Expand Up @@ -133,7 +133,7 @@ class StreamSinkImpl<T> implements StreamSink<T> {
_completeDoneError(error, stackTrace);
}
});
}
}
return _controllerInstance;
}
}
8 changes: 2 additions & 6 deletions lib/src/copy/web_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
// This is up-to-date as of sdk revision
// e41fb4cafd6052157dbc1490d437045240f4773f.

/**
* Web socket status codes used when closing a web socket connection.
*/
/// Web socket status codes used when closing a web socket connection.
abstract class WebSocketStatus {
static const int NORMAL_CLOSURE = 1000;
static const int GOING_AWAY = 1001;
Expand All @@ -31,9 +29,7 @@ abstract class WebSocketStatus {
}

abstract class WebSocket {
/**
* Possible states of the connection.
*/
/// Possible states of the connection.
static const int CONNECTING = 0;
static const int OPEN = 1;
static const int CLOSING = 2;
Expand Down
Loading