<GIOChannel>

<GIOChannel>

Description

A data structure representing an IO Channel. The fields should be considered private and should only be accessed with the following functions.

Functions

close

(define-values () (iochannel:close self))

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().

Parameters

channel

A GIOChannel

Passed as self

flush

(define-values (%return) (iochannel:flush self))

Flushes the write buffer for the GIOChannel.

Parameters

channel

a GIOChannel

Passed as self

get-buffer-condition

(define-values (%return) (iochannel:get-buffer-condition self))

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.

Parameters

channel

A GIOChannel

Passed as self

get-buffer-size

(define-values (%return) (iochannel:get-buffer-size self))

Gets the buffer size.

Parameters

channel

a GIOChannel

Passed as self

get-buffered?

(define-values (%return) (iochannel:get-buffered? self))

Returns whether channel is buffered.

Parameters

channel

a GIOChannel

Passed as self

get-close-on-unref?

(define-values (%return) (iochannel:get-close-on-unref? self))

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.

Parameters

channel

a GIOChannel.

Passed as self

get-encoding

(define-values (%return) (iochannel:get-encoding self))

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.

Parameters

channel

a GIOChannel

Passed as self

get-flags

(define-values (%return) (iochannel:get-flags self))

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

The values of the flags G_IO_FLAG_IS_READABLE and G_IO_FLAG_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.

Parameters

channel

a GIOChannel

Passed as self

get-line-term

(define-values (%return) (iochannel:get-line-term self length))

This returns the string that GIOChannel uses to determine where in the file a line break occurs. A value of NULL indicates autodetection.

Parameters

channel

a GIOChannel

Passed as self

length

a location to return the length of the line terminator

Passed as length

init

(define-values () (iochannel:init self))

Initializes a GIOChannel struct.

This is called by each of the above functions when creating a GIOChannel, and so is not often needed by the application programmer (unless you are creating a new type of GIOChannel).

Parameters

channel

a GIOChannel

Passed as self

read

(define-values (%return) (iochannel:read self buf count bytes-read))

Reads data from a GIOChannel.

Parameters

channel

a GIOChannel

Passed as self

buf

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

Passed as buf

count

the number of bytes to read from the GIOChannel

Passed as count

bytes_read

returns the number of bytes actually read

Passed as bytes-read

read-chars!

(define-values (%return buf bytes-read) (iochannel:read-chars! self buf))

Replacement for g_io_channel_read() with the new API.

Parameters

channel

a GIOChannel

Passed as self

buf

a buffer to read data into

Passed as buf

count

the size of the buffer. Note that the buffer may not be completely filled even if there is data in the buffer if the remaining data is not a complete character.

Inferred from buf

bytes_read

The number of bytes read. This may be zero even on success if count < 6 and the channel's encoding is non-NULL. This indicates that the next UTF-8 character is too wide for the buffer.

Passed as bytes-read

read-line

(define-values
  (%return str-return length terminator-pos)
  (iochannel:read-line self))

Reads a line, including the terminating character(s), from a GIOChannel into a newly-allocated string. str_return will contain allocated memory if the return is G_IO_STATUS_NORMAL.

Parameters

channel

a GIOChannel

Passed as self

str_return

The line read from the GIOChannel, including the line terminator. This data should be freed with g_free() when no longer needed. This is a nul-terminated string. If a length of zero is returned, this will be NULL instead.

Passed as str-return

length

location to store length of the read data, or NULL

Passed as length

terminator_pos

location to store position of line terminator, or NULL

Passed as terminator-pos

read-line-string

(define-values
  (%return)
  (iochannel:read-line-string self buffer terminator-pos))

Reads a line from a GIOChannel, using a GString as a buffer.

Parameters

channel

a GIOChannel

Passed as self

buffer

a GString into which the line will be written. If buffer already contains data, the old data will be overwritten.

Passed as buffer

terminator_pos

location to store position of line terminator, or NULL

Passed as terminator-pos

read-to-end

(define-values (%return str-return length) (iochannel:read-to-end self))

Reads all the remaining data from the file.

Parameters

channel

a GIOChannel

Passed as self

str_return

Location to store a pointer to a string holding the remaining data in the GIOChannel. This data should be freed with g_free() when no longer needed. This data is terminated by an extra nul character, but there may be other nuls in the intervening data.

Passed as str-return

length

location to store length of the data

Inferred from str-return

read-unichar

(define-values (%return thechar) (iochannel:read-unichar self))

Reads a Unicode character from channel. This function cannot be called on a channel with NULL encoding.

Parameters

channel

a GIOChannel

Passed as self

thechar

a location to return a character

Passed as thechar

ref

(define-values (%return) (iochannel:ref self))

Increments the reference count of a GIOChannel.

Parameters

channel

a GIOChannel

Passed as self

seek

