Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Edition 2018 #287

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ script:
- cargo check --features ssl
- cargo check --features nativetls
- cargo test
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]] ; then cargo install clippy --force && cargo clippy -- -A doc_markdown -A cyclomatic_complexity -A collapsible_if ; fi'
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]] ; then rustup component add rustfmt-preview && cargo fmt --all -- --write-mode=diff ; fi'
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]] ; then rustup component add clippy-preview && cargo clippy --all-targes ; fi'
- bash -c 'if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]] ; then rustup component add rustfmt-preview && cargo fmt --all -- --check ; fi'
after_success: |
# pip install --user autobahntestsuite &&
# /home/travis/.local/bin/wstest -m fuzzingserver -s ./tests/fuzzingserver.json & SPID=$! &&
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ name = "ws"
readme = "README.md"
repository = "https://github.com/housleyjk/ws-rs"
version = "0.9.1"
edition = "2018"

[dependencies]
byteorder = "1.2.1"
bytes = "0.4.6"
httparse = "1.2.4"
log = "0.4.1"
log = "0.4.8"
mio = "0.6.14"
mio-extras = "2.0"
rand = "0.7"
Expand Down
6 changes: 3 additions & 3 deletions examples/autobahn-client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// WebSocket client used for testing against the Autobahn Test Suite
extern crate ws;
//! WebSocket client used for testing against the Autobahn Test Suite

use std::cell::Cell;
use std::rc::Rc;
Expand Down Expand Up @@ -42,7 +41,8 @@ fn main() {

connect(case_url, |out| {
DeflateHandler::new(move |msg| out.send(msg))
}).unwrap();
})
.unwrap();

case_id += 1
}
Expand Down
15 changes: 7 additions & 8 deletions examples/autobahn-server.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
extern crate env_logger;
/// WebSocket server used for testing against the Autobahn Test Suite. This is basically the server
/// example without printing output or comments.
extern crate ws;
//! WebSocket server used for testing against the Autobahn Test Suite. This is basically the server
//! example without printing output or comments.

use env_logger;
use ws;
#[cfg(feature = "permessage-deflate")]
use ws::deflate::DeflateHandler;

#[cfg(not(feature = "permessage-deflate"))]
fn main() {
env_logger::init();

ws::listen("127.0.0.1:3012", |out| {
move |msg| out.send(msg)
}).unwrap()
ws::listen("127.0.0.1:3012", |out| move |msg| out.send(msg)).unwrap()
}

#[cfg(feature = "permessage-deflate")]
Expand All @@ -21,5 +19,6 @@ fn main() {

ws::listen("127.0.0.1:3012", |out| {
DeflateHandler::new(move |msg| out.send(msg))
}).unwrap();
})
.unwrap();
}
3 changes: 1 addition & 2 deletions examples/bench-server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// WebSocket server used for testing the bench example.
extern crate ws;
//! WebSocket server used for testing the bench example.

use ws::{Builder, Sender, Settings};

Expand Down
15 changes: 7 additions & 8 deletions examples/bench.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
extern crate env_logger;
extern crate time;
extern crate url;
/// A simple, but immature, benchmark client for destroying other WebSocket frameworks and proving
/// WS-RS's performance excellence. ;)
/// Make sure you allow for enough connections in your OS (e.g. ulimit -Sn 10000).
extern crate ws;
//! A simple, but immature, benchmark client for destroying other WebSocket frameworks and proving
//! WS-RS's performance excellence. ;)
//! Make sure you allow for enough connections in your OS (e.g. ulimit -Sn 10000).

// Try this against node for some fun

// TODO: Separate this example into a separate lib
// TODO: num threads, num connections per thread, num concurrent connections per thread, num
// messages per connection, length of message, text or binary

use env_logger;
use time;
use url;
use ws::{Builder, CloseCode, Handler, Handshake, Message, Result, Sender, Settings};

const CONNECTIONS: usize = 10_000; // simultaneous
const MESSAGES: u32 = 10;
static MESSAGE: &'static str = "TEST TEST TEST TEST TEST TEST TEST TEST";
static MESSAGE: &str = "TEST TEST TEST TEST TEST TEST TEST TEST";

