[][src]Trait libuv::handles::streams::stream::StreamTrait

pub trait StreamTrait: ToStream {
    fn shutdown<CB: Into<ShutdownCB<'static>>>(
        &mut self,
        cb: CB
    ) -> Result<ShutdownReq> { ... }
fn listen<CB: Into<ConnectionCB<'static>>>(
        &mut self,
        backlog: i32,
        cb: CB
    ) -> Result<()> { ... }
fn accept(&mut self, client: &mut StreamHandle) -> Result<()> { ... }
fn read_start<ACB: Into<AllocCB<'static>>, RCB: Into<ReadCB<'static>>>(
        &mut self,
        alloc_cb: ACB,
        read_cb: RCB
    ) -> Result<()> { ... }
fn read_stop(&mut self) -> Result<()> { ... }
fn write<CB: Into<WriteCB<'static>>>(
        &mut self,
        bufs: &[impl BufTrait],
        cb: CB
    ) -> Result<WriteReq> { ... }
fn write2<CB: Into<WriteCB<'static>>>(
        &mut self,
        send_handle: &StreamHandle,
        bufs: &[impl BufTrait],
        cb: CB
    ) -> Result<WriteReq> { ... }
fn try_write(&mut self, bufs: &[impl BufTrait]) -> Result<i32> { ... }
fn is_readable(&self) -> bool { ... }
fn is_writable(&self) -> bool { ... }
fn set_blocking(&mut self, blocking: bool) -> Result<()> { ... }
fn get_write_queue_size(&self) -> usize { ... } }

Provided methods

fn shutdown<CB: Into<ShutdownCB<'static>>>(
    &mut self,
    cb: CB
) -> Result<ShutdownReq>

Shutdown the outgoing (write) side of a duplex stream. It waits for pending write requests to complete. The handle should refer to a initialized stream. The cb is called after shutdown is complete at which point the returned ShutdownReq is automatically destroy()'d.

fn listen<CB: Into<ConnectionCB<'static>>>(
    &mut self,
    backlog: i32,
    cb: CB
) -> Result<()>

Start listening for incoming connections. backlog indicates the number of connections the kernel might queue, same as listen(2). When a new incoming connection is received the uv_connection_cb callback is called.

fn accept(&mut self, client: &mut StreamHandle) -> Result<()>

This call is used in conjunction with listen() to accept incoming connections. Call this function after receiving the connection callback to accept the connection. Before calling this function the client handle must be initialized.

When the connection callback is called it is guaranteed that this function will complete successfully the first time. If you attempt to use it more than once, it may fail. It is suggested to only call this function once per connection callback.

Note: server and client must be handles running on the same loop.

fn read_start<ACB: Into<AllocCB<'static>>, RCB: Into<ReadCB<'static>>>(
    &mut self,
    alloc_cb: ACB,
    read_cb: RCB
) -> Result<()>

Read data from an incoming stream. The read_cb callback will be made several times until there is no more data to read or read_stop() is called.

fn read_stop(&mut self) -> Result<()>

Stop reading data from the stream. The uv_read_cb callback will no longer be called.

This function is idempotent and may be safely called on a stopped stream.

fn write<CB: Into<WriteCB<'static>>>(
    &mut self,
    bufs: &[impl BufTrait],
    cb: CB
) -> Result<WriteReq>

Write data to stream. Buffers are written in order.

Note: The memory pointed to by the buffers must remain valid until the callback gets called.

fn write2<CB: Into<WriteCB<'static>>>(
    &mut self,
    send_handle: &StreamHandle,
    bufs: &[impl BufTrait],
    cb: CB
) -> Result<WriteReq>

Extended write function for sending handles over a pipe. The pipe must be initialized with ipc == 1.

Note: send_handle must be a TCP socket or pipe, which is a server or a connection (listening or connected state). Bound sockets or pipes will be assumed to be servers.

Note: The memory pointed to by the buffers must remain valid until the callback gets called.

fn try_write(&mut self, bufs: &[impl BufTrait]) -> Result<i32>

Same as write(), but won’t queue a write request if it can’t be completed immediately.

Will return number of bytes written (can be less than the supplied buffer size).

fn is_readable(&self) -> bool

Returns true if the stream is readable, false otherwise.

fn is_writable(&self) -> bool

Returns true if the stream is writable, false otherwise.

fn set_blocking(&mut self, blocking: bool) -> Result<()>

Enable or disable blocking mode for a stream.

When blocking mode is enabled all writes complete synchronously. The interface remains unchanged otherwise, e.g. completion or failure of the operation will still be reported through a callback which is made asynchronously.

Warning: Relying too much on this API is not recommended. It is likely to change significantly in the future.

Currently only works on Windows for PipeHandles. On UNIX platforms, all Stream handles are supported.

Also libuv currently makes no ordering guarantee when the blocking mode is changed after write requests have already been submitted. Therefore it is recommended to set the blocking mode immediately after opening or creating the stream.

fn get_write_queue_size(&self) -> usize

Returns the size of the write queue.

Loading content...

Implementors

impl StreamTrait for PipeHandle[src]

impl StreamTrait for StreamHandle[src]

impl StreamTrait for TcpHandle[src]

impl StreamTrait for TtyHandle[src]

impl StreamTrait for UdpHandle[src]

Loading content...