Struct lightws::endpoint::Endpoint

source ·
pub struct Endpoint<IO, Role> { /* private fields */ }
Expand description

Handshake endpoint.

Implementations§

source§

impl<IO: Read + Write, Role: ClientRole> Endpoint<IO, Role>

source

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.

source

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!

source

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>

source

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.

source

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!

source

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>

source

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.

source

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

pub async fn connect_async( io: IO, buf: &mut [u8], host: &str, path: &str ) -> Result<Stream<IO, Role>>

Async version of connect.

source§

impl<IO: AsyncRead + AsyncWrite + Unpin, Role: ServerRole> Endpoint<IO, Role>

source

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.

source

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!

source

pub async fn accept_async( io: IO, buf: &mut [u8], host: &str, path: &str ) -> Result<Stream<IO, Role>>

Async version of accept.

Auto Trait Implementations§

§

impl<IO, Role> RefUnwindSafe for Endpoint<IO, Role>
where IO: RefUnwindSafe, Role: RefUnwindSafe,

§

impl<IO, Role> Send for Endpoint<IO, Role>
where IO: Send, Role: Send,

§

impl<IO, Role> Sync for Endpoint<IO, Role>
where IO: Sync, Role: Sync,

§

impl<IO, Role> Unpin for Endpoint<IO, Role>
where IO: Unpin, Role: Unpin,

§

impl<IO, Role> UnwindSafe for Endpoint<IO, Role>
where IO: UnwindSafe, Role: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V