1.42 <GIOStream>

Class: <GIOStream>

It derives from <GObject>.

<GIOStream> represents an object that has both read and write streams. Generally the two streams act as separate input and output streams, but they share some common resources and state. For instance, for seekable streams, both streams may use the same position.

Examples of <GIOStream> objects are <GSocketConnection>, which represents a two-way network connection; and <GFileIOStream>, which represents a file handle opened in read-write mode.

To do the actual reading and writing you need to get the substreams with iostream:get-input-stream and iostream:get-output-stream.

The <GIOStream> object owns the input and the output streams, not the other way around, so keeping the substreams alive will not keep the <GIOStream> object alive. If the <GIOStream> object is freed it will be closed, thus closing the substreams, so even if the substreams stay alive they will always return closed for all operations.

To close a stream use iostream:close? which will close the common stream object and also the individual substreams. You can also close the substreams themselves. In most cases this only marks the substream as closed, so further I/O on it fails but common state in the <GIOStream> may still be open. However, some streams may support ‘half-closed’ states where one direction of the stream is actually shut down.

Operations on <GIOStream>s cannot be started while another operation on the <GIOStream> or its substreams is in progress. Specifically, an application can read from the <GInputStream> and write to the <GOutputStream> simultaneously (either in separate threads, or as asynchronous operations in the same thread), but an application cannot start any <GIOStream> operation while there is a <GIOStream>, <GInputStream> or <GOutputStream> operation in progress, and an application can’t start any <GInputStream> or <GOutputStream> operation while there is a <GIOStream> operation in progress.

This is a product of individual stream operations being associated with a given <GMainContext> (the thread-default context at the time the operation was started), rather than entire streams being associated with a single <GMainContext>.

GIO may run operations on <GIOStream>s from other (worker) threads, and this may be exposed to application code in the behaviour of wrapper streams, such as <GBufferedInputStream> or <GTlsConnection>. With such wrapper APIs, application code may only run operations on the base (wrapped) stream when the wrapper stream is idle. Note that the semantics of such operations may not be well-defined due to the state the wrapper stream leaves the base stream in (though they are guaranteed not to crash).

Fields

parent-instance

Properties

Property: iostream:closed self

Whether the stream is closed.

Its value is a boolean.

It is read only.

Property: iostream:input-stream self

The <GInputStream> to read from.

Its value is a <GInputStream>, or #f.

It is read only.

Property: iostream:output-stream self

The <GOutputStream> to write to.

Its value is a <GOutputStream>, or #f.

It is read only.

Procedures

Method: iostream:clear-pending self
Method: clear-pending self

Clears the pending flag on self.

self

Passed: a <GIOStream>.

a <GIOStream>

Method: iostream:close-async self io-priority [cancellable] [callback]
Method: close-async self io-priority [cancellable] [callback]

Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call iostream:close-finish? to get the result of the operation.

For behaviour details see iostream:close?.

The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

self

Passed: a <GIOStream>.

a <GIOStream>

io-priority

Passed: a 32-bit integer.

the io priority of the request

cancellable

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

optional cancellable object

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback to call when the request is satisfied

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

the data to pass to callback function

Method: iostream:close-finish? self result ⇒ %return
Method: close-finish? self result ⇒ %return

Closes a stream.

self

Passed: a <GIOStream>.

a <GIOStream>

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a boolean.

#t if stream was successfully closed, #f otherwise.

Method: iostream:close? self [cancellable] ⇒ %return
Method: close? self [cancellable] ⇒ %return

Closes the stream, releasing resources related to it. This will also close the individual input and output streams, if they are not already closed.

Once the stream is closed, all other operations will return closed. Closing a stream multiple times will not return an error.

Closing a stream will automatically flush any outstanding buffers in the stream.

Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return closed for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written.

If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error cancelled will be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn’t block to e.g. check errors.

The default implementation of this method just calls close on the individual input/output streams.

self

Passed: a <GIOStream>.

a <GIOStream>

cancellable

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

optional <GCancellable> object, #f to ignore

%return

Returned: a boolean.

#t on success, #f on failure

Method: iostream:get-input-stream self ⇒ %return
Method: get-input-stream self ⇒ %return

