pub struct Endpoint<IO, Role> { /* private fields */ }
Expand description
Handshake endpoint.
Implementations§
source§impl<IO: Read + Write, Role: ClientRole> Endpoint<IO, Role>
impl<IO: Read + Write, Role: ClientRole> Endpoint<IO, Role>
sourcepub fn send_request<const N: usize>(
io: &mut IO,
buf: &mut [u8],
request: &Request<'_, '_, N>
) -> Result<usize>
pub fn send_request<const N: usize>( io: &mut IO, buf: &mut [u8], request: &Request<'_, '_, N> ) -> Result<usize>
Send websocket upgrade request to IO source, return the number of bytes transmitted. Request data are encoded to the provided buffer.
This function will block until all data are written to IO source or an error occurs.
sourcepub unsafe fn recv_response<'h, 'b: 'h, const N: usize>(
io: &mut IO,
buf: &mut [u8],
response: &mut Response<'h, 'b, N>
) -> Result<usize>
pub unsafe fn recv_response<'h, 'b: 'h, const N: usize>( io: &mut IO, buf: &mut [u8], response: &mut Response<'h, 'b, N> ) -> Result<usize>
Receive websocket upgrade response from IO source, return
the number of bytes transmitted.
Received data are stored in the provided buffer, and parsed
as Response
.
This function will block on reading data, until there is enough data to parse a response or an error occurs.
Safety
Caller must not modify the buffer while response
is in use,
otherwise it is undefined behavior!
sourcepub fn connect(
io: IO,
buf: &mut [u8],
host: &str,
path: &str
) -> Result<Stream<IO, Role>>
pub fn connect( io: IO, buf: &mut [u8], host: &str, path: &str ) -> Result<Stream<IO, Role>>
Perform a simple websocket client handshake, return a new websocket stream.
This function is a combination of send_request
and recv_response
, without accessing Response
.
It will block until the handshake completes, or an error occurs.
source§impl<IO: Read + Write, Role: ServerRole> Endpoint<IO, Role>
impl<IO: Read + Write, Role: ServerRole> Endpoint<IO, Role>
sourcepub fn send_response<const N: usize>(
io: &mut IO,
buf: &mut [u8],
response: &Response<'_, '_, N>
) -> Result<usize>
pub fn send_response<const N: usize>( io: &mut IO, buf: &mut [u8], response: &Response<'_, '_, N> ) -> Result<usize>
Send websocket upgrade response to IO source, return the number of bytes transmitted. Response data are encoded to the provided buffer.
This function will block until all data are written to IO source or an error occurs.
sourcepub unsafe fn recv_request<'h, 'b: 'h, const N: usize>(
io: &mut IO,
buf: &mut [u8],
request: &mut Request<'h, 'b, N>
) -> Result<usize>
pub unsafe fn recv_request<'h, 'b: 'h, const N: usize>( io: &mut IO, buf: &mut [u8], request: &mut Request<'h, 'b, N> ) -> Result<usize>
Receive websocket upgrade request from IO source, return
the number of bytes transmitted.
Received data are stored in the provided buffer, and parsed
as Request
.
This function will block on reading data, until there is enough data to parse a request or an error occurs.
Safety
Caller must not modify the buffer while request
is in use,
otherwise it is undefined behavior!
sourcepub fn accept(
io: IO,
buf: &mut [u8],
host: &str,
path: &str
) -> Result<Stream<IO, Role>>
pub fn accept( io: IO, buf: &mut [u8], host: &str, path: &str ) -> Result<Stream<IO, Role>>
Perform a simple websocket server handshake, return a new websocket stream.
This function is a combination of recv_request
and send_response
, without accessing Request
.
It will block until the handshake completes, or an error occurs.
source§impl<IO: AsyncRead + AsyncWrite + Unpin, Role: ClientRole> Endpoint<IO, Role>
impl<IO: AsyncRead + AsyncWrite + Unpin, Role: ClientRole> Endpoint<IO, Role>
sourcepub async fn send_request_async<'h, 'b: 'h, const N: usize>(
io: &mut IO,
buf: &mut [u8],
request: &Request<'h, 'b, N>
) -> Result<usize>
pub async fn send_request_async<'h, 'b: 'h, const N: usize>( io: &mut IO, buf: &mut [u8], request: &Request<'h, 'b, N> ) -> Result<usize>
Async version of send_request
.
sourcepub async unsafe fn recv_response_async<'h, 'b: 'h, const N: usize>(
io: &mut IO,
buf: &mut [u8],
response: &mut Response<'h, 'b, N>
) -> Result<usize>
pub async unsafe fn recv_response_async<'h, 'b: 'h, const N: usize>( io: &mut IO, buf: &mut [u8], response: &mut Response<'h, 'b, N> ) -> Result<usize>
Async version of recv_response
.
Safety
Caller must not modify the buffer while response
is in use,
otherwise it is undefined behavior!
source§impl<IO: AsyncRead + AsyncWrite + Unpin, Role: ServerRole> Endpoint<IO, Role>
impl<IO: AsyncRead + AsyncWrite + Unpin, Role: ServerRole> Endpoint<IO, Role>
sourcepub async fn send_response_async<const N: usize>(
io: &mut IO,
buf: &mut [u8],
response: &Response<'_, '_, N>
) -> Result<usize>
pub async fn send_response_async<const N: usize>( io: &mut IO, buf: &mut [u8], response: &Response<'_, '_, N> ) -> Result<usize>
Async version of send_response
.
sourcepub async unsafe fn recv_request_async<'h, 'b: 'h, const N: usize>(
io: &mut IO,
buf: &mut [u8],
request: &mut Request<'h, 'b, N>
) -> Result<usize>
pub async unsafe fn recv_request_async<'h, 'b: 'h, const N: usize>( io: &mut IO, buf: &mut [u8], request: &mut Request<'h, 'b, N> ) -> Result<usize>
Async version of recv_request
.
Safety
Caller must not modify the buffer while request
is in use,
otherwise it is undefined behavior!