IoChannel

class IoChannel(pointer: <Error class: unknown class><<Error class: unknown class>>, cleaner: <Error class: unknown class>? = null) : ProxyInstance

The GIOChannel data type aims to provide a portable method for using file descriptors, pipes, and sockets, and integrating them into the main event loop (see struct@GLib.MainContext). Currently, full support is available on UNIX platforms; support for Windows is only partially complete.

To create a new GIOChannel on UNIX systems use ctor@GLib.IOChannel.unix_new. This works for plain file descriptors, pipes and sockets. Alternatively, a channel can be created for a file in a system independent manner using ctor@GLib.IOChannel.new_file.

Once a GIOChannel has been created, it can be used in a generic manner with the functions method@GLib.IOChannel.read_chars, method@GLib.IOChannel.write_chars, method@GLib.IOChannel.seek_position, and method@GLib.IOChannel.shutdown.

To add a GIOChannel to the main event loop, use func@GLib.io_add_watch or func@GLib.io_add_watch_full. Here you specify which events you are interested in on the GIOChannel, and provide a function to be called whenever these events occur.

GIOChannel instances are created with an initial reference count of 1. method@GLib.IOChannel.ref and method@GLib.IOChannel.unref can be used to increment or decrement the reference count respectively. When the reference count falls to 0, the GIOChannel is freed. (Though it isn’t closed automatically, unless it was created using ctor@GLib.IOChannel.new_file.) Using func@GLib.io_add_watch or func@GLib.io_add_watch_full increments a channel’s reference count.

The new functions method@GLib.IOChannel.read_chars, method@GLib.IOChannel.read_line, method@GLib.IOChannel.read_line_string, method@GLib.IOChannel.read_to_end, method@GLib.IOChannel.write_chars, method@GLib.IOChannel.seek_position, and method@GLib.IOChannel.flush should not be mixed with the deprecated functions method@GLib.IOChannel.read, method@GLib.IOChannel.write, and method@GLib.IOChannel.seek on the same channel.

Skipped during bindings generation

  • parameter length: length: Out parameter is not supported

  • parameter bytes_read: Unsupported pointer to primitive type

  • parameter buf: buf: Out parameter is not supported

  • parameter str_return: str_return: Out parameter is not supported

  • parameter terminator_pos: Unsupported pointer to primitive type

  • parameter str_return: str_return: Out parameter is not supported

  • parameter thechar: thechar: Out parameter is not supported

  • parameter bytes_written: Unsupported pointer to primitive type

  • parameter buf: Array parameter of type guint8 is not supported

Constructors

Link copied to clipboard
constructor()

Allocate a new IoChannel.

constructor(scope: <Error class: unknown class>)

Allocate a new IoChannel using the provided AutofreeScope.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>, cleaner: <Error class: unknown class>? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val glibIOChannelPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val handle: <Error class: unknown class>?

Functions

Link copied to clipboard
fun close()

Close an IO channel. Any pending data to be written will be flushed, ignoring errors. The channel will not be freed until the last reference is dropped using g_io_channel_unref().

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compare two proxy instances for equality. This will compare both the type of the instances, and their memory addresses.

Link copied to clipboard
fun flush(): <Error class: unknown class><IoStatus>

Flushes the write buffer for the GIOChannel.

Link copied to clipboard

This function returns a #GIOCondition depending on whether there is data to be read/space to write data in the internal buffers in the #GIOChannel. Only the flags %G_IO_IN and %G_IO_OUT may be set.

Link copied to clipboard

Returns whether @channel is buffered.

Link copied to clipboard
fun getBufferSize(): <Error class: unknown class>

Gets the buffer size.

Link copied to clipboard

Returns whether the file/socket/whatever associated with @channel will be closed when @channel receives its final unref and is destroyed. The default value of this is true for channels created by g_io_channel_new_file (), and false for all other channels.

Link copied to clipboard

Gets the encoding for the input/output of the channel. The internal encoding is always UTF-8. The encoding null makes the channel safe for binary data.

Link copied to clipboard

Gets the current flags for a #GIOChannel, including read-only flags such as %G_IO_FLAG_IS_READABLE.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun init()

Initializes a #GIOChannel struct.

Link copied to clipboard
fun ref(): IoChannel

Increments the reference count of a #GIOChannel.

Link copied to clipboard
fun seek(offset: <Error class: unknown class>, type: SeekType): IoError

Sets the current position in the #GIOChannel, similar to the standard library function fseek().

Link copied to clipboard
fun seekPosition(offset: <Error class: unknown class>, type: SeekType): <Error class: unknown class><IoStatus>

Replacement for g_io_channel_seek() with the new API.

Link copied to clipboard
fun setBuffered(buffered: Boolean)

The buffering state can only be set if the channel's encoding is null. For any other encoding, the channel must be buffered.

Link copied to clipboard
fun setBufferSize(size: <Error class: unknown class>)

Sets the buffer size.

Link copied to clipboard
fun setCloseOnUnref(doClose: Boolean)

Whether to close the channel on the final unref of the #GIOChannel data structure. The default value of this is true for channels created by g_io_channel_new_file (), and false for all other channels.

Link copied to clipboard
fun setEncoding(encoding: String? = null): <Error class: unknown class><IoStatus>

Sets the encoding for the input/output of the channel. The internal encoding is always UTF-8. The default encoding for the external file is UTF-8.

Link copied to clipboard
fun setFlags(flags: IoFlags): <Error class: unknown class><IoStatus>

Sets the (writeable) flags in @channel to (@flags & %G_IO_FLAG_SET_MASK).

Link copied to clipboard
fun setLineTerm(lineTerm: String? = null, length: <Error class: unknown class>)

This sets the string that #GIOChannel uses to determine where in the file a line break occurs.

Link copied to clipboard
fun shutdown(flush: Boolean): <Error class: unknown class><IoStatus>

Close an IO channel. Any pending data to be written will be flushed if @flush is true. The channel will not be freed until the last reference is dropped using g_io_channel_unref().

Link copied to clipboard
fun unixGetFd(): <Error class: unknown class>

Returns the file descriptor of the #GIOChannel.

Link copied to clipboard
fun unref()

Decrements the reference count of a #GIOChannel.

Link copied to clipboard
fun writeUnichar(thechar: <Error class: unknown class>): <Error class: unknown class><IoStatus>

Writes a Unicode character to @channel. This function cannot be called on a channel with null encoding.