pub struct Connecting<S> { /* private fields */ }Expand description
A WebSocket connection in the handshake phase.
Drive the handshake by calling poll() when the socket
is ready. Returns Client<S> when complete.
Check wants_read() / wants_write()
to determine which readiness event to wait for in your event loop.
§Usage
ⓘ
use nexus_web::ws::{Connecting, ClientBuilder};
let tcp = TcpStream::connect("exchange.com:443")?;
tcp.set_nonblocking(true)?;
let mut connecting = ClientBuilder::new()
.begin_connect(tcp, "wss://exchange.com/ws")?;
// In your event loop:
loop {
// ... poll for socket readiness ...
if let Some(ws) = connecting.poll()? {
// Handshake complete — ws.recv() is now available
break;
}
}Implementations§
Source§impl<S: Read + Write> Connecting<S>
impl<S: Read + Write> Connecting<S>
Sourcepub fn poll(&mut self) -> Result<Option<Client<S>>, Error>
pub fn poll(&mut self) -> Result<Option<Client<S>>, Error>
Drive the handshake forward. Non-blocking.
Returns Ok(None) while in progress, Ok(Some(ws)) when the
connection is ready and recv() can be called.
Call when the socket is readable or writable (check
wants_read() / wants_write()).
On WouldBlock, returns Ok(None) — call again when the socket
is ready.
Sourcepub fn wants_write(&self) -> bool
pub fn wants_write(&self) -> bool
Whether the handshake needs to write to the socket.
Sourcepub fn wants_read(&self) -> bool
pub fn wants_read(&self) -> bool
Whether the handshake needs to read from the socket.
Sourcepub fn stream_mut(&mut self) -> &mut S
pub fn stream_mut(&mut self) -> &mut S
Mutable access to the underlying stream.
Trait Implementations§
Source§impl<S> Drop for Connecting<S>
impl<S> Drop for Connecting<S>
Auto Trait Implementations§
impl<S> Freeze for Connecting<S>where
S: Freeze,
impl<S> !RefUnwindSafe for Connecting<S>
impl<S> Send for Connecting<S>where
S: Send,
impl<S> Sync for Connecting<S>where
S: Sync,
impl<S> Unpin for Connecting<S>where
S: Unpin,
impl<S> UnsafeUnpin for Connecting<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for Connecting<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more