fn main() {
env_logger::init();
Expand Down
29 changes: 15 additions & 14 deletions examples/channel.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
extern crate env_logger;
/// An example of using channels to transfer data between three parts of some system.
///
/// A WebSocket server echoes data back to a client and tees that data to a logging system.
/// A WebSocket client sends some data do the server.
/// A worker thread stores data as a log and sends that data back to the main program when the
/// WebSocket server has finished receiving data.
///
/// This example demonstrates how to use threads, channels, and WebSocket handlers to create a
/// complex system from simple, composable parts.
extern crate ws;
//! An example of using channels to transfer data between three parts of some system.
//!
//! A WebSocket server echoes data back to a client and tees that data to a logging system.
//! A WebSocket client sends some data do the server.
//! A worker thread stores data as a log and sends that data back to the main program when the
//! WebSocket server has finished receiving data.
//!
//! This example demonstrates how to use threads, channels, and WebSocket handlers to create a
//! complex system from simple, composable parts.

use std::sync::mpsc::Sender as ThreadOut;
use std::sync::mpsc::channel;
use std::sync::mpsc::Sender as ThreadOut;
use std::thread;
use std::thread::sleep;
use std::time::Duration;

use env_logger;
use ws::{connect, listen, CloseCode, Handler, Handshake, Message, Result, Sender};

fn main() {
Expand Down Expand Up @@ -60,7 +59,8 @@ fn main() {
// in theory, there could be many active connections
log: log_in.clone(),
}
}).unwrap()
})
.unwrap()
})
.unwrap();

Expand Down Expand Up @@ -117,7 +117,8 @@ fn main() {
// in theory, there could be many client connections sending off the data
data: client_data.clone(),
}
}).unwrap()
})
.unwrap()
})
.unwrap();

Expand Down
17 changes: 8 additions & 9 deletions examples/cli.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
extern crate clap;
extern crate env_logger;
extern crate term;
/// Run this cli like this:
/// cargo run --example server
/// cargo run --example cli -- ws://127.0.0.1:3012
extern crate ws;
//! Run this cli like this:
//! cargo run --example server
//! cargo run --example cli -- ws://127.0.0.1:3012

use std::io;
use std::io::prelude::*;
use std::sync::mpsc::Sender as TSender;
use std::sync::mpsc::channel;
use std::sync::mpsc::Sender as TSender;
use std::thread;

use clap::{App, Arg};
use env_logger;
use term;
use ws::{connect, CloseCode, Error, ErrorKind, Handler, Handshake, Message, Result, Sender};

fn main() {
Expand Down Expand Up @@ -42,7 +40,8 @@ fn main() {
connect(url, |sender| Client {
ws_out: sender,
thread_out: tx.clone(),
}).unwrap();
})
.unwrap();
});