(define-values (%return) (iochannel:seek self offset type))

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

Parameters

channel

a GIOChannel

Passed as self

offset

an offset, in bytes, which is added to the position specified by type

Passed as offset

type

the position in the file, which can be G_SEEK_CUR (the current position), G_SEEK_SET (the start of the file), or G_SEEK_END (the end of the file)

Passed as type

seek-position

(define-values (%return) (iochannel:seek-position self offset type))

Replacement for g_io_channel_seek() with the new API.

Parameters

channel

a GIOChannel

Passed as self

offset

The offset in bytes from the position specified by type

Passed as offset

type

a GSeekType. The type G_SEEK_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.

Passed as type

set-buffer-size

(define-values () (iochannel:set-buffer-size self size))

Sets the buffer size.

Parameters

channel

a GIOChannel

Passed as self

size

the size of the buffer, or 0 to let GLib pick a good size

Passed as size

set-buffered

(define-values () (iochannel:set-buffered self buffered))

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 G_IO_STATUS_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 G_SEEK_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.

Parameters

channel

a GIOChannel

Passed as self

buffered

whether to set the channel buffered or unbuffered

Passed as buffered

set-close-on-unref

(define-values () (iochannel:set-close-on-unref self do-close))

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.

Setting this flag to TRUE for a channel you have already closed can cause problems when the final reference to the GIOChannel is dropped.

Parameters

channel

a GIOChannel

Passed as self

do_close

Whether to close the channel on the final unref of the GIOChannel data structure.

Passed as do-close

set-encoding

(define-values (%return) (iochannel:set-encoding self encoding))

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 G_IO_STATUS_EOF (or, in the case of g_io_channel_read_to_end(), G_IO_STATUS_NORMAL).

- One of the functions g_io_channel_read_chars() or g_io_channel_read_unichar() has returned G_IO_STATUS_AGAIN or G_IO_STATUS_ERROR. This may be useful in the case of G_CONVERT_ERROR_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 G_SEEK_CUR, and, if they are "seekable", cannot call g_io_channel_write_chars() after calling one of the API "read" functions.

Parameters

channel

a GIOChannel

Passed as self

encoding

the encoding type

Passed as encoding

set-flags

(define-values (%return) (iochannel:set-flags self flags))

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

Parameters

channel

a GIOChannel

Passed as self

flags

the flags to set on the IO channel

Passed as flags

set-line-term

(define-values () (iochannel:set-line-term self line-term length))

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

Parameters

channel

a GIOChannel

Passed as self

line_term

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.

Passed as line-term

length

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.

Passed as length

shutdown

(define-values (%return) (iochannel:shutdown self flush))

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().

Parameters

channel

a GIOChannel

Passed as self

flush

if TRUE, flush pending

Passed as flush

unix-get-fd

(define-values (%return) (iochannel:unix-get-fd self))

Returns the file descriptor of the GIOChannel.

On Windows this function returns the file descriptor or socket of the GIOChannel.

Parameters

channel

a GIOChannel, created with g_io_channel_unix_new().

Passed as self

unref

(define-values () (iochannel:unref self))

Decrements the reference count of a GIOChannel.

Parameters

channel

a GIOChannel

Passed as self

write

(define-values (%return) (iochannel:write self buf count bytes-written))

Writes data to a GIOChannel.

Parameters

channel

a GIOChannel

Passed as self

buf

the buffer containing the data to write

Passed as buf

count

the number of bytes to write

Passed as count

bytes_written

the number of bytes actually written

Passed as bytes-written

write-chars

(define-values (%return bytes-written) (iochannel:write-chars self buf count))

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 ().

Parameters

channel

a GIOChannel

Passed as self

buf

a buffer to write data from

Passed as buf

count

the size of the buffer. If -1, the buffer is taken to be a nul-terminated string.

Passed as count

bytes_written

The number of bytes written. This can be nonzero even if the return value is not G_IO_STATUS_NORMAL. If the return value is G_IO_STATUS_NORMAL and the channel is blocking, this will always be equal to count if count >= 0.

Passed as bytes-written

write-unichar

(define-values (%return) (iochannel:write-unichar self thechar))

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

Parameters

channel

a GIOChannel

Passed as self

thechar

a character

Passed as thechar

iochannel:unix-new

(define-values (%return) (iochannel:unix-new fd))

Undocumented

Parameters

fd

Passed as fd

iochannel:new-file

(define-values (%return) (iochannel:new-file filename mode))

Undocumented

Parameters

filename

Passed as filename

mode

Passed as mode

iochannel:error-from-errno

(define-values (%return) (iochannel:error-from-errno en))

Converts an errno error number to a GIOChannelError.

Parameters

en

an errno error number, e.g. EINVAL

Passed as en

iochannel:error-quark

(define-values (%return) (iochannel:error-quark))

Undocumented