Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
775f006
adds a common stream interface that is simpler than WebsocketStream
illegalprime Jul 2, 2016
a6df89f
integrated new Stream trait and IntoWs struct
illegalprime Jul 3, 2016
14e159c
Fixed client creation with new stream trait
illegalprime Jul 3, 2016
87fecda
started work on having the server side code use websocket upgrade
illegalprime Jul 3, 2016
7a6a137
server now uses the ws upgrade trait to create clients
illegalprime Jul 4, 2016
f7e4d3b
IntoWs for Streams & Request/Stream pairs
illegalprime Jul 4, 2016
495351e
started on hyper IntoWs integration
illegalprime Jul 5, 2016
8628391
removed TryUnsizedClone and many Stream impls for a simpler model whe…
illegalprime Jul 7, 2016
dccab0f
removed response and request from the server code in favor of WsUpgrade
illegalprime Jul 7, 2016
03152d2
moved hyper-specific upgrade implementation into its own module
illegalprime Jul 7, 2016
9f14e1a
implemented AsTcpStream for Box<AsTcpStream>
illegalprime Jul 17, 2016
6bb3f8f
Steps toward implementing IntoWs for Hyper request
illegalprime Jul 17, 2016
ebb11eb
sender and receiver not holding the stream anymore, client uses stream
illegalprime Mar 27, 2017
f1595d8
added back splitting and shutting down client
illegalprime Mar 27, 2017
f03c007
started working on builder
illegalprime Mar 28, 2017
ae9b002
finished builder pattern and removed unused modules
illegalprime Mar 28, 2017
c582ee4
implement intows for hyper request, cleanup and refactoring
illegalprime Mar 28, 2017
e659824
moved client builder into its own module
illegalprime Mar 28, 2017
6a28b31
implemented intows
illegalprime Mar 28, 2017
7fed8bb
added TCP settings functions and verified questions about ws protocol
illegalprime Mar 28, 2017
d6fb9fe
updated all dependencies to the latest and greatest
illegalprime Mar 28, 2017
d5864e2
made openssl optional behind a feature gate
illegalprime Mar 29, 2017
19f298a
pass all current tests with warnings
illegalprime Mar 29, 2017
8dd2ff0
tests pass without warnings
illegalprime Mar 29, 2017
7b86a41
fleshed out roadmap, fixes #27
illegalprime Mar 29, 2017
ca8d824
added standard style enforced by the CI
illegalprime Mar 29, 2017
c828d9f
added buffering reads and writes to roadmap
illegalprime Mar 29, 2017
66a132a
easier wsupgrade api for protocols/exts, ability for client to verify…
illegalprime Mar 29, 2017
df581cf
changed stream trait to impl Read and Write, not contain
illegalprime Mar 30, 2017
134e3cb
keep track of all the used buffers in BufReaders so no data goes missing
illegalprime Mar 31, 2017
a363b1f
version bump to 0.18.0: major API change
illegalprime Mar 29, 2017
3a60b54
docs and doc tests
illegalprime Apr 1, 2017
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: 8 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hard_tabs = true
array_layout = "Block"
fn_args_layout = "Block"
chain_indent = "Visual"
chain_one_line_max = 100
take_source_hints = true
write_mode = "Overwrite"

47 changes: 26 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
language: rust
rust: nightly
cache: cargo
before_script:
- export PATH="$PATH:$HOME/.cargo/bin"
- which rustfmt || cargo install rustfmt

