|
|
@ -69,14 +69,17 @@ use log::*; |
|
|
|
use std::pin::Pin; |
|
|
|
use std::pin::Pin; |
|
|
|
use std::task::{Context, Poll}; |
|
|
|
use std::task::{Context, Poll}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
use tungstenite::{ |
|
|
|
use tungstenite::{ |
|
|
|
client::IntoClientRequest, |
|
|
|
client::IntoClientRequest, |
|
|
|
error::Error as WsError, |
|
|
|
|
|
|
|
handshake::{ |
|
|
|
handshake::{ |
|
|
|
client::{ClientHandshake, Response}, |
|
|
|
client::{ClientHandshake, Response}, |
|
|
|
server::{Callback, NoCallback}, |
|
|
|
server::{Callback, NoCallback}, |
|
|
|
HandshakeError, |
|
|
|
HandshakeError, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
use tungstenite::{ |
|
|
|
|
|
|
|
error::Error as WsError, |
|
|
|
protocol::{Message, Role, WebSocket, WebSocketConfig}, |
|
|
|
protocol::{Message, Role, WebSocket, WebSocketConfig}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -103,6 +106,7 @@ use tungstenite::protocol::CloseFrame; |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This is typically used for clients who have already established, for
|
|
|
|
/// This is typically used for clients who have already established, for
|
|
|
|
/// example, a TCP connection to the remote server.
|
|
|
|
/// example, a TCP connection to the remote server.
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
pub async fn client_async<'a, R, S>( |
|
|
|
pub async fn client_async<'a, R, S>( |
|
|
|
request: R, |
|
|
|
request: R, |
|
|
|
stream: S, |
|
|
|
stream: S, |
|
|
@ -116,6 +120,7 @@ where |
|
|
|
|
|
|
|
|
|
|
|
/// The same as `client_async()` but the one can specify a websocket configuration.
|
|
|
|
/// The same as `client_async()` but the one can specify a websocket configuration.
|
|
|
|
/// Please refer to `client_async()` for more details.
|
|
|
|
/// Please refer to `client_async()` for more details.
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
pub async fn client_async_with_config<'a, R, S>( |
|
|
|
pub async fn client_async_with_config<'a, R, S>( |
|
|
|
request: R, |
|
|
|
request: R, |
|
|
|
stream: S, |
|
|
|
stream: S, |
|
|
@ -150,6 +155,7 @@ where |
|
|
|
/// This is typically used after a socket has been accepted from a
|
|
|
|
/// This is typically used after a socket has been accepted from a
|
|
|
|
/// `TcpListener`. That socket is then passed to this function to perform
|
|
|
|
/// `TcpListener`. That socket is then passed to this function to perform
|
|
|
|
/// the server half of the accepting a client's websocket connection.
|
|
|
|
/// the server half of the accepting a client's websocket connection.
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
pub async fn accept_async<S>(stream: S) -> Result<WebSocketStream<S>, WsError> |
|
|
|
pub async fn accept_async<S>(stream: S) -> Result<WebSocketStream<S>, WsError> |
|
|
|
where |
|
|
|
where |
|
|
|
S: AsyncRead + AsyncWrite + Unpin, |
|
|
|
S: AsyncRead + AsyncWrite + Unpin, |
|
|
@ -159,6 +165,7 @@ where |
|
|
|
|
|
|
|
|
|
|
|
/// The same as `accept_async()` but the one can specify a websocket configuration.
|
|
|
|
/// The same as `accept_async()` but the one can specify a websocket configuration.
|
|
|
|
/// Please refer to `accept_async()` for more details.
|
|
|
|
/// Please refer to `accept_async()` for more details.
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
pub async fn accept_async_with_config<S>( |
|
|
|
pub async fn accept_async_with_config<S>( |
|
|
|
stream: S, |
|
|
|
stream: S, |
|
|
|
config: Option<WebSocketConfig>, |
|
|
|
config: Option<WebSocketConfig>, |
|
|
@ -174,6 +181,7 @@ where |
|
|
|
/// This function does the same as `accept_async()` but accepts an extra callback
|
|
|
|
/// This function does the same as `accept_async()` but accepts an extra callback
|
|
|
|
/// for header processing. The callback receives headers of the incoming
|
|
|
|
/// for header processing. The callback receives headers of the incoming
|
|
|
|
/// requests and is able to add extra headers to the reply.
|
|
|
|
/// requests and is able to add extra headers to the reply.
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
pub async fn accept_hdr_async<S, C>(stream: S, callback: C) -> Result<WebSocketStream<S>, WsError> |
|
|
|
pub async fn accept_hdr_async<S, C>(stream: S, callback: C) -> Result<WebSocketStream<S>, WsError> |
|
|
|
where |
|
|
|
where |
|
|
|
S: AsyncRead + AsyncWrite + Unpin, |
|
|
|
S: AsyncRead + AsyncWrite + Unpin, |
|
|
@ -184,6 +192,7 @@ where |
|
|
|
|
|
|
|
|
|
|
|
/// The same as `accept_hdr_async()` but the one can specify a websocket configuration.
|
|
|
|
/// The same as `accept_hdr_async()` but the one can specify a websocket configuration.
|
|
|
|
/// Please refer to `accept_hdr_async()` for more details.
|
|
|
|
/// Please refer to `accept_hdr_async()` for more details.
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
pub async fn accept_hdr_async_with_config<S, C>( |
|
|
|
pub async fn accept_hdr_async_with_config<S, C>( |
|
|
|
stream: S, |
|
|
|
stream: S, |
|
|
|
callback: C, |
|
|
|
callback: C, |
|
|
|