giochannel.h File Reference

__G_IOCHANNEL_H__

Typedef GIOChannel

typedef typedefG_BEGIN_DECLS struct _GIOChannelGIOChannel

Typedef GIOFuncs

typedef struct _GIOFuncsGIOFuncs

Enum GIOError

G_IO_CHANNEL_ERROR

Enum GIOChannelError

Enum GIOStatus

Enum GSeekType

EnumeratorValueDescription
G_SEEK_CUR
G_SEEK_SET
G_SEEK_END

Enum GIOCondition

Enum GIOFlags

EnumeratorValueDescription
G_IO_FLAG_APPEND1 << 0
G_IO_FLAG_NONBLOCK1 << 1
G_IO_FLAG_IS_READABLE1 << 2
G_IO_FLAG_IS_WRITEABLE1 << 3
G_IO_FLAG_IS_SEEKABLE1 << 4
G_IO_FLAG_MASK(1 << 5) - 1
G_IO_FLAG_GET_MASKG_IO_FLAG_MASK
G_IO_FLAG_SET_MASKG_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK

Typedef GIOFunc

typedef gboolean(*GIOFunc

g_io_channel_init ( GIOChannel * )

IMPORT_C voidg_io_channel_init(GIOChannel *channel)

g_io_channel_init: : a GIOChannel

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

g_io_channel_ref ( GIOChannel * )

IMPORT_C GIOChannel *g_io_channel_ref(GIOChannel *channel)

g_io_channel_ref: : a GIOChannel

Increments the reference count of a GIOChannel.

Returns: the that was passed in (since 2.6)

g_io_channel_unref ( GIOChannel * )

IMPORT_C voidg_io_channel_unref(GIOChannel *channel)

g_io_channel_unref: : a GIOChannel

Decrements the reference count of a GIOChannel.

g_io_channel_read ( GIOChannel *, gchar *, gsize, gsize * )

IMPORT_C GIOErrorg_io_channel_read(GIOChannel *channel,
gchar *buf,
gsizecount,
gsize *bytes_read
)

g_io_channel_read: : a GIOChannel : a buffer to read the data into (which should be at least count bytes long) : the number of bytes to read from the GIOChannel : returns the number of bytes actually read

Reads data from a GIOChannel.

Return value: G_IO_ERROR_NONE if the operation was successful.

Deprecated:2.2: Use g_io_channel_read_chars() instead.

g_io_channel_write ( GIOChannel *, const gchar *, gsize, gsize * )

IMPORT_C GIOErrorg_io_channel_write(GIOChannel *channel,
const gchar *buf,
gsizecount,
gsize *bytes_written
)

g_io_channel_write: : a GIOChannel : the buffer containing the data to write : the number of bytes to write : the number of bytes actually written

Writes data to a GIOChannel.

Return value: G_IO_ERROR_NONE if the operation was successful.

Deprecated:2.2: Use g_io_channel_write_chars() instead.

g_io_channel_seek ( GIOChannel *, gint64, GSeekType )

IMPORT_C GIOErrorg_io_channel_seek(GIOChannel *channel,
gint64offset,
GSeekTypetype
)

g_io_channel_seek: : a GIOChannel : an offset, in bytes, which is added to the position specified by : 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)

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

Return value: G_IO_ERROR_NONE if the operation was successful.

Deprecated:2.2: Use g_io_channel_seek_position() instead.

g_io_channel_close ( GIOChannel * )

IMPORT_C voidg_io_channel_close(GIOChannel *channel)

g_io_channel_new_file: : A string containing the name of a file : One of "r", "w", "a", "r+", "w+", "a+". These have the same meaning as in fopen() : A location to return an error of type G_FILE_ERROR

Open a file as a GIOChannel using mode . This channel will be closed when the last reference to it is dropped, so there is no need to call g_io_channel_close() (though doing so will not cause problems, as long as no attempt is made to access the channel after it is closed).

Return value: A GIOChannel on success, NULL on failure. g_io_channel_close: : A GIOChannel

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

Deprecated:2.2: Use g_io_channel_shutdown() instead.

g_io_channel_shutdown ( GIOChannel *, gboolean, GError ** )