script:
- cargo fmt -- --write-mode=diff
- cargo build --features nightly
- cargo test --features nightly
- cargo bench --features nightly
Expand All @@ -12,36 +17,36 @@ after_success:
- >
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && sudo pip install ghp-import
- >
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
echo "Running Autobahn TestSuite for client" ;
wstest -m fuzzingserver -s ./autobahn/fuzzingserver.json & FUZZINGSERVER_PID=$! ;
sleep 10 ;
./target/debug/examples/autobahn-client ;
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
echo "Running Autobahn TestSuite for client" ;
wstest -m fuzzingserver -s ./autobahn/fuzzingserver.json & FUZZINGSERVER_PID=$! ;
sleep 10 ;
./target/debug/examples/autobahn-client ;
kill -9 ${FUZZINGSERVER_PID} ; }
- >
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
echo "Running Autobahn TestSuite for server" ;
./target/debug/examples/autobahn-server & WSSERVER_PID=$! ;
sleep 10 ;
wstest -m fuzzingclient -s ./autobahn/fuzzingclient.json ;
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
echo "Running Autobahn TestSuite for server" ;
./target/debug/examples/autobahn-server & WSSERVER_PID=$! ;
sleep 10 ;
wstest -m fuzzingclient -s ./autobahn/fuzzingclient.json ;
kill -9 ${WSSERVER_PID} ; }
- >
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
echo "Building docs and gh-pages" ;
PROJECT_VERSION=$(cargo doc --features nightly | grep "Documenting websocket v" | sed 's/.*Documenting websocket v\(.*\) .*/\1/') ;
curl -sL https://github.com/${TRAVIS_REPO_SLUG}/archive/html.tar.gz | tar xz ;
cd ./rust-websocket-html &&
find . -type f | xargs sed -i 's/<!--VERSION-->/'"${PROJECT_VERSION}"'/g' ;
mv ../target/doc ./doc ;
mv ../autobahn/server ./autobahn/server ;
mv ../autobahn/client ./autobahn/client ;
mv ./autobahn/server/index.json ./autobahn/server/index.temp && rm ./autobahn/server/*.json && mv ./autobahn/server/index.temp ./autobahn/server/index.json ;
echo "Building docs and gh-pages" ;
PROJECT_VERSION=$(cargo doc --features nightly | grep "Documenting websocket v" | sed 's/.*Documenting websocket v\(.*\) .*/\1/') ;
curl -sL https://github.com/${TRAVIS_REPO_SLUG}/archive/html.tar.gz | tar xz ;
cd ./rust-websocket-html &&
find . -type f | xargs sed -i 's/<!--VERSION-->/'"${PROJECT_VERSION}"'/g' ;
mv ../target/doc ./doc ;
mv ../autobahn/server ./autobahn/server ;
mv ../autobahn/client ./autobahn/client ;
mv ./autobahn/server/index.json ./autobahn/server/index.temp && rm ./autobahn/server/*.json && mv ./autobahn/server/index.temp ./autobahn/server/index.json ;
mv ./autobahn/client/index.json ./autobahn/client/index.temp && rm ./autobahn/client/*.json && mv ./autobahn/client/index.temp ./autobahn/client/index.json ;
cd ../ ; }
- >
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
echo "Pushing gh-pages" ;
ghp-import -n ./rust-websocket-html -m "Generated by Travis CI build ${TRAVIS_BUILD_NUMBER} for commit ${TRAVIS_COMMIT}" &&
echo "Pushing gh-pages" ;
ghp-import -n ./rust-websocket-html -m "Generated by Travis CI build ${TRAVIS_BUILD_NUMBER} for commit ${TRAVIS_COMMIT}" &&
git push -fq https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages ; }

env:
Expand Down
24 changes: 13 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]

name = "websocket"
version = "0.17.2"
authors = ["cyderize <admin@cyderize.org>"]
version = "0.18.0"
authors = ["cyderize <admin@cyderize.org>", "Michael Eden <themichaeleden@gmail.com>"]

description = "A WebSocket (RFC6455) library for Rust."

Expand All @@ -17,15 +17,17 @@ keywords = ["websocket", "websockets", "rfc6455"]
license = "MIT"

[dependencies]
hyper = ">=0.7, <0.11"
unicase = "1.0.1"
openssl = "0.7.6"
url = "1.0"
rustc-serialize = "0.3.16"
bitflags = "0.7"
rand = "0.3.12"
byteorder = "1.0"
net2 = "0.2.17"
hyper = { git = "https://github.com/hyperium/hyper.git", branch = "0.10.x" }
unicase = "^1.0"
url = "^1.0"
rustc-serialize = "^0.3"
bitflags = "^0.8"
rand = "^0.3"
byteorder = "^1.0"
sha1 = "^0.2"
openssl = { version = "^0.9.10", optional = true }

[features]
default = ["ssl"]
ssl = ["openssl"]
nightly = ["hyper/nightly"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Rust-WebSocket provides a framework for dealing with WebSocket connections (both
To add a library release version from [crates.io](https://crates.io/crates/websocket) to a Cargo project, add this to the 'dependencies' section of your Cargo.toml:

```INI
websocket = "0.17.1"
websocket = "0.18.0"
```

To add the library's Git repository to a Cargo project, add this to your Cargo.toml:
Expand Down
41 changes: 41 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The Roadmap

## More Docs, Examples and Tests

Easy as that, every method should be tested and documented.
Every use-case should have an example.

## Adding Features

### `net2` Feature

This is a feature to add the `net2` crate which will let us do cool things
like set the option `SO_REUSEADDR` and similar when making TCP connections.

This is discussed in [vi/rust-websocket#2](https://github.com/vi/rust-websocket/pull/2).

### Add Mio & Tokio (Evented Websocket)

There are a lot of issues that would be solved if this was evented, such as:

- [#88 tokio support](https://github.com/cyderize/rust-websocket/issues/88)
- [#66 Timeout on recv_message](https://github.com/cyderize/rust-websocket/issues/66)
- [#6 one client, one thread?](https://github.com/cyderize/rust-websocket/issues/6)

So maybe we should _just_ add `tokio` support, or maybe `mio` is still used and popular.

### Support Permessage-Deflate

We need this to pass more autobahn tests!

### Buffer Reads and Writes

In the old crate the stream was split up into a reader and writer stream so you could
have both a `BufReader` and a `BufWriter` to buffer your operations to gain some speed.
However is doesn't make sense to split the stream up anymore
(see [#83](https://github.com/cyderize/rust-websocket/issues/83))
meaning that we should buffer reads and writes in some other way.

Some work has begun on this, like [#91](https://github.com/cyderize/rust-websocket/pull/91),
but is this enough? And what about writing?

61 changes: 27 additions & 34 deletions examples/autobahn-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extern crate websocket;
extern crate rustc_serialize as serialize;

use std::str::from_utf8;
use websocket::client::request::Url;
use websocket::{Client, Message, Sender, Receiver};
use websocket::ClientBuilder;
use websocket::Message;
use websocket::message::Type;
use serialize::json;

Expand All @@ -20,22 +20,18 @@ fn main() {
let case_count = get_case_count(addr.clone());

while current_case_id <= case_count {
let url = addr.clone() + "/runCase?case=" + &current_case_id.to_string()[..] + "&agent=" + agent;
let case_id = current_case_id;
current_case_id += 1;
let url = addr.clone() + "/runCase?case=" + &case_id.to_string()[..] + "&agent=" + agent;

let ws_uri = Url::parse(&url[..]).unwrap();
let request = Client::connect(ws_uri).unwrap();
let response = request.send().unwrap();
match response.validate() {
Ok(()) => (),
Err(e) => {
println!("{:?}", e);
current_case_id += 1;
continue;
}
}
let (mut sender, mut receiver) = response.begin().split();
let client = ClientBuilder::new(&url)
.unwrap()
.connect_insecure()
.unwrap();

println!("Executing test case: {}/{}", current_case_id, case_count);
let (mut receiver, mut sender) = client.split().unwrap();

println!("Executing test case: {}/{}", case_id, case_count);

for message in receiver.incoming_messages() {
let message: Message = match message {
Expand All @@ -49,7 +45,7 @@ fn main() {

match message.opcode {
Type::Text => {
let response = Message::text(from_utf8(&*message.payload).unwrap());
let response = Message::text(from_utf8(&*message.payload).unwrap());
sender.send_message(&response).unwrap();
}
Type::Binary => {
Expand All @@ -65,26 +61,23 @@ fn main() {
_ => (),
}
}

current_case_id += 1;
}

update_reports(addr.clone(), agent);
}

fn get_case_count(addr: String) -> usize {
let url = addr + "/getCaseCount";
let ws_uri = Url::parse(&url[..]).unwrap();
let request = Client::connect(ws_uri).unwrap();
let response = request.send().unwrap();
match response.validate() {
Ok(()) => (),

let client = match ClientBuilder::new(&url).unwrap().connect_insecure() {
Ok(c) => c,
Err(e) => {
println!("{:?}", e);
return 0;
}
}
let (mut sender, mut receiver) = response.begin().split();
};

let (mut receiver, mut sender) = client.split().unwrap();

let mut count = 0;

Expand All @@ -93,7 +86,8 @@ fn get_case_count(addr: String) -> usize {
Ok(message) => message,
Err(e) => {
println!("Error: {:?}", e);
let _ = sender.send_message(&Message::close_because(1002, "".to_string()));
let _ =
sender.send_message(&Message::close_because(1002, "".to_string()));
break;
}
};
Expand All @@ -118,17 +112,16 @@ fn get_case_count(addr: String) -> usize {

fn update_reports(addr: String, agent: &str) {
let url = addr + "/updateReports?agent=" + agent;
let ws_uri = Url::parse(&url[..]).unwrap();
let request = Client::connect(ws_uri).unwrap();
let response = request.send().unwrap();
match response.validate() {
Ok(()) => (),

let client = match ClientBuilder::new(&url).unwrap().connect_insecure() {
Ok(c) => c,
Err(e) => {
println!("{:?}", e);
return;
}
}
let (mut sender, mut receiver) = response.begin().split();
};

let (mut receiver, mut sender) = client.split().unwrap();

println!("Updating reports...");

Expand Down
23 changes: 11 additions & 12 deletions examples/autobahn-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ extern crate websocket;

use std::thread;
use std::str::from_utf8;
use websocket::{Server, Message, Sender, Receiver};
use websocket::{Server, Message};
use websocket::message::Type;

fn main() {
let addr = "127.0.0.1:9002".to_string();

let server = Server::bind(&addr[..]).unwrap();
let server = Server::bind("127.0.0.1:9002").unwrap();

for connection in server {
thread::spawn(move || {
let request = connection.unwrap().read_request().unwrap();
request.validate().unwrap();
let response = request.accept();
let (mut sender, mut receiver) = response.send().unwrap().split();
let client = connection.accept().unwrap();

let (mut receiver, mut sender) = client.split().unwrap();

for message in receiver.incoming_messages() {
let message: Message = match message {
Expand All @@ -29,10 +26,12 @@ fn main() {

match message.opcode {
Type::Text => {
let response = Message::text(from_utf8(&*message.payload).unwrap());
sender.send_message(&response).unwrap()
},
Type::Binary => sender.send_message(&Message::binary(message.payload)).unwrap(),
let response = Message::text(from_utf8(&*message.payload).unwrap());
sender.send_message(&response).unwrap()
}
Type::Binary => {
sender.send_message(&Message::binary(message.payload)).unwrap()
}
Type::Close => {
let _ = sender.send_message(&Message::close());
return;
Expand Down
Loading