Struct mio_httpc::WebSocket [−][src]
pub struct WebSocket { /* fields omitted */ }
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.
Methods
impl WebSocket
[src]
impl WebSocket
pub fn call(&self) -> &Call
[src]
pub fn call(&self) -> &Call
pub fn empty() -> WebSocket
[src]
pub fn empty() -> WebSocket
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
pub fn is_active(&self) -> bool
[src]
pub fn is_active(&self) -> bool
True if websocket is established. False if still initiating or closed.
pub fn sendq_len(&self) -> usize
[src]
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.
pub fn is_ref(&self, r: CallRef) -> bool
[src]
pub fn is_ref(&self, r: CallRef) -> bool
pub fn is_call(&self, cid: &Option<CallRef>) -> bool
[src]
pub fn is_call(&self, cid: &Option<CallRef>) -> bool
For quick comparison with httpc::event response. If cid is none will return false.
pub fn is_opt_call(a: &Option<WebSocket>, b: &Option<CallRef>) -> bool
[src]
pub fn is_opt_call(a: &Option<WebSocket>, b: &Option<CallRef>) -> bool
If using Option
pub fn ping(&mut self, body: Option<&[u8]>)
[src]
pub fn ping(&mut self, body: Option<&[u8]>)
Ping server. Body if present is capped at 125 bytes.
pub fn pong(&mut self, body: Option<&[u8]>)
[src]
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.
pub fn close(&mut self, status: Option<u16>, body: Option<&[u8]>)
[src]
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.
pub fn finish(self, htp: &mut Httpc)
[src]
pub fn finish(self, htp: &mut Httpc)
Actually close connection. If any other call returns error, you should always call finish afterwards.
pub fn finish_inplace(&mut self, htp: &mut Httpc)
[src]
pub fn finish_inplace(&mut self, htp: &mut Httpc)
Actually close connection and replace self with an empty websocket.
pub fn send_text(&mut self, fin: bool, pkt: &str)
[src]
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.
pub fn send_bin(&mut self, fin: bool, pkt: &[u8])
[src]
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.
pub fn send_bin_inplace(
&mut self,
htp: &mut Httpc,
poll: &Poll,
fin: bool,
pkt: &mut [u8]
) -> Result<usize>
[src]
pub fn send_bin_inplace(
&mut self,
htp: &mut Httpc,
poll: &Poll,
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.
pub fn recv_packet<'a>(
&mut self,
htp: &'a mut Httpc,
poll: &Poll
) -> Result<WSPacket<'a>>
[src]
pub fn recv_packet<'a>(
&mut self,
htp: &'a mut Httpc,
poll: &Poll
) -> Result<WSPacket<'a>>
You should call this in a loop until you get WSPacket::None.
pub fn perform(&mut self, htp: &mut Httpc, poll: &Poll) -> Result<()>
[src]
pub fn perform(&mut self, htp: &mut Httpc, poll: &Poll) -> Result<()>
Perform socket operation.