How to create PollableOutputStream for OutputStream?

Should I use dynamic cast to create it for OutputStream object (received from SocketConnection in my case)?

Hi,

No, that doesn’t work like that.
Gio.PollableOutputStream is an interface, not all OutputStreams implement it, so there is no guarantee you can cast it.
Depending on the type of socket, the operating system, etc…, an OutputStream may or may not be pollable.

You can use GObject.type_is_a to check if a stream object implements PollableOutputStream. If yes, then only you can cast it.

1 Like

Thanks, seems I found solution: it’s into_async_read_write method (in Rust):

It return reference to PollableInputStream / PollableOutputStream from input_stream / output_stream getters without any cast.

It does the casts internally. The correct solution is your_stream.dynamic_cast::<gio::PollableOutputStream>().

1 Like

Also please put the correct tags on your posts.

Could you explain please about tags I should remove or append here?
Tried gio but not found in list, must I remove glib one?

glib is the tag for glib / gio / gobject / gthread / gmodule topics.

$ dpkg -L libglib2.0-0t64:amd64 | grep so.0$

/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
/usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
/usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0
1 Like

Your question is specific to Rust, so that one. Otherwise this looks OK