IOChannel

Description 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. Currently full support is available on UNIX platforms, support for Windows is only partially complete. To create a new GIOChannel on UNIX systems use g_io_channel_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 g_io_channel_new_file(). Once a GIOChannel has been created, it can be used in a generic manner with the functions g_io_channel_read_chars(), g_io_channel_write_chars(), g_io_channel_seek_position(), and g_io_channel_shutdown(). To add a GIOChannel to the main event loop use g_io_add_watch() or g_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. g_io_channel_ref() and g_io_channel_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 g_io_channel_new_from_file().) Using g_io_add_watch() or g_io_add_watch_full() increments a channel's reference count. The new functions g_io_channel_read_chars(), g_io_channel_read_line(), g_io_channel_read_line_string(), g_io_channel_read_to_end(), g_io_channel_write_chars(), g_io_channel_seek_position(), and g_io_channel_flush() should not be mixed with the deprecated functions g_io_channel_read(), g_io_channel_write(), and g_io_channel_seek() on the same channel.

class IOChannel {}

Constructors

this
this(GIOChannel* gIOChannel)

Sets our main struct and passes it to the parent class

Destructor

~this
~this()
Undocumented in source.

Members

Functions

close
void close()

Warning g_io_channel_close has been deprecated since version 2.2 and should not be used in newly-written code. Use g_io_channel_shutdown() instead. 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().

doref
IOChannel doref()

Increments the reference count of a GIOChannel.

flush
GIOStatus flush()

Flushes the write buffer for the GIOChannel.

gIoAddWatch
uint gIoAddWatch(GIOCondition condition, GIOFunc func, void* userData)

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

gIoAddWatchFull
uint gIoAddWatchFull(int priority, GIOCondition condition, GIOFunc func, void* userData, GDestroyNotify notify)

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 manually if you need greater control.

gIoCreateWatch
Source gIoCreateWatch(GIOCondition condition)

Creates a GSource that's dispatched when condition is met for the given channel. 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.

getBufferCondition
GIOCondition getBufferCondition()

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.

getBufferSize
gsize getBufferSize()

Gets the buffer size.

getBuffered
int getBuffered()

Returns whether channel is buffered.

getCloseOnUnref
int getCloseOnUnref()

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.

getEncoding
string getEncoding()

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.

getFlags
GIOFlags getFlags()

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.

getIOChannelStruct
GIOChannel* getIOChannelStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getLineTerm
string getLineTerm(int length)

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

getStruct
void* getStruct()

the main Gtk struct as a void*

init
void init()

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

read
GIOError read(string buf, gsize count, gsize bytesRead)

Warning g_io_channel_read has been deprecated since version 2.2 and should not be used in newly-written code. Use g_io_channel_read_chars() instead. Reads data from a GIOChannel.

readChars
GIOStatus readChars(string buf, gsize count, gsize bytesRead)

Replacement for g_io_channel_read() with the new API.

readLine
GIOStatus readLine(string strReturn, gsize terminatorPos)

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.

readLineString
GIOStatus readLineString(StringG buffer, gsize terminatorPos)

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

readToEnd
GIOStatus readToEnd(string strReturn)

Reads all the remaining data from the file.

readUnichar
GIOStatus readUnichar(gunichar thechar)

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

seek
GIOError seek(long offset, GSeekType type)

Warning g_io_channel_seek has been deprecated since version 2.2 and should not be used in newly-written code. Use g_io_channel_seek_position() instead. Sets the current position in the GIOChannel, similar to the standard library function fseek().

seekPosition
GIOStatus seekPosition(long offset, GSeekType type)

Replacement for g_io_channel_seek() with the new API.

setBufferSize
void setBufferSize(gsize size)

Sets the buffer size.

setBuffered
void setBuffered(int 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.

setCloseOnUnref
void setCloseOnUnref(int doClose)

Setting this flag to TRUE for a channel you have already closed can cause problems.

setEncoding
GIOStatus setEncoding(string 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

setFlags
GIOStatus setFlags(GIOFlags flags)

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

setLineTerm
void setLineTerm(string lineTerm, int length)

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

shutdown
GIOStatus shutdown(int 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().

unixGetFd
int unixGetFd()

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

unref
void unref()

Decrements the reference count of a GIOChannel.

write
GIOError write(string buf, gsize count, gsize bytesWritten)

Warning g_io_channel_write has been deprecated since version 2.2 and should not be used in newly-written code. Use g_io_channel_write_chars() instead. Writes data to a GIOChannel.

writeChars
GIOStatus writeChars(string buf, gssize count, gsize bytesWritten)

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

writeUnichar
GIOStatus writeUnichar(gunichar thechar)

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

Static functions

errorFromErrno
GIOChannelError errorFromErrno(int en)

Converts an errno error number to a GIOChannelError.

unixNew
IOChannel unixNew(int fd)

Creates a new GIOChannel given a file descriptor. On UNIX systems this works for plain files, pipes, and sockets. The returned GIOChannel has a reference count of 1. The default encoding for GIOChannel is UTF-8. If your application is reading output from a command using via pipe, you may need to set the encoding to the encoding of the current locale (see g_get_charset()) with the g_io_channel_set_encoding() function. If you want to read raw binary data without interpretation, then call the g_io_channel_set_encoding() function with NULL for the encoding argument. This function is available in GLib on Windows, too, but you should avoid using it on Windows. The domain of file descriptors and sockets overlap. There is no way for GLib to know which one you mean in case the argument you pass to this function happens to be both a valid file descriptor and socket. If that happens a warning is issued, and GLib assumes that it is the file descriptor you mean.

win32_NewFd
IOChannel win32_NewFd(int fd)

Creates a new GIOChannel given a file descriptor on Windows. This works for file descriptors from the C runtime. This function works for file descriptors as returned by the open(), creat(), pipe() and fileno() calls in the Microsoft C runtime. In order to meaningfully use this function your code should use the same C runtime as GLib uses, which is msvcrt.dll. Note that in current Microsoft compilers it is near impossible to convince it to build code that would use msvcrt.dll. The last Microsoft compiler version that supported using msvcrt.dll as the C runtime was version 6. The GNU compiler and toolchain for Windows, also known as Mingw, fully supports msvcrt.dll. If you have created a GIOChannel for a file descriptor and started watching (polling) it, you shouldn't call read() on the file descriptor. This is because adding polling for a file descriptor is implemented in GLib on Windows by starting a thread that sits blocked in a read() from the file descriptor most of the time. All reads from the file descriptor should be done by this internal GLib thread. Your code should call only g_io_channel_read(). This function is available only in GLib on Windows.

win32_NewMessages
IOChannel win32_NewMessages(gsize hwnd)

Creates a new GIOChannel given a window handle on Windows. This function creates a GIOChannel that can be used to poll for Windows messages for the window in question.

win32_NewSocket
IOChannel win32_NewSocket(int socket)

Creates a new GIOChannel given a socket on Windows. This function works for sockets created by Winsock. It's available only in GLib 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.

Variables

gIOChannel
GIOChannel* gIOChannel;

the main Gtk struct

Meta