Gets the input stream for this object. This is used for reading.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a <GInputStream>.

a <GInputStream>, owned by the <GIOStream>. Do not free.

Method: iostream:get-output-stream self ⇒ %return
Method: get-output-stream self ⇒ %return

Gets the output stream for this object. This is used for writing.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a <GOutputStream>.

a <GOutputStream>, owned by the <GIOStream>. Do not free.

Method: iostream:has-pending? self ⇒ %return
Method: has-pending? self ⇒ %return

Checks if a stream has pending actions.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a boolean.

#t if self has pending actions.

Method: iostream:is-closed? self ⇒ %return
Method: is-closed? self ⇒ %return

Checks if a stream is closed.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a boolean.

#t if the stream is closed.

Method: iostream:set-pending? self ⇒ %return
Method: set-pending? self ⇒ %return

Sets self to have actions pending. If the pending flag is already set or self is closed, it will return #f and set error.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a boolean.

#t if pending was previously unset and is now set.

Method: iostream:splice-async self stream2 flags io-priority [cancellable] [callback]
Method: splice-async self stream2 flags io-priority [cancellable] [callback]

Asynchronously splice the output stream of self to the input stream of stream2, and splice the output stream of stream2 to the input stream of self.

When the operation is finished callback will be called. You can then call iostream:splice-finish? to get the result of the operation.

self

Passed: a <GIOStream>.

a <GIOStream>.

stream2

Passed: a <GIOStream>.

a <GIOStream>.

flags

Passed: a <GIOStreamSpliceFlags>, or a list of its symbols, or one of them.

a set of <GIOStreamSpliceFlags>.

io-priority

Passed: a 32-bit integer.

the io priority of the request.

cancellable

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

optional <GCancellable> object, #f to ignore.

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback to call when the request is satisfied

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

the data to pass to callback function

Procedure: iostream:splice-finish? result ⇒ %return

Finishes an asynchronous io stream splice operation.

result

Passed: a <GAsyncResult>.

a <GAsyncResult>.

%return

Returned: a boolean.

#t on success, #f otherwise.

Virtual methods

Virtual method: iostream:do-close-async implementor self io-priority [cancellable] [callback]

Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call iostream:close-finish? to get the result of the operation.

For behaviour details see iostream:close?.

The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

To override it in a new class, give register-type #:vfuncs `((close-async . ,procedure)). The procedure is called as (procedure self io-priority cancellable callback user-data).

implementor

Passed: the class whose implementation to call: <GIOStream>, or a class that derives from it, or its GType number.

self

Passed: a <GIOStream>.

a <GIOStream>

io-priority

Passed: a 32-bit integer.

the io priority of the request

cancellable

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

optional cancellable object

callback

Passed, or left out: a procedure, or #f.

a GAsyncReadyCallback to call when the request is satisfied

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

the data to pass to callback function

Virtual method: iostream:do-close-finish implementor self result ⇒ %return

Closes a stream.

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

implementor

Passed: the class whose implementation to call: <GIOStream>, or a class that derives from it, or its GType number.

self

Passed: a <GIOStream>.

a <GIOStream>

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a boolean.

#t if stream was successfully closed, #f otherwise.

Virtual method: iostream:do-close-fn implementor self [cancellable] ⇒ %return

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

implementor

Passed: the class whose implementation to call: <GIOStream>, or a class that derives from it, or its GType number.

self

Passed: a <GIOStream>.

cancellable

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

%return

Returned: a boolean.

Virtual method: iostream:do-get-input-stream implementor self ⇒ %return

Gets the input stream for this object. This is used for reading.

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

implementor

Passed: the class whose implementation to call: <GIOStream>, or a class that derives from it, or its GType number.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a <GInputStream>.

a <GInputStream>, owned by the <GIOStream>. Do not free.

Virtual method: iostream:do-get-output-stream implementor self ⇒ %return

Gets the output stream for this object. This is used for writing.

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

implementor

Passed: the class whose implementation to call: <GIOStream>, or a class that derives from it, or its GType number.

self

Passed: a <GIOStream>.

a <GIOStream>

%return

Returned: a <GOutputStream>.

a <GOutputStream>, owned by the <GIOStream>. Do not free.