![]() |
![]() |
Inheritance diagram for Glib::IOChannel:
Public Member Functions | |
virtual | ~IOChannel () |
IOStatus | read (gunichar& unichar, std::auto_ptr<Glib::Error>& error) |
This function cannot be called on a channel with 0 encoding. | |
IOStatus | read (char* buf, gsize count, gsize& bytes_read, std::auto_ptr<Glib::Error>& error) |
Replacement for g_io_channel_read() with the new API. | |
IOStatus | read (Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error) |
Read a maximum of count bytes into str. | |
IOStatus | read_line (Glib::ustring& line, std::auto_ptr<Glib::Error>& error) |
Read a whole line. | |
IOStatus | read_to_end (Glib::ustring& str, std::auto_ptr<Glib::Error>& error) |
Reads all the remaining data from the file. | |
IOStatus | write (const Glib::ustring& str, std::auto_ptr<Glib::Error>& error) |
Write a string to the I/O channel. | |
IOStatus | write (const char* buf, gssize count, gsize& bytes_written, std::auto_ptr<Glib::Error>& error) |
Replacement for g_io_channel_write() with the new API. | |
IOStatus | write (gunichar unichar, std::auto_ptr<Glib::Error>& error) |
This function cannot be called on a channel with 0 encoding. | |
IOStatus | seek (gint64 offset, SeekType type, std::auto_ptr<Glib::Error>& error) |
Replacement for g_io_channel_seek() with the new API. | |
IOStatus | flush (std::auto_ptr<Glib::Error>& error) |
Flushes the write buffer for the GIOChannel. | |
IOStatus | close (bool flush, std::auto_ptr<Glib::Error>& error) |
Close an IO channel. | |
gsize | get_buffer_size () const |
Gets the buffer size. | |
void | set_buffer_size (gsize size) |
Sets the buffer size. | |
IOFlags | get_flags () const |
Gets the current flags for a G::IOChannel, including read-only flags such as G::IO_FLAG_IS_READABLE. | |
IOStatus | set_flags (IOFlags flags, std::auto_ptr<Glib::Error>& error) |
Sets the (writeable) flags in channel to ( flags & G::IO_CHANNEL_SET_MASK). | |
void | set_buffered (bool buffered) |
The buffering state can only be set if the channel's encoding is 0 . | |
bool | get_buffered () const |
Returns whether channel is buffered. | |
IOCondition | get_buffer_condition () const |
This function returns a G::IOCondition depending on whether there is data to be read/space to write data in the internal buffers in the G::IOChannel. | |
bool | get_close_on_unref () const |
Returns whether the file/socket/whatever associated with channel will be closed when channel receives its final unref and is destroyed. | |
void | set_close_on_unref (bool do_close) |
Setting this flag to true for a channel you have already closed can cause problems. | |
IOStatus | set_encoding (const std::string& encoding, std::auto_ptr<Glib::Error>& error) |
Sets the encoding for the input/output of the channel. | |
std::string | get_encoding () const |
Get the encoding of the I/O channel. | |
void | set_line_term (const std::string& term=std::string()) |
std::string | get_line_term () const |
Glib::RefPtr<IOSource> | create_watch (IOCondition condition) |
Creates an IOSource object. | |
virtual void | reference () const |
virtual void | unreference () const |
GIOChannel* | gobj () |
const GIOChannel* | gobj () const |
Static Public Member Functions | |
static Glib::RefPtr<IOChannel> | create_from_file (const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error) |
Open a file filename as an I/O channel using mode mode. | |
static Glib::RefPtr<IOChannel> | create_from_fd (int fd) |
Creates an I/O channel from a file descriptor. | |
static Glib::RefPtr<IOChannel> | create_from_win32_fd (int fd) |
Create an I/O channel for C runtime (emulated Unix-like) file descriptors. | |
static Glib::RefPtr<IOChannel> | create_from_win32_socket (int socket) |
Create an I/O channel for a winsock socket. | |
Protected Member Functions | |
IOChannel () | |
Constructor that should be used by derived classes. | |
virtual IOStatus | read_vfunc (char* buf, gsize count, gsize& bytes_read) |
virtual IOStatus | write_vfunc (const char* buf, gsize count, gsize& bytes_written) |
virtual IOStatus | seek_vfunc (gint64 offset, SeekType type) |
virtual IOStatus | close_vfunc () |
virtual IOStatus | set_flags_vfunc (IOFlags flags) |
virtual IOFlags | get_flags_vfunc () |
virtual Glib::RefPtr<Glib::Source> | create_watch_vfunc (IOCondition cond) |
Protected Attributes | |
GIOChannel* | gobject_ |
Note that IOChannels implement an automatic implicit character set conversion to the data stream, and usually will not pass by default binary data unchanged. To set the encoding of the channel, use e.g. set_encoding("ISO-8859-15"). To set the channel to no encoding, use set_encoding() without any arguments.
You can create an IOChannel with one of the static create methods, or implement one yourself, in which case you have to 1) override all _vfunc() members. 2) set the GIOChannel flags in your constructor.
virtual Glib::IOChannel::~IOChannel | ( | ) | [virtual] |
Glib::IOChannel::IOChannel | ( | ) | [protected] |
Constructor that should be used by derived classes.
Use this constructor if you want to inherit from IOChannel. It will set up a GIOChannel that will call the vfuncs of your class even if it is being used from C code, and it will keep a reference to the C++ code while the GIOChannel exists.
static Glib::RefPtr<IOChannel> Glib::IOChannel::create_from_file | ( | const std::string & | filename, | |
const std::string & | mode, | |||
std::auto_ptr<Glib::Error>& | error | |||
) | [static] |
Open a file filename as an I/O channel using mode mode.
This channel will be closed when the last reference to it is dropped, so there is no need to call close() (though doing so will not cause problems, as long as no attempt is made to access the channel after it is closed).
filename | The name of the file to open. | |
mode | One of "r" , "w" , "a" , "r+" , "w+" , "a+" . These have the same meaning as in fopen() . |
Glib::FileError |
static Glib::RefPtr<IOChannel> Glib::IOChannel::create_from_fd | ( | int | fd | ) | [static] |
Creates an I/O channel from a file descriptor.
On Unix, IOChannels created with this function work for any file descriptor or socket.
On Win32, this can be used either for files opened with the MSVCRT (the Microsoft run-time C library) _open()
or _pipe()
, including file descriptors 0, 1 and 2 (corresponding to stdin
, stdout
and stderr
), or for Winsock SOCKET
s. If the parameter is a legal file descriptor, it is assumed to be such, otherwise it should be a SOCKET
. This relies on SOCKET
s and file descriptors not overlapping. If you want to be certain, call either create_from_win32_fd() or create_from_win32_socket() instead as appropriate.
The term file descriptor as used in the context of Win32 refers to the emulated Unix-like file descriptors MSVCRT provides. The native corresponding concept is file HANDLE
. There isn't as of yet a way to get IOChannels for Win32 file HANDLE
s.
static Glib::RefPtr<IOChannel> Glib::IOChannel::create_from_win32_fd | ( | int | fd | ) | [static] |
Create an I/O channel for C runtime (emulated Unix-like) file descriptors.
After calling add_watch() on a I/O channel returned by this function, you shouldn't call read() on the file descriptor. This is because adding polling for a file descriptor is implemented on Win32 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 IOChannel::read().
static Glib::RefPtr<IOChannel> Glib::IOChannel::create_from_win32_socket | ( | int | socket | ) | [static] |
Create an I/O channel for a winsock socket.
The parameter should be a SOCKET
. Contrary to I/O channels for file descriptors (on Win32), you can use normal recv()
or recvfrom()
on sockets even if GLib is polling them.
IOStatus Glib::IOChannel::read | ( | gunichar & | unichar, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
This function cannot be called on a channel with 0
encoding.
thechar | A location to return a character. | |
error | A location to return an error of type G::ConvertError or G::IOChannelError. |
IOStatus Glib::IOChannel::read | ( | char * | buf, | |
gsize | count, | |||
gsize & | bytes_read, | |||
std::auto_ptr<Glib::Error>& | error | |||
) |
Replacement for g_io_channel_read() with the new API.
buf | A buffer to read data into. | |
count | 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. | |
bytes_read | The number of bytes read. This may be zero even on success if count < 6 and the channel's encoding is non-0 . This indicates that the next UTF-8 character is too wide for the buffer. | |
error | A location to return an error of type G::ConvertError or G::IOChannelError. |
IOStatus Glib::IOChannel::read | ( | Glib::ustring& | str, | |
gsize | count, | |||
std::auto_ptr<Glib::Error>& | error | |||
) |
Read a maximum of count bytes into str.
count | The maximum number of bytes to read. |
str | The characters that have been read. |
Glib::IOChannelError | ||
Glib::ConvertError |
IOStatus Glib::IOChannel::read_line | ( | Glib::ustring& | line, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
Read a whole line.
Reads until the line separator is found, which is included in the result string.
line | The line that was read. |
Glib::IOChannelError | ||
Glib::ConvertError |
IOStatus Glib::IOChannel::read_to_end | ( | Glib::ustring& | str, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
Reads all the remaining data from the file.
str | The resulting string. |
Glib::IOChannelError | ||
Glib::ConvertError |
IOStatus Glib::IOChannel::write | ( | const Glib::ustring& | str, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
Write a string to the I/O channel.
Note that this method does not return the number of characters written. If the channel is blocking and the returned value is Glib::IO_STATUS_NORMAL, the whole string was written.
str | the string to write. |
Glib::IOChannelError | ||
Glib::ConvertError |
IOStatus Glib::IOChannel::write | ( | const char * | buf, | |
gssize | count, | |||
gsize & | bytes_written, | |||
std::auto_ptr<Glib::Error>& | error | |||
) |
Replacement for g_io_channel_write() with the new API.
On seekable channels with encodings other than 0
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().
buf | A buffer to write data from. | |
count | The size of the buffer. If -1, the buffer is taken to be a nul-terminated string. | |
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. | |
error | A location to return an error of type G::ConvertError or G::IOChannelError. |
IOStatus Glib::IOChannel::write | ( | gunichar | unichar, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
This function cannot be called on a channel with 0
encoding.
thechar | A character. | |
error | A location to return an error of type G::ConvertError or G::IOChannelError. |
IOStatus Glib::IOChannel::seek | ( | gint64 | offset, | |
SeekType | type, | |||
std::auto_ptr<Glib::Error>& | error | |||
) |
Replacement for g_io_channel_seek() with the new API.
offset | The offset in bytes from the position specified by type . | |
type | A G::SeekType. 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. | |
error | A location to return an error of type G::IOChannelError. |
IOStatus Glib::IOChannel::flush | ( | std::auto_ptr<Glib::Error>& | error | ) |
Flushes the write buffer for the GIOChannel.
error | Location to store an error of type G::IOChannelError. |
IOStatus Glib::IOChannel::close | ( | bool | flush, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
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().
flush | If true , flush pending. | |
err | Location to store a G::IOChannelError. |
gsize Glib::IOChannel::get_buffer_size | ( | ) | const |
Gets the buffer size.
void Glib::IOChannel::set_buffer_size | ( | gsize | size | ) |
Sets the buffer size.
size | The size of the buffer. 0 == pick a good size. |
IOFlags Glib::IOChannel::get_flags | ( | ) | const |
Gets the current flags for a G::IOChannel, 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.
IOStatus Glib::IOChannel::set_flags | ( | IOFlags | flags, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
Sets the (writeable) flags in channel to ( flags & G::IO_CHANNEL_SET_MASK).
flags | The flags to set on the IO channel. | |
error | A location to return an error of type G::IOChannelError. |
void Glib::IOChannel::set_buffered | ( | bool | buffered | ) |
The buffering state can only be set if the channel's encoding is 0
.
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.
buffered | Whether to set the channel buffered or unbuffered. |
bool Glib::IOChannel::get_buffered | ( | ) | const |
Returns whether channel is buffered.
true
if the channel is buffered. IOCondition Glib::IOChannel::get_buffer_condition | ( | ) | const |
This function returns a G::IOCondition depending on whether there is data to be read/space to write data in the internal buffers in the G::IOChannel.
Only the flags G::IO_IN and G::IO_OUT may be set.
bool Glib::IOChannel::get_close_on_unref | ( | ) | const |
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.
void Glib::IOChannel::set_close_on_unref | ( | bool | do_close | ) |
Setting this flag to true
for a channel you have already closed can cause problems.
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. |
IOStatus Glib::IOChannel::set_encoding | ( | const std::string & | encoding, | |
std::auto_ptr<Glib::Error>& | error | |||
) |
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 ""
is safe to use with binary data.
The encoding can only be set if one of the following conditions is true:
""
or UTF-8.Channels which do not meet one of the above conditions cannot call seek_position() with a seek type of Glib::SEEK_TYPE_CUR and, if they are "seekable", cannot call write() after calling one of the API "read" methods.
encoding | The encoding name, or "" for binary. |
Glib::IOChannelError |
std::string Glib::IOChannel::get_encoding | ( | ) | const |
Get the encoding of the I/O channel.
void Glib::IOChannel::set_line_term | ( | const std::string & | term = std::string() |
) |
std::string Glib::IOChannel::get_line_term | ( | ) | const |
Glib::RefPtr<IOSource> Glib::IOChannel::create_watch | ( | IOCondition | condition | ) |
Creates an IOSource object.
Create a slot from a function to be called when condition is met for the channel with sigc::ptr_fun() or sigc::mem_fun() and pass it into the connect() function of the returned IOSource object. Polling of the channel will start when you attach a MainContext object to the returned IOSource object using its attach() function.
Glib::signal_io().connect() is a simpler interface to the same functionality, for the case where you want to add the source to the default main context.
condition | The condition to watch for. |
virtual void Glib::IOChannel::reference | ( | ) | const [virtual] |
virtual void Glib::IOChannel::unreference | ( | ) | const [virtual] |
GIOChannel* Glib::IOChannel::gobj | ( | ) | [inline] |
const GIOChannel* Glib::IOChannel::gobj | ( | ) | const [inline] |
virtual IOStatus Glib::IOChannel::read_vfunc | ( | char * | buf, | |
gsize | count, | |||
gsize & | bytes_read | |||
) | [protected, virtual] |
Reimplemented in Glib::StreamIOChannel.
virtual IOStatus Glib::IOChannel::write_vfunc | ( | const char * | buf, | |
gsize | count, | |||
gsize & | bytes_written | |||
) | [protected, virtual] |
Reimplemented in Glib::StreamIOChannel.
Reimplemented in Glib::StreamIOChannel.
virtual IOStatus Glib::IOChannel::close_vfunc | ( | ) | [protected, virtual] |
Reimplemented in Glib::StreamIOChannel.
Reimplemented in Glib::StreamIOChannel.
virtual IOFlags Glib::IOChannel::get_flags_vfunc | ( | ) | [protected, virtual] |
Reimplemented in Glib::StreamIOChannel.
virtual Glib::RefPtr<Glib::Source> Glib::IOChannel::create_watch_vfunc | ( | IOCondition | cond | ) | [protected, virtual] |
Reimplemented in Glib::StreamIOChannel.
GIOChannel* Glib::IOChannel::gobject_ [protected] |