Struct mio_httpc::WebSocket

source ·
pub struct WebSocket { /* private fields */ }
Expand description

WebSocket interface.

WebSocket does not send pings/pongs automatically or close replies.

If received ping, you should send pong back. You can also just send pong which will not invoke a response. You should send ping periodically as you never know if your connection is actually alive without it.

If WSPacket::Close() returned you should call close and then finish. If you want to initiate close, you should call close and wait for WSPacket::Close(), then call finish. That is the standard way of closing ws connections.

Implementations§

source§

impl WebSocket

source

pub fn call(&self) -> &Call

source

pub fn empty() -> WebSocket

source

pub fn is_empty(&self) -> bool

source

pub fn is_active(&self) -> bool

True if websocket is established. False if still initiating or closed.

source

pub fn sendq_len(&self) -> usize

How many bytes are in send buffer waiting to be sent. Does not take into account any send_bin_inplace packets.

source

pub fn is_ref(&self, r: CallRef) -> bool

source

pub fn is_call(&self, cid: &Option<CallRef>) -> bool

For quick comparison with httpc::event response. If cid is none will return false.

source

pub fn is_opt_call(a: &Option<WebSocket>, b: &Option<CallRef>) -> bool

If using Option in a struct, you can quickly compare callid from httpc::event. If either is none will return false.

source

pub fn ping(&mut self, body: Option<&[u8]>)

Ping server. Body if present is capped at 125 bytes.

source

pub fn pong(&mut self, body: Option<&[u8]>)

A reply to ping or not. Both are valid. Body if present is capped at 125 bytes.

source

pub fn close(&mut self, status: Option<u16>, body: Option<&[u8]>)

A reply to close or initiate close. close must be sent by both parties. Body if present is capped at 125 bytes.

source

pub fn finish(self, htp: &mut Httpc)

Actually close connection. If any other call returns error, you should always call finish afterwards.

source

pub fn finish_inplace(&mut self, htp: &mut Httpc)

Actually close connection and replace self with an empty websocket.

source

pub fn send_text(&mut self, fin: bool, pkt: &str)

Send text packet. Data gets copied out into an internal buffer, as it must be masked before sending. No bytes will have been sent after calling this. Actual sending is done by recv_packet or perform.

source

pub fn send_bin(&mut self, fin: bool, pkt: &[u8])

Send binary packet. Data gets copied out into an internal buffer, as it must be masked before sending. No bytes will have been sent after calling this. Actual sending is done by recv_packet or perform.

source

pub fn send_bin_inplace( &mut self, htp: &mut Httpc, poll: &Registry, fin: bool, pkt: &mut [u8] ) -> Result<usize>

Send websocket packet. It will create a frame for entire size of pkt slice. It is assumed slice always starts at unsent data. If pkt was not sent completely it will remember how many bytes it has leftover for current packet. You must always use previous result to move pkt slice forward.

If starting from the middle, fin is ignored and will be used to start the next packet.

inplace send will mask pkt directly and send it. This is the most efficient method but leaves pkt scrambled.

source

pub fn recv_packet<'a>( &mut self, htp: &'a mut Httpc, poll: &Registry ) -> Result<WSPacket<'a>>

You should call this in a loop until you get WSPacket::None.

source

pub fn perform(&mut self, htp: &mut Httpc, poll: &Registry) -> Result<()>

Perform socket operation.

Auto Trait Implementations§

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, 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