[−][src]Trait in_stream::InStream
implement this trait to provide a stream endpoint / socket type connection works like combined std::io::{Read, Write}, but with generic types the underlying stream should be treated as non-blocking. For example, if this is a TLS stream, we may still need to complete a handshaking process before data can actually be written.
read
will return WouldBlock if there is no pending data to be read
write
will buffer any data if the stream is not ready to write
flush
will block until pending data has been written
Associated Constants
const URL_SCHEME: &'static str
your implementation should work with a single url scheme/protocol if you need to support multiple (i.e. ws:// vs wss://) consider using macros/code generation to DRY
Required methods
fn raw_connect<C: InStreamConfig>(url: &Url2, config: C) -> Result<Self>
create a new connection / stream of this type. this function does the actual work of connecting, but it is recommended your struct provide a wrapper with a concrete config type
fn remote_url(&self) -> Url2
access the remote url this connection represents
fn check_ready(&mut self) -> Result<bool>
process the stream to see if any remaining handshake items can be completed
returns true
if stream is set-up and ready to send/receive
note that you can write before this function returns true
but your messages may be buffered / sent later
fn read(&mut self, data: R) -> Result<usize>
non-blocking read. if R is an array-type, success result is number of elements read otherwise it is 1
fn write(&mut self, data: W) -> Result<usize>
buffered write. Implementors should buffer data on WouldBlock
fn flush(&mut self) -> Result<()>
blocking flush all pending buffered write data.
Implementors
impl<'_, '_> InStream<&'_ mut [u8], &'_ [u8]> for InStreamMem
[src]
const URL_SCHEME: &'static str
[src]
we want a url like mem://
fn raw_connect<C: InStreamConfig>(url: &Url2, config: C) -> Result<Self>
[src]
fn check_ready(&mut self) -> Result<bool>
[src]
fn remote_url(&self) -> Url2
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn flush(&mut self) -> Result<()>
[src]
impl<'_, '_> InStream<&'_ mut [u8], &'_ [u8]> for InStreamTcp
[src]
const URL_SCHEME: &'static str
[src]
tcp streams should use urls like tcp://