1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#![warn(missing_docs)]
#![cfg_attr(all(test, feature = "nightly"), feature(test))]
#![cfg_attr(
	feature = "cargo-clippy",
	allow(write_with_newline, type_complexity, match_ref_pats)
)]
#![deny(unused_mut)]

//! Rust-WebSocket is a WebSocket (RFC6455) library written in Rust.
//!
//! # Synchronous and Asynchronous
//! This crate has both async and sync implementations of websockets, you are free to
//! choose which one you would like to use by switching on the `async` or `sync` features
//! for this crate. By default both are switched on since they do not conflict with each
//! other.
//!
//! You'll find many modules with `::sync` and `::async` submodules that separate these
//! behaviours. Since it get's tedious to add these on when appropriate a top-level
//! convenience module called `websocket::sync` and `websocket::async` has been added that
//! groups all the sync and async stuff, respectively.
//!
//! # Clients
//! To make a client use the `ClientBuilder` struct, this builder has methods
//! for creating both synchronous and asynchronous clients.
//!
//! # Servers
//! WebSocket servers act similarly to the `TcpListener`, and listen for connections.
//! See the `Server` struct documentation for more information. The `bind()` and
//! `bind_secure()` functions will bind the server to the given `SocketAddr`.
//!
//! # Extending Rust-WebSocket
//! The `ws` module contains the traits and functions used by Rust-WebSocket at a lower
//! level. Their usage is explained in the module documentation.
extern crate base64;
extern crate byteorder;
#[cfg(feature = "async")]
extern crate bytes;
#[cfg(feature = "async")]
pub extern crate futures;
extern crate hyper;
#[cfg(any(feature = "sync-ssl", feature = "async-ssl"))]
extern crate native_tls;
extern crate rand;
extern crate sha1;
#[cfg(feature = "async")]
extern crate tokio_core;
#[cfg(feature = "async")]
extern crate tokio_io;
#[cfg(feature = "async-ssl")]
extern crate tokio_tls;
extern crate unicase;
pub extern crate url;

#[macro_use]
extern crate bitflags;

#[cfg(all(feature = "nightly", test))]
extern crate test;

macro_rules! upsert_header {
	($headers:expr; $header:ty;  { Some($pat:pat) => $some_match:expr,None => $default:expr }) => {{
		if $headers.has::<$header>() {
			if let Some($pat) = $headers.get_mut::<$header>() {
				$some_match
				}
		} else {
			$headers.set($default);
			}
		}};
}

pub mod dataframe;
pub mod header;
pub mod message;
pub mod result;
pub mod ws;

#[cfg(feature = "async")]
pub mod codec;

#[cfg(feature = "sync")]
pub mod receiver;
#[cfg(feature = "sync")]
pub mod sender;

pub mod client;
pub mod server;
pub mod stream;

/// A collection of handy synchronous-only parts of the crate.
#[cfg(feature = "sync")]
pub mod sync {
	pub use sender;
	pub use sender::Writer;

	pub use receiver;
	pub use receiver::Reader;

	pub use stream::sync as stream;
	pub use stream::sync::Stream;

	/// A collection of handy synchronous-only parts of the `server` module.
	pub mod server {
		pub use server::sync::*;
		pub use server::upgrade::sync as upgrade;
		pub use server::upgrade::sync::IntoWs;
		pub use server::upgrade::sync::Upgrade;
	}
	pub use server::sync::Server;

	/// A collection of handy synchronous-only parts of the `client` module.
	pub mod client {
		pub use client::builder::ClientBuilder;
		pub use client::sync::*;
	}
	pub use client::sync::Client;
}

/// A collection of handy asynchronous-only parts of the crate.
#[cfg(feature = "async")]
pub mod async {
	pub use codec;
	pub use codec::http::HttpClientCodec;
	pub use codec::http::HttpServerCodec;
	pub use codec::ws::Context as MsgCodecCtx;
	pub use codec::ws::MessageCodec;

	pub use stream::async as stream;
	pub use stream::async::Stream;

	/// A collection of handy asynchronous-only parts of the `server` module.
	pub mod server {
		pub use server::async::*;
		pub use server::upgrade::async as upgrade;
		pub use server::upgrade::async::IntoWs;
		pub use server::upgrade::async::Upgrade;
	}
	pub use server::async::Server;

	/// A collection of handy asynchronous-only parts of the `client` module.
	pub mod client {
		pub use client::async::*;
		pub use client::builder::ClientBuilder;
	}
	pub use client::async::Client;

	pub use result::async::WebSocketFuture;

	pub use futures;
	pub use tokio_core::net::TcpListener;
	pub use tokio_core::net::TcpStream;
	pub use tokio_core::reactor::Core;
	pub use tokio_core::reactor::Handle;
}

pub use self::client::builder::ClientBuilder;
pub use self::message::CloseData;
pub use self::message::Message;
pub use self::message::OwnedMessage;

pub use self::result::WebSocketError;
pub use self::result::WebSocketResult;