2.25 <GPollableInputStream>

Interface: <GPollableInputStream>

<GPollableInputStream> is implemented by <GInputStream>s that can be polled for readiness to read. 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 <GPollableInputStream> but have only certain instances of that class be pollable. If pollable-input-stream:can-poll? returns false, then the behavior of other <GPollableInputStream> methods is undefined.

Procedures

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

Checks if self is actually pollable. Some classes may implement <GPollableInputStream> but have only certain instances of that class be pollable. If this method returns #f, then the behavior of other <GPollableInputStream> 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 <GPollableInputStream>.

a <GPollableInputStream>.

%return

Returned: a boolean.

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

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

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

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

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

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>.

cancellable

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

a <GCancellable>, or #f

%return

Returned: a <GSource>.

a new <GSource>

Method: pollable-input-stream:is-readable? self ⇒ %return
Method: is-readable? self ⇒ %return

Checks if self can be read.

Note that some stream types may not be able to implement this 100% reliably, and it is possible that a call to input-stream:read! after this returns #t would still block. To guarantee non-blocking behavior, you should always use pollable-input-stream:read-nonblocking!, which will return a would-block error rather than blocking.

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

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>.

%return

Returned: a boolean.

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

Method: pollable-input-stream:read-nonblocking! self buffer [cancellable] ⇒ %return buffer
Method: read-nonblocking! self buffer [cancellable] ⇒ %return buffer

Attempts to read up to count bytes from self into buffer, as with input-stream:read!. If self is not currently readable, this will immediately return would-block, and you can use pollable-input-stream:create-source to create a <GSource> that will be triggered when self is readable.

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.

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

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>

buffer

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer. It is filled in, and returned: a bytevector.

a buffer to read data into (which should be at least count bytes long).

cancellable

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

a <GCancellable>, or #f

%return

Returned: a 64-bit integer.

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

count

Not returned: it is the length of buffer.

the number of bytes you want to read

Virtual methods

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

Checks if self is actually pollable. Some classes may implement <GPollableInputStream> but have only certain instances of that class be pollable. If this method returns #f, then the behavior of other <GPollableInputStream> 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 <GPollableInputStream>, or its GType number.

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>.

%return

Returned: a boolean.

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

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

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

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

The behaviour of this method is undefined if pollable-input-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 <GPollableInputStream>, or its GType number.

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>.

cancellable

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

a <GCancellable>, or #f

%return

Returned: a <GSource>.

a new <GSource>

Virtual method: pollable-input-stream:do-is-readable implementor self ⇒ %return

Checks if self can be read.

Note that some stream types may not be able to implement this 100% reliably, and it is possible that a call to input-stream:read! after this returns #t would still block. To guarantee non-blocking behavior, you should always use pollable-input-stream:read-nonblocking!, which will return a would-block error rather than blocking.

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

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

implementor

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

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>.

%return

Returned: a boolean.

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

Virtual method: pollable-input-stream:do-read-nonblocking implementor self buffer ⇒ %return buffer

Attempts to read up to count bytes from self into buffer, as with input-stream:read!. If self is not currently readable, this will immediately return would-block, and you can use pollable-input-stream:create-source to create a <GSource> that will be triggered when self is readable.

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.

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

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

implementor

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

self

Passed: a <GPollableInputStream>.

a <GPollableInputStream>

buffer

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer, or #f. It is filled in, and returned: a bytevector, or #f.

a buffer to read data into (which should be at least count bytes long).

%return

Returned: a 64-bit integer.

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

count

Not returned: it is the length of buffer.

the number of bytes you want to read