Skip to content

Commit 32c516c

Browse files
committed
Merge remote-tracking branch 'illegalprime/ws-upgrade'
2 parents 0333fe7 + 3a60b54 commit 32c516c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2641
-2067
lines changed

.rustfmt.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
hard_tabs = true
2+
array_layout = "Block"
3+
fn_args_layout = "Block"
4+
chain_indent = "Visual"
5+
chain_one_line_max = 100
6+
take_source_hints = true
7+
write_mode = "Overwrite"
8+

.travis.yml

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
language: rust
22
rust: nightly
3+
cache: cargo
4+
before_script:
5+
- export PATH="$PATH:$HOME/.cargo/bin"
6+
- which rustfmt || cargo install rustfmt
37

48
script:
9+
- cargo fmt -- --write-mode=diff
510
- cargo build --features nightly
611
- cargo test --features nightly
712
- cargo bench --features nightly
@@ -12,36 +17,36 @@ after_success:
1217
- >
1318
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && sudo pip install ghp-import
1419
- >
15-
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
16-
echo "Running Autobahn TestSuite for client" ;
17-
wstest -m fuzzingserver -s ./autobahn/fuzzingserver.json & FUZZINGSERVER_PID=$! ;
18-
sleep 10 ;
19-
./target/debug/examples/autobahn-client ;
20+
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
21+
echo "Running Autobahn TestSuite for client" ;
22+
wstest -m fuzzingserver -s ./autobahn/fuzzingserver.json & FUZZINGSERVER_PID=$! ;
23+
sleep 10 ;
24+
./target/debug/examples/autobahn-client ;
2025
kill -9 ${FUZZINGSERVER_PID} ; }
2126
- >
22-
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
23-
echo "Running Autobahn TestSuite for server" ;
24-
./target/debug/examples/autobahn-server & WSSERVER_PID=$! ;
25-
sleep 10 ;
26-
wstest -m fuzzingclient -s ./autobahn/fuzzingclient.json ;
27+
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
28+
echo "Running Autobahn TestSuite for server" ;
29+
./target/debug/examples/autobahn-server & WSSERVER_PID=$! ;
30+
sleep 10 ;
31+
wstest -m fuzzingclient -s ./autobahn/fuzzingclient.json ;
2732
kill -9 ${WSSERVER_PID} ; }
2833
- >
2934
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
30-
echo "Building docs and gh-pages" ;
31-
PROJECT_VERSION=$(cargo doc --features nightly | grep "Documenting websocket v" | sed 's/.*Documenting websocket v\(.*\) .*/\1/') ;
32-
curl -sL https://github.com/${TRAVIS_REPO_SLUG}/archive/html.tar.gz | tar xz ;
33-
cd ./rust-websocket-html &&
34-
find . -type f | xargs sed -i 's/<!--VERSION-->/'"${PROJECT_VERSION}"'/g' ;
35-
mv ../target/doc ./doc ;
36-
mv ../autobahn/server ./autobahn/server ;
37-
mv ../autobahn/client ./autobahn/client ;
38-
mv ./autobahn/server/index.json ./autobahn/server/index.temp && rm ./autobahn/server/*.json && mv ./autobahn/server/index.temp ./autobahn/server/index.json ;
35+
echo "Building docs and gh-pages" ;
36+
PROJECT_VERSION=$(cargo doc --features nightly | grep "Documenting websocket v" | sed 's/.*Documenting websocket v\(.*\) .*/\1/') ;
37+
curl -sL https://github.com/${TRAVIS_REPO_SLUG}/archive/html.tar.gz | tar xz ;
38+
cd ./rust-websocket-html &&
39+
find . -type f | xargs sed -i 's/<!--VERSION-->/'"${PROJECT_VERSION}"'/g' ;
40+
mv ../target/doc ./doc ;
41+
mv ../autobahn/server ./autobahn/server ;
42+
mv ../autobahn/client ./autobahn/client ;
43+
mv ./autobahn/server/index.json ./autobahn/server/index.temp && rm ./autobahn/server/*.json && mv ./autobahn/server/index.temp ./autobahn/server/index.json ;
3944
mv ./autobahn/client/index.json ./autobahn/client/index.temp && rm ./autobahn/client/*.json && mv ./autobahn/client/index.temp ./autobahn/client/index.json ;
4045
cd ../ ; }
4146
- >
4247
[ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && {
43-
echo "Pushing gh-pages" ;
44-
ghp-import -n ./rust-websocket-html -m "Generated by Travis CI build ${TRAVIS_BUILD_NUMBER} for commit ${TRAVIS_COMMIT}" &&
48+
echo "Pushing gh-pages" ;
49+
ghp-import -n ./rust-websocket-html -m "Generated by Travis CI build ${TRAVIS_BUILD_NUMBER} for commit ${TRAVIS_COMMIT}" &&
4550
git push -fq https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages ; }
4651
4752
env:

Cargo.toml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22

33
name = "websocket"
4-
version = "0.17.2"
5-
authors = ["cyderize <admin@cyderize.org>"]
4+
version = "0.18.0"
5+
authors = ["cyderize <admin@cyderize.org>", "Michael Eden <themichaeleden@gmail.com>"]
66

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

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

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

3030
[features]
31+
default = ["ssl"]
32+
ssl = ["openssl"]
3133
nightly = ["hyper/nightly"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Rust-WebSocket provides a framework for dealing with WebSocket connections (both
1010
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:
1111

1212
```INI
13-
websocket = "0.17.1"
13+
websocket = "0.18.0"
1414
```
1515

1616
To add the library's Git repository to a Cargo project, add this to your Cargo.toml:

ROADMAP.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# The Roadmap
2+
3+
## More Docs, Examples and Tests
4+
5+
Easy as that, every method should be tested and documented.
6+
Every use-case should have an example.
7+
8+
## Adding Features
9+
10+
### `net2` Feature
11+
12+
This is a feature to add the `net2` crate which will let us do cool things
13+
like set the option `SO_REUSEADDR` and similar when making TCP connections.
14+
15+
This is discussed in [vi/rust-websocket#2](https://github.com/vi/rust-websocket/pull/2).
16+
17+
### Add Mio & Tokio (Evented Websocket)
18+
19+
There are a lot of issues that would be solved if this was evented, such as:
20+
21+
- [#88 tokio support](https://github.com/cyderize/rust-websocket/issues/88)
22+
- [#66 Timeout on recv_message](https://github.com/cyderize/rust-websocket/issues/66)
23+
- [#6 one client, one thread?](https://github.com/cyderize/rust-websocket/issues/6)
24+
25+
So maybe we should _just_ add `tokio` support, or maybe `mio` is still used and popular.
26+
27+
### Support Permessage-Deflate
28+
29+
We need this to pass more autobahn tests!
30+
31+
### Buffer Reads and Writes
32+
33+
In the old crate the stream was split up into a reader and writer stream so you could
34+
have both a `BufReader` and a `BufWriter` to buffer your operations to gain some speed.
35+
However is doesn't make sense to split the stream up anymore
36+
(see [#83](https://github.com/cyderize/rust-websocket/issues/83))
37+
meaning that we should buffer reads and writes in some other way.
38+
39+
Some work has begun on this, like [#91](https://github.com/cyderize/rust-websocket/pull/91),
40+
but is this enough? And what about writing?
41+

examples/autobahn-client.rs

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ extern crate websocket;
22
extern crate rustc_serialize as serialize;
33

44
use std::str::from_utf8;
5-
use websocket::client::request::Url;
6-
use websocket::{Client, Message, Sender, Receiver};
5+
use websocket::ClientBuilder;
6+
use websocket::Message;
77
use websocket::message::Type;
88
use serialize::json;
99

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

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

25-
let ws_uri = Url::parse(&url[..]).unwrap();
26-
let request = Client::connect(ws_uri).unwrap();
27-
let response = request.send().unwrap();
28-
match response.validate() {
29-
Ok(()) => (),
30-
Err(e) => {
31-
println!("{:?}", e);
32-
current_case_id += 1;
33-
continue;
34-
}
35-
}
36-
let (mut sender, mut receiver) = response.begin().split();
27+
let client = ClientBuilder::new(&url)
28+
.unwrap()
29+
.connect_insecure()
30+
.unwrap();
3731

38-
println!("Executing test case: {}/{}", current_case_id, case_count);
32+
let (mut receiver, mut sender) = client.split().unwrap();
33+
34+
println!("Executing test case: {}/{}", case_id, case_count);
3935

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

5046
match message.opcode {
5147
Type::Text => {
52-
let response = Message::text(from_utf8(&*message.payload).unwrap());
48+
let response = Message::text(from_utf8(&*message.payload).unwrap());
5349
sender.send_message(&response).unwrap();
5450
}
5551
Type::Binary => {
@@ -65,26 +61,23 @@ fn main() {
6561
_ => (),
6662
}
6763
}
68-
69-
current_case_id += 1;
7064
}
7165

7266
update_reports(addr.clone(), agent);
7367
}
7468

7569
fn get_case_count(addr: String) -> usize {
7670
let url = addr + "/getCaseCount";
77-
let ws_uri = Url::parse(&url[..]).unwrap();
78-
let request = Client::connect(ws_uri).unwrap();
79-
let response = request.send().unwrap();
80-
match response.validate() {
81-
Ok(()) => (),
71+
72+
let client = match ClientBuilder::new(&url).unwrap().connect_insecure() {
73+
Ok(c) => c,
8274
Err(e) => {
8375
println!("{:?}", e);
8476
return 0;
8577
}
86-
}
87-
let (mut sender, mut receiver) = response.begin().split();
78+
};
79+
80+
let (mut receiver, mut sender) = client.split().unwrap();
8881

8982
let mut count = 0;
9083

@@ -93,7 +86,8 @@ fn get_case_count(addr: String) -> usize {
9386
Ok(message) => message,
9487
Err(e) => {
9588
println!("Error: {:?}", e);
96-
let _ = sender.send_message(&Message::close_because(1002, "".to_string()));
89+
let _ =
90+
sender.send_message(&Message::close_because(1002, "".to_string()));
9791
break;
9892
}
9993
};
@@ -118,17 +112,16 @@ fn get_case_count(addr: String) -> usize {
118112

119113
fn update_reports(addr: String, agent: &str) {
120114
let url = addr + "/updateReports?agent=" + agent;
121-
let ws_uri = Url::parse(&url[..]).unwrap();
122-
let request = Client::connect(ws_uri).unwrap();
123-
let response = request.send().unwrap();
124-
match response.validate() {
125-
Ok(()) => (),
115+
116+
let client = match ClientBuilder::new(&url).unwrap().connect_insecure() {
117+
Ok(c) => c,
126118
Err(e) => {
127119
println!("{:?}", e);
128120
return;
129121
}
130-
}
131-
let (mut sender, mut receiver) = response.begin().split();
122+
};
123+
124+
let (mut receiver, mut sender) = client.split().unwrap();
132125

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

examples/autobahn-server.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ extern crate websocket;
22

33
use std::thread;
44
use std::str::from_utf8;
5-
use websocket::{Server, Message, Sender, Receiver};
5+
use websocket::{Server, Message};
66
use websocket::message::Type;
77

88
fn main() {
9-
let addr = "127.0.0.1:9002".to_string();
10-
11-
let server = Server::bind(&addr[..]).unwrap();
9+
let server = Server::bind("127.0.0.1:9002").unwrap();
1210

1311
for connection in server {
1412
thread::spawn(move || {
15-
let request = connection.unwrap().read_request().unwrap();
16-
request.validate().unwrap();
17-
let response = request.accept();
18-
let (mut sender, mut receiver) = response.send().unwrap().split();
13+
let client = connection.accept().unwrap();
14+
15+
let (mut receiver, mut sender) = client.split().unwrap();
1916

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

3027
match message.opcode {
3128
Type::Text => {
32-
let response = Message::text(from_utf8(&*message.payload).unwrap());
33-
sender.send_message(&response).unwrap()
34-
},
35-
Type::Binary => sender.send_message(&Message::binary(message.payload)).unwrap(),
29+
let response = Message::text(from_utf8(&*message.payload).unwrap());
30+
sender.send_message(&response).unwrap()
31+
}
32+
Type::Binary => {
33+
sender.send_message(&Message::binary(message.payload)).unwrap()
34+
}
3635
Type::Close => {
3736
let _ = sender.send_message(&Message::close());
3837
return;

0 commit comments

Comments
 (0)