2.26 <GPollableOutputStream>

Interface: <GPollableOutputStream>

<GPollableOutputStream> is implemented by <GOutputStream>s that can be polled for readiness to write. This can be used when interfacing with a non-GIO API that expects UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.

Some classes may implement <GPollableOutputStream> but have only certain instances of that class be pollable. If pollable-output-stream:can-poll? returns false, then the behavior of other <GPollableOutputStream> methods is undefined.

Procedures

Method: pollable-output-stream:can-poll? self ⇒ %return
Method: can-poll? self ⇒ %return

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 #f, 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.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>.

%return

Returned: a boolean.

#t if self is pollable, #f if not.

Method: pollable-output-stream:create-source self [cancellable] ⇒ %return
Method: create-source self [cancellable] ⇒ %return

Creates a <GSource> that triggers when self can be written, or cancellable is triggered or an error occurs. The callback on the source is of the GPollableSourceFunc type.

As with pollable-output-stream:is-writable?, it is possible that the stream may not actually be writable even after the source triggers, so you should use pollable-output-stream:write-nonblocking rather than output-stream:write from the callback.

The behaviour of this method is undefined if pollable-output-stream:can-poll? returns #f for self.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>.

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

%return

Returned: a <GSource>.

a new <GSource>

Method: pollable-output-stream:is-writable? self ⇒ %return
Method: is-writable? self ⇒ %return

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 output-stream:write after this returns #t would still block. To guarantee non-blocking behavior, you should always use pollable-output-stream:write-nonblocking, which will return a would-block error rather than blocking.

The behaviour of this method is undefined if pollable-output-stream:can-poll? returns #f for self.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>.

%return

Returned: a boolean.

#t if self is writable, #f if not. If an error has occurred on self, this will result in pollable-output-stream:is-writable? returning #t, and the next attempt to write will return the error.

Method: pollable-output-stream:write-nonblocking self buffer [cancellable] ⇒ %return
Method: write-nonblocking self buffer [cancellable] ⇒ %return

Attempts to write up to count bytes from buffer to self, as with output-stream:write. If self is not currently writable, this will immediately return would-block, and you can use 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 would-block 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 pollable-output-stream:can-poll? returns #f for self.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>

buffer

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

a buffer to write data from

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

%return

Returned: a 64-bit integer.

the number of bytes written, or -1 on error (including would-block).

count

Not passed: guile-gi gives the length of buffer.

the number of bytes you want to write

Virtual methods

Virtual method: pollable-output-stream:do-can-poll implementor self ⇒ %return

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 #f, 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.

To override it in a new class, give register-type #:vfuncs `((can-poll . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GPollableOutputStream>, or its GType number.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>.

%return

Returned: a boolean.

#t if self is pollable, #f if not.

Virtual method: pollable-output-stream:do-create-source implementor self [cancellable] ⇒ %return

Creates a <GSource> that triggers when self can be written, or cancellable is triggered or an error occurs. The callback on the source is of the GPollableSourceFunc type.

As with pollable-output-stream:is-writable?, it is possible that the stream may not actually be writable even after the source triggers, so you should use pollable-output-stream:write-nonblocking rather than output-stream:write from the callback.

The behaviour of this method is undefined if pollable-output-stream:can-poll? returns #f for self.

To override it in a new class, give register-type #:vfuncs `((create-source . ,procedure)). The procedure is called as (procedure self cancellable) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GPollableOutputStream>, or its GType number.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>.

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable>, or #f

%return

Returned: a <GSource>.

a new <GSource>

Virtual method: pollable-output-stream:do-is-writable implementor self ⇒ %return

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 output-stream:write after this returns #t would still block. To guarantee non-blocking behavior, you should always use pollable-output-stream:write-nonblocking, which will return a would-block error rather than blocking.

The behaviour of this method is undefined if pollable-output-stream:can-poll? returns #f for self.

To override it in a new class, give register-type #:vfuncs `((is-writable . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GPollableOutputStream>, or its GType number.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>.

%return

Returned: a boolean.

#t if self is writable, #f if not. If an error has occurred on self, this will result in pollable-output-stream:is-writable? returning #t, and the next attempt to write will return the error.

Virtual method: pollable-output-stream:do-write-nonblocking implementor self buffer ⇒ %return

Attempts to write up to count bytes from buffer to self, as with output-stream:write. If self is not currently writable, this will immediately return would-block, and you can use 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 would-block 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 pollable-output-stream:can-poll? returns #f for self.

To override it in a new class, give register-type #:vfuncs `((write-nonblocking . ,procedure)). The procedure is called as (procedure self buffer) ⇒ %return.

implementor

Passed: the class whose implementation to call: a class that implements <GPollableOutputStream>, or its GType number.

self

Passed: a <GPollableOutputStream>.

a <GPollableOutputStream>

buffer

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer, or #f.

a buffer to write data from

%return

Returned: a 64-bit integer.

the number of bytes written, or -1 on error (including would-block).

count

Not passed: guile-gi gives the length of buffer.

the number of bytes you want to write