if let Ok(Event::Connect(sender)) = rx.recv() {
Expand Down
7 changes: 3 additions & 4 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate env_logger;
/// Simple WebSocket client with error handling. It is not necessary to setup logging, but doing
/// so will allow you to see more details about the connection by using the RUST_LOG env variable.
extern crate ws;
//! Simple WebSocket client with error handling. It is not necessary to setup logging, but doing
//! so will allow you to see more details about the connection by using the RUST_LOG env variable.

use env_logger;
use ws::{connect, CloseCode};

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/external_shutdown.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate ws;

use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;

use ws;

fn main() {
let (tx, rx) = channel();

Expand Down
6 changes: 3 additions & 3 deletions examples/html_chat.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// An example of a chat web application server
extern crate ws;
//! An example of a chat web application server

use ws::{listen, Handler, Message, Request, Response, Result, Sender};

// This can be read from a file
static INDEX_HTML: &'static [u8] = br#"
static INDEX_HTML: &[u8] = br#"
<!DOCTYPE html>
<html>
<head>
Expand Down
63 changes: 31 additions & 32 deletions examples/peer2peer.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
extern crate clap;
extern crate env_logger;
extern crate url;
/// An example of a client-server-agnostic WebSocket that takes input from stdin and sends that
/// input to all other peers.
///
/// For example, to create a network like this:
///
/// 3013 ---- 3012 ---- 3014
/// \ |
/// \ |
/// \ |
/// \ |
/// \ |
/// \ |
/// \ |
/// 3015
///
/// Run these commands in separate processes
/// ./peer2peer
/// ./peer2peer --server localhost:3013 ws://localhost:3012
/// ./peer2peer --server localhost:3014 ws://localhost:3012
/// ./peer2peer --server localhost:3015 ws://localhost:3012 ws://localhost:3013
///
/// Stdin on 3012 will be sent to all other peers
/// Stdin on 3013 will be sent to 3012 and 3015
/// Stdin on 3014 will be sent to 3012 only
/// Stdin on 3015 will be sent to 3012 and 2013
extern crate ws;
#[macro_use]
extern crate log;
//! An example of a client-server-agnostic WebSocket that takes input from stdin and sends that
//! input to all other peers.
//!
//! For example, to create a network like this:
//!
//! 3013 ---- 3012 ---- 3014
//! \ |
//! \ |
//! \ |
//! \ |
//! \ |
//! \ |
//! \ |
//! 3015
//!
//! Run these commands in separate processes
//! ./peer2peer
//! ./peer2peer --server localhost:3013 ws://localhost:3012
//! ./peer2peer --server localhost:3014 ws://localhost:3012
//! ./peer2peer --server localhost:3015 ws://localhost:3012 ws://localhost:3013
//!
//! Stdin on 3012 will be sent to all other peers
//! Stdin on 3013 will be sent to 3012 and 3015
//! Stdin on 3014 will be sent to 3012 only
//! Stdin on 3015 will be sent to 3012 and 2013

use std::io;
use std::io::prelude::*;
use std::thread;

use clap::{App, Arg};
use env_logger;
use log::info;
use url;
use ws;

fn main() {
// Setup logging
Expand Down Expand Up @@ -68,7 +66,8 @@ fn main() {
info!("Peer {} got message: {}", my_addr, msg);
Ok(())
}
}).unwrap();
})
.unwrap();

// Get a sender for ALL connections to the websocket
let broacaster = me.broadcaster();
Expand Down
17 changes: 8 additions & 9 deletions examples/pong.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
extern crate env_logger;
extern crate mio_extras;
extern crate time;
/// An example demonstrating how to send and recieve a custom ping/pong frame.
extern crate ws;
//! An example demonstrating how to send and recieve a custom ping/pong frame.

use std::str::from_utf8;

use env_logger;
use mio_extras::timer::Timeout;

use time;
use ws::util::Token;
use ws::{listen, CloseCode, Error, ErrorKind, Frame, Handler, Handshake, Message, OpCode, Result,
Sender};
use ws::{
listen, CloseCode, Error, ErrorKind, Frame, Handler, Handshake, Message, OpCode, Result, Sender,
};

const PING: Token = Token(1);
const EXPIRE: Token = Token(2);
Expand All @@ -24,7 +22,8 @@ fn main() {
out,
ping_timeout: None,
expire_timeout: None,
}).unwrap();
})
.unwrap();
}

// Server WebSocket handler
Expand Down
13 changes: 7 additions & 6 deletions examples/router.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
extern crate env_logger;
/// WebSocket server using trait objects to route
/// to an infinitely extensible number of handlers
extern crate ws;
//! WebSocket server using trait objects to route
//! to an infinitely extensible number of handlers

// A WebSocket handler that routes connections to different boxed handlers by resource
use env_logger;
use ws;

/// A WebSocket handler that routes connections to different boxed handlers by resource
struct Router {
sender: ws::Sender,
inner: Box<ws::Handler>,
inner: Box<dyn ws::Handler>,
}

impl ws::Handler for Router {
Expand Down
7 changes: 3 additions & 4 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate env_logger;
/// Simple WebSocket server with error handling. It is not necessary to setup logging, but doing
/// so will allow you to see more details about the connection by using the RUST_LOG env variable.
extern crate ws;
//! Simple WebSocket server with error handling. It is not necessary to setup logging, but doing
//! so will allow you to see more details about the connection by using the RUST_LOG env variable.

use env_logger;
use ws::listen;

fn main() {
Expand Down
Loading