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().
Flushes the write buffer for the GIOChannel.
the status of the operation: One of GLib.IOStatus.NORMAL, GLib.IOStatus.AGAIN, or GLib.IOStatus.ERROR.
This function returns a GLib.IOCondition depending on whether there is data to be read/space to write data in the internal buffers in the GLib.IOChannel. Only the flags GLib.IOCondition.IN and GLib.IOCondition.OUT may be set.
Gets the buffer size.
the size of the buffer.
Returns whether channel is buffered.
true if the channel is buffered.
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.
true if the channel will be closed, false otherwise.
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.
A string containing the encoding, this string is owned by GLib and must not be freed.
Gets the current flags for a GLib.IOChannel, including read-only flags such as GLib.IOFlags.IS_READABLE.
The values of the flags GLib.IOFlags.IS_READABLE and GLib.IOFlags.IS_WRITABLE
are cached for internal use by the channel when it is created.
If they should change at some later point (e.g. partial shutdown
of a socket with the UNIX shutdown() function), the user
should immediately call g_io_channel_get_flags() to update
the internal values of these flags.
the flags which are set on the channel
This returns the string that GLib.IOChannel uses to determine
where in the file a line break occurs. A value of null
indicates autodetection. Since 2.84, the return value is always
nul-terminated.
The line termination string. This value is owned by GLib and must not be freed.
Initializes a GLib.IOChannel struct.
This is called by each of the above functions when creating a GLib.IOChannel, and so is not often needed by the application programmer (unless you are creating a new type of GLib.IOChannel).
Reads data from a GLib.IOChannel.
a buffer to read the data into (which should be at least count bytes long)
the number of bytes to read from the GLib.IOChannel
returns the number of bytes actually read
GLib.IOError.NONE if the operation was successful.
Replacement for g_io_channel_read() with the new API.
the status of the operation.
Reads a line, including the terminating character(s),
from a GLib.IOChannel into a newly-allocated string.
str_return will contain allocated memory if the return
is GLib.IOStatus.NORMAL.
the status of the operation.
Reads a line from a GLib.IOChannel, using a GLib.String as a buffer.
a GLib.String into which the line will be written. If buffer already contains data, the old data will be overwritten.
Optionalterminator_pos: numberlocation to store position of line terminator, or null
the status of the operation.
Reads all the remaining data from the file.
GLib.IOStatus.NORMAL on success. This function never returns GLib.IOStatus.EOF.
Reads a Unicode character from channel.
This function cannot be called on a channel with null encoding.
Increments the reference count of a GLib.IOChannel.
the channel that was passed in (since 2.6)
Sets the current position in the GLib.IOChannel, similar to the standard
library function fseek().
an offset, in bytes, which is added to the position specified by type
the position in the file, which can be GLib.SeekType.CUR (the current position), GLib.SeekType.SET (the start of the file), or GLib.SeekType.END (the end of the file)
GLib.IOError.NONE if the operation was successful.
Replacement for g_io_channel_seek() with the new API.
The offset in bytes from the position specified by type
a GLib.SeekType. The type GLib.SeekType.CUR is only allowed in those cases where a call to g_io_channel_set_encoding () is allowed. See the documentation for g_io_channel_set_encoding () for details.
the status of the operation.
Sets the buffer size.
the size of the buffer, or 0 to let GLib pick a good size
The buffering state can only be set if the channel's encoding
is null. For any other encoding, the channel must be buffered.
A buffered channel can only be set unbuffered if the channel's internal buffers have been flushed. Newly created channels or channels which have returned GLib.IOStatus.EOF not require such a flush. For write-only channels, a call to g_io_channel_flush () is sufficient. For all other channels, the buffers may be flushed by a call to g_io_channel_seek_position (). This includes the possibility of seeking with seek type GLib.SeekType.CUR and an offset of zero. Note that this means that socket-based channels cannot be set unbuffered once they have had data read from them.
On unbuffered channels, it is safe to mix read and write calls from the new and old APIs, if this is necessary for maintaining old code.
The default state of the channel is buffered.
whether to set the channel buffered or unbuffered
Whether to close the channel on the final unref of the GLib.IOChannel
data structure. The default value of this is true for channels
created by g_io_channel_new_file (), and false for all other channels.
Setting this flag to true for a channel you have already closed
can cause problems when the final reference to the GLib.IOChannel is dropped.
Whether to close the channel on the final unref of the GIOChannel data structure.
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.
The encoding null is safe to use with binary data.
The encoding can only be set if one of the following conditions is true:
The channel was just created, and has not been written to or read from yet.
The channel is write-only.
The channel is a file, and the file pointer was just repositioned
by a call to g_io_channel_seek_position(). (This flushes all the
internal buffers.)
The current encoding is null or UTF-8.
One of the (new API) read functions has just returned GLib.IOStatus.EOF
(or, in the case of g_io_channel_read_to_end(), GLib.IOStatus.NORMAL).
One of the functions g_io_channel_read_chars() or
g_io_channel_read_unichar() has returned GLib.IOStatus.AGAIN or
GLib.IOStatus.ERROR. This may be useful in the case of
GLib.ConvertError.ILLEGAL_SEQUENCE.
Returning one of these statuses from g_io_channel_read_line(),
g_io_channel_read_line_string(), or g_io_channel_read_to_end()
does not guarantee that the encoding can be changed.
Channels which do not meet one of the above conditions cannot call
g_io_channel_seek_position() with an offset of GLib.SeekType.CUR, and, if
they are "seekable", cannot call g_io_channel_write_chars() after
calling one of the API "read" functions.
Optionalencoding: stringthe encoding type
GLib.IOStatus.NORMAL if the encoding was successfully set
Sets the (writeable) flags in channel to (flags & GLib.IOFlags.SET_MASK).
the flags to set on the IO channel
the status of the operation.
This sets the string that GLib.IOChannel uses to determine where in the file a line break occurs.
The line termination string. Use null for autodetect. Autodetection breaks on "\n", "\r\n", "\r", "\0", and the Unicode paragraph separator. Autodetection should not be used for anything other than file-based channels.
The length of the termination string. If -1 is passed, the string is assumed to be nul-terminated. This option allows termination strings with embedded nuls.
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().
if true, flush pending
the status of the operation.
Returns the file descriptor of the GLib.IOChannel.
On Windows this function returns the file descriptor or socket of the GLib.IOChannel.
the file descriptor of the GLib.IOChannel.
Decrements the reference count of a GLib.IOChannel.
Writes data to a GLib.IOChannel.
the buffer containing the data to write
the number of bytes to write
the number of bytes actually written
GLib.IOError.NONE if the operation was successful.
Replacement for g_io_channel_write() with the new API.
On seekable channels with encodings other than null or UTF-8, generic
mixing of reading and writing is not allowed. A call to g_io_channel_write_chars ()
may only be made on a channel from which data has been read in the
cases described in the documentation for g_io_channel_set_encoding ().
a buffer to write data from
the size of the buffer. If -1, the buffer is taken to be a nul-terminated string.
the status of the operation.
Writes a Unicode character to channel.
This function cannot be called on a channel with null encoding.
a character
Staticerror_Converts an errno error number to a GLib.IOChannelError.
an errno error number, e.g. EINVAL
Staticerror_Staticnew_Staticunix_
The GLib.IOChannel data type aims to provide a portable method for using file descriptors, pipes, and sockets, and integrating them into the main event loop (see GLib.MainContext). Currently, full support is available on UNIX platforms; support for Windows is only partially complete.
To create a new GLib.IOChannel on UNIX systems use 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 GLib.IOChannel.new_file.
Once a GLib.IOChannel has been created, it can be used in a generic manner with the functions GLib.IOChannel.read_chars, GLib.IOChannel.write_chars, GLib.IOChannel.seek_position, and GLib.IOChannel.shutdown.
To add a GLib.IOChannel to the main event loop, use GLib.io_add_watch or GLib.io_add_watch_full. Here you specify which events you are interested in on the GLib.IOChannel, and provide a function to be called whenever these events occur.
GLib.IOChannel instances are created with an initial reference count of 1. GLib.IOChannel.ref and GLib.IOChannel.unref can be used to increment or decrement the reference count respectively. When the reference count falls to 0, the GLib.IOChannel is freed. (Though it isn’t closed automatically, unless it was created using GLib.IOChannel.new_file.) Using GLib.io_add_watch or GLib.io_add_watch_full increments a channel’s reference count.
The new functions GLib.IOChannel.read_chars, GLib.IOChannel.read_line, GLib.IOChannel.read_line_string, GLib.IOChannel.read_to_end, GLib.IOChannel.write_chars, GLib.IOChannel.seek_position, and GLib.IOChannel.flush should not be mixed with the deprecated functions GLib.IOChannel.read, GLib.IOChannel.write, and GLib.IOChannel.seek on the same channel.