pub trait PollableOutputStreamExt: 'static {
    fn can_poll(&self) -> bool;
    fn is_writable(&self) -> bool;
    fn write_nonblocking(
        &self,
        buffer: &[u8],
        cancellable: Option<&impl IsA<Cancellable>>
    ) -> Result<isize, Error>; }
Expand description

Required Methods

Checks if self is actually pollable. Some classes may implement PollableOutputStream but have only certain instances of that class be pollable. If this method returns false, then the behavior of other PollableOutputStream methods is undefined.

For any given stream, the value returned by this method is constant; a stream cannot switch from pollable to non-pollable or vice versa.

Returns

true if self is pollable, false if not.

Checks if self can be written.

Note that some stream types may not be able to implement this 100% reliably, and it is possible that a call to OutputStreamExt::write() after this returns true would still block. To guarantee non-blocking behavior, you should always use write_nonblocking(), which will return a IOErrorEnum::WouldBlock error rather than blocking.

Returns

true if self is writable, false if not. If an error has occurred on self, this will result in is_writable() returning true, and the next attempt to write will return the error.

Attempts to write up to count bytes from buffer to self, as with OutputStreamExt::write(). If self is not currently writable, this will immediately return IOErrorEnum::WouldBlock, and you can use PollableOutputStreamExtManual::create_source() to create a glib::Source that will be triggered when self is writable.

Note that since this method never blocks, you cannot actually use cancellable to cancel it. However, it will return an error if cancellable has already been cancelled when you call, which may happen if you call this method after a source triggers due to having been cancelled.

Also note that if IOErrorEnum::WouldBlock is returned some underlying transports like D/TLS require that you re-send the same buffer and count in the next write call.

buffer

a buffer to write data from

cancellable

a Cancellable, or None

Returns

the number of bytes written, or -1 on error (including IOErrorEnum::WouldBlock).

Implementors