IMPORT_C GIOStatusg_io_channel_shutdown(GIOChannel *channel,
gbooleanflush,
GError **err
)

g_io_channel_shutdown: : a GIOChannel : if TRUE, flush pending : location to store a GIOChannelError

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

Return value: the status of the operation.

g_io_add_watch_full ( GIOChannel *, gint, GIOCondition, GIOFunc, gpointer, GDestroyNotify )

IMPORT_C guintg_io_add_watch_full(GIOChannel *channel,
gintpriority,
GIOConditioncondition,
GIOFuncfunc,
gpointeruser_data,
GDestroyNotifynotify
)

g_io_add_watch_full: : a GIOChannel : the priority of the GIOChannel source : the condition to watch for : the function to call when the condition is satisfied : user data to pass to : the function to call when the source is removed

Adds the GIOChannel into the default main loop context with the given priority.

This internally creates a main loop source using g_io_create_watch() and attaches it to the main loop context with g_source_attach(). You can do these steps manuallt if you need greater control.

Returns: the event source id

g_io_create_watch ( GIOChannel *, GIOCondition )

IMPORT_C GSource *g_io_create_watch(GIOChannel *channel,
GIOConditioncondition
)

g_io_create_watch: : a GIOChannel to watch : conditions to watch for

Creates a GSource that's dispatched when is met for the given . For example, if condition is #G_IO_IN, the source will be dispatched when there's data available for reading.

g_io_add_watch() is a simpler interface to this same functionality, for the case where you want to add the source to the default main loop context at the default priority.

On Windows, polling a GSource created to watch a channel for a socket puts the socket in non-blocking mode. This is a side-effect of the implementation and unavoidable.

Returns: a new GSource

g_io_add_watch ( GIOChannel *, GIOCondition, GIOFunc, gpointer )

IMPORT_C guintg_io_add_watch(GIOChannel *channel,
GIOConditioncondition,
GIOFuncfunc,
gpointeruser_data
)

g_io_add_watch: : a GIOChannel : the condition to watch for : the function to call when the condition is satisfied : user data to pass to

Adds the GIOChannel into the default main loop context with the default priority.

Returns: the event source id

g_io_channel_set_buffer_size ( GIOChannel *, gsize )

IMPORT_C voidg_io_channel_set_buffer_size(GIOChannel *channel,
gsizesize
)

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

Sets the buffer size.

g_io_channel_get_buffer_size ( GIOChannel * )

IMPORT_C gsizeg_io_channel_get_buffer_size(GIOChannel *channel)

g_io_channel_get_buffer_size: : a GIOChannel

Gets the buffer size.

Return value: the size of the buffer.

g_io_channel_get_buffer_condition ( GIOChannel * )

IMPORT_C GIOConditiong_io_channel_get_buffer_condition(GIOChannel *channel)

g_io_channel_get_buffer_condition: : A GIOChannel

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.

Return value: A GIOCondition

g_io_channel_set_flags ( GIOChannel *, GIOFlags, GError ** )

IMPORT_C GIOStatusg_io_channel_set_flags(GIOChannel *channel,
GIOFlagsflags,
GError **error
)

g_io_channel_set_flags: : a GIOChannel : the flags to set on the IO channel : A location to return an error of type GIOChannelError

Sets the (writeable) flags in to ( & G_IO_CHANNEL_SET_MASK).

Return value: the status of the operation.

g_io_channel_get_flags ( GIOChannel * )

IMPORT_C GIOFlagsg_io_channel_get_flags(GIOChannel *channel)

g_io_channel_get_flags: : a GIOChannel

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_WRITEABLE 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.

Return value: the flags which are set on the channel

g_io_channel_set_line_term ( GIOChannel *, const gchar *, gint )

IMPORT_C voidg_io_channel_set_line_term(GIOChannel *channel,
const gchar *line_term,
gintlength
)

g_io_channel_set_line_term: : a GIOChannel : 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.

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

g_io_channel_get_line_term ( GIOChannel *, gint * )

IMPORT_C G_CONST_RETURN gchar *g_io_channel_get_line_term(GIOChannel *channel,
gint *length
)

g_io_channel_get_line_term: : a GIOChannel : a location to return the length of the line terminator

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

Return value: The line termination string. This value is owned by GLib and must not be freed.

g_io_channel_set_buffered ( GIOChannel *, gboolean )

IMPORT_C voidg_io_channel_set_buffered(GIOChannel *channel,
gbooleanbuffered
)

g_io_channel_set_buffered: : a GIOChannel : whether to set the channel buffered or unbuffered

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.

g_io_channel_get_buffered ( GIOChannel * )

IMPORT_C gbooleang_io_channel_get_buffered(GIOChannel *channel)

g_io_channel_get_buffered: : a GIOChannel

Returns whether is buffered.

Return Value: TRUE if the is buffered.

g_io_channel_set_encoding ( GIOChannel *, const gchar *, GError ** )

IMPORT_C GIOStatusg_io_channel_set_encoding(GIOChannel *channel,
const gchar *encoding,
GError **error
)

g_io_channel_set_encoding: : a GIOChannel : the encoding type : location to store an error of type GConvertError

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: <itemizedlist> <listitem>

The channel was just created, and has not been written to or read from yet.

</listitem> <listitem>

The channel is write-only.

</listitem> <listitem>

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

</listitem> <listitem>

The current encoding is NULL or UTF-8.

</listitem> <listitem>

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

</listitem> <listitem>

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 <emphasis>not</emphasis> guarantee that the encoding can be changed.

</listitem> </itemizedlist> 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.

Return Value: G_IO_STATUS_NORMAL if the encoding was successfully set.

g_io_channel_get_encoding ( GIOChannel * )

IMPORT_C G_CONST_RETURN gchar *g_io_channel_get_encoding(GIOChannel *channel)

g_io_channel_get_encoding: : a GIOChannel

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.

Return value: A string containing the encoding, this string is owned by GLib and must not be freed.

g_io_channel_set_close_on_unref ( GIOChannel *, gboolean )

IMPORT_C voidg_io_channel_set_close_on_unref(GIOChannel *channel,
gbooleando_close
)

g_io_channel_set_close_on_unref: : a GIOChannel : 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.

g_io_channel_get_close_on_unref ( GIOChannel * )

IMPORT_C gbooleang_io_channel_get_close_on_unref(GIOChannel *channel)

g_io_channel_get_close_on_unref: : a GIOChannel.

Returns whether the file/socket/whatever associated with will be closed when 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.

Return value: Whether the channel will be closed on the final unref of the GIOChannel data structure.

g_io_channel_flush ( GIOChannel *, GError ** )

IMPORT_C GIOStatusg_io_channel_flush(GIOChannel *channel,
GError **error
)

g_io_channel_flush: : a GIOChannel : location to store an error of type GIOChannelError

Flushes the write buffer for the GIOChannel.

Return value: the status of the operation: One of G_IO_STATUS_NORMAL, G_IO_STATUS_AGAIN, or G_IO_STATUS_ERROR.

g_io_channel_read_line ( GIOChannel *, gchar **, gsize *, gsize *, GError ** )

IMPORT_C GIOStatusg_io_channel_read_line(GIOChannel *channel,
gchar **str_return,
gsize *length,
gsize *terminator_pos,
GError **error
)

g_io_channel_read_line: : a GIOChannel : 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 of zero is returned, this will be NULL instead. : location to store length of the read data, or NULL : location to store position of line terminator, or NULL : A location to return an error of type GConvertError or GIOChannelError

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

Return value: the status of the operation.

g_io_channel_read_line_string ( GIOChannel *, GString *, gsize *, GError ** )

IMPORT_C GIOStatusg_io_channel_read_line_string(GIOChannel *channel,
GString *buffer,
gsize *terminator_pos,
GError **error
)

g_io_channel_read_line_string: : a GIOChannel : a GString into which the line will be written. If already contains data, the old data will be overwritten. : location to store position of line terminator, or NULL : a location to store an error of type GConvertError or GIOChannelError

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

Return value: the status of the operation.

g_io_channel_read_to_end ( GIOChannel *, gchar **, gsize *, GError ** )

IMPORT_C GIOStatusg_io_channel_read_to_end(GIOChannel *channel,
gchar **str_return,
gsize *length,
GError **error
)

g_io_channel_read_to_end: : a GIOChannel : 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. : location to store length of the data : location to return an error of type GConvertError or GIOChannelError

Reads all the remaining data from the file.

Return value: G_IO_STATUS_NORMAL on success. This function never returns G_IO_STATUS_EOF.

g_io_channel_read_chars ( GIOChannel *, gchar *, gsize, gsize *, GError ** )

IMPORT_C GIOStatusg_io_channel_read_chars(GIOChannel *channel,
gchar *buf,
gsizecount,
gsize *bytes_read,
GError **error
)

g_io_channel_read_chars: : a GIOChannel : a buffer to read data into : the size of the buffer. Note that the buffer may not be complelely filled even if there is data in the buffer if the remaining data is not a complete character. : 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. : a location to return an error of type GConvertError or GIOChannelError.

Replacement for g_io_channel_read() with the new API.

Return value: the status of the operation.

g_io_channel_read_unichar ( GIOChannel *, gunichar *, GError ** )

IMPORT_C GIOStatusg_io_channel_read_unichar(GIOChannel *channel,
gunichar *thechar,
GError **error
)

g_io_channel_read_unichar: : a GIOChannel : a location to return a character : a location to return an error of type GConvertError or GIOChannelError

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

Return value: a GIOStatus

g_io_channel_write_chars ( GIOChannel *, const gchar *, gssize, gsize *, GError ** )

IMPORT_C GIOStatusg_io_channel_write_chars(GIOChannel *channel,
const gchar *buf,
gssizecount,
gsize *bytes_written,
GError **error
)

g_io_channel_write_chars: : a GIOChannel : a buffer to write data from : the size of the buffer. If -1, the buffer is taken to be a nul-terminated string. : 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 if >= 0. : a location to return an error of type GConvertError or GIOChannelError

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

Return value: the status of the operation.

g_io_channel_write_unichar ( GIOChannel *, gunichar, GError ** )

IMPORT_C GIOStatusg_io_channel_write_unichar(GIOChannel *channel,
gunicharthechar,
GError **error
)

g_io_channel_write_unichar: : a GIOChannel : a character : location to return an error of type GConvertError or GIOChannelError

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

Return value: a GIOStatus

g_io_channel_seek_position ( GIOChannel *, gint64, GSeekType, GError ** )

IMPORT_C GIOStatusg_io_channel_seek_position(GIOChannel *channel,
gint64offset,
GSeekTypetype,
GError **error
)

g_io_channel_seek_position: : a GIOChannel : The offset in bytes from the position specified by : 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. : A location to return an error of type GIOChannelError

Replacement for g_io_channel_seek() with the new API.

Return value: the status of the operation.

g_io_channel_new_file ( const gchar *, const gchar *, GError ** )

IMPORT_C GIOChannel *g_io_channel_new_file(const gchar *filename,
const gchar *mode,
GError **error
)

g_io_channel_error_quark ( void )

IMPORT_C GQuarkg_io_channel_error_quark(void)

g_io_channel_error_quark:

Return value: the quark used as G_IO_CHANNEL_ERROR

g_io_channel_error_from_errno ( gint )

IMPORT_C GIOChannelErrorg_io_channel_error_from_errno(ginten)

g_io_channel_error_from_errno: : an <literal>errno</literal> error number, e.g. EINVAL

Converts an <literal>errno</literal> error number to a GIOChannelError.

Return value: a GIOChannelError error number, e.g. G_IO_CHANNEL_ERROR_INVAL.

g_io_channel_unix_new ( int )

IMPORT_C GIOChannel *g_io_channel_unix_new(intfd)

g_io_channel_unix_get_fd ( GIOChannel * )

IMPORT_C gintg_io_channel_unix_get_fd(GIOChannel *channel)

g_io_watch_funcs

GLIB_VAR GSourceFuncsg_io_watch_funcs

_g_io_watch_funcs ( )

IMPORT_C GSourceFuncs *_g_io_watch_funcs()