pub trait PollableOutputStreamExt: IsA<PollableOutputStream> + 'static {
// Provided methods
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
Trait containing all PollableOutputStream
methods.
§Implementors
ConverterOutputStream
, MemoryOutputStream
, PollableOutputStream
, UnixOutputStream
Provided Methods§
Sourcefn can_poll(&self) -> bool
fn can_poll(&self) -> bool
Checks if @self is actually pollable. Some classes may implement
#GPollableOutputStream but have only certain instances of that
class be pollable. If this method returns false
, then the behavior
of other #GPollableOutputStream 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
Sourcefn is_writable(&self) -> bool
fn is_writable(&self) -> bool
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 g_output_stream_write()
after this returns true
would still block. To guarantee
non-blocking behavior, you should always use
g_pollable_output_stream_write_nonblocking(), which will return a
IOErrorEnum::WouldBlock
error rather than blocking.
The behaviour of this method is undefined if
g_pollable_output_stream_can_poll() returns false
for @self.
§Returns
true
if @self is writable, false
if not. If an error
has occurred on @self, this will result in
g_pollable_output_stream_is_writable() returning true
, and the
next attempt to write will return the error.
Sourcefn write_nonblocking(
&self,
buffer: &[u8],
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<isize, Error>
fn write_nonblocking( &self, buffer: &[u8], cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<isize, Error>
Attempts to write up to @count bytes from @buffer to @self, as
with g_output_stream_write(). If @self is not currently writable,
this will immediately return IOErrorEnum::WouldBlock
, and you can
use g_pollable_output_stream_create_source() to create a #GSource
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.
The behaviour of this method is undefined if
g_pollable_output_stream_can_poll() returns false
for @self.
§buffer
a buffer to write data from
§cancellable
a #GCancellable, or None
§Returns
the number of bytes written, or -1 on error (including
IOErrorEnum::WouldBlock
).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.