IOChannel
Object Hierarchy:
GLib.IOChannel
GLib.IOChannel
GLib.IOChannel
Description:
[ Compact ] [ CCode ( ref_function = "g_io_channel_ref" , type_id = "G_TYPE_IO_CHANNEL" , unref_function = "g_io_channel_unref" ) ]public class IOChannel
Example: Watch a file with IOChannel:
public static int main (string [] args) { MainLoop loop = new MainLoop (null , false ); IOChannel channel = null ; try { channel = new IOChannel.file ("my-io-channel-test-file.txt" , "r" ); } catch (FileError e) { print ("FileError: %s \n " , e.message); return 0 ; } uint stat = channel.add_watch (IOCondition.IN, (source, condition) => { size_t terminator_pos = -1 ; string str_return = null ; size_t length = -1 ; if (condition == IOCondition.HUP) { print ("The connection has been broken. \n " ); return false ; } try { IOStatus status = channel.read_line (out str_return, out length, out terminator_pos); if (status == IOStatus.EOF) { // Quit the program: loop.quit (); return false ; } print ("watch: %s " , str_return); return true ; } catch (IOChannelError e) { print ("IOChannelError: %s \n " , e.message); return false ; } catch (ConvertError e) { print ("ConvertError: %s \n " , e.message); return false ; } }); if (stat == 0 ) { print ("Cannot add watch on IOChannel. \n " ); return 0 ; } loop.run (); return 0 ; }
valac --pkg glib-2.0 GLib.IOChannel.vala
Content:
Static methods:
Creation methods:
Methods:
public uint add_watch (IOCondition condition, IOFunc func)
public uint add_watch_full (int priority, IOCondition condition, owned IOFunc func)
public IOSource create_watch (IOCondition condition)
public IOStatus flush () throws IOChannelError
public IOCondition get_buffer_condition ()
public size_t get_buffer_size ()
public bool get_buffered ()
public bool get_close_on_unref ()
public unowned string get_encoding ()
public IOFlags get_flags ()
public unowned string get_line_term (out int length)
public void init ()
public IOStatus read_chars (char [] buf, out size_t bytes_read) throws ConvertError , IOChannelError
public IOStatus read_line (out string str_return, out size_t length, out size_t terminator_pos) throws ConvertError , IOChannelError
public IOStatus read_line_string (StringBuilder buffer, out size_t terminator_pos) throws ConvertError , IOChannelError
public IOStatus read_to_end (out string str_return, out size_t length) throws ConvertError , IOChannelError
public IOStatus read_unichar (out unichar thechar) throws ConvertError , IOChannelError
public IOStatus seek_position (int64 offset, SeekType type) throws IOChannelError
public void set_buffer_size (size_t size)
public void set_buffered (bool buffered)
public void set_close_on_unref (bool do_close)
public IOStatus set_encoding (string ? encoding) throws IOChannelError
public IOStatus set_flags (IOFlags flags) throws IOChannelError
public void set_line_term (string line_term, int length)
public IOStatus shutdown (bool flush) throws IOChannelError
public int unix_get_fd ()
public int win32_get_fd ()
public void win32_make_pollfd (IOCondition condition, ref PollFD fd)
public void win32_set_debug (bool flag)
public IOStatus write_chars (char [] buf, out size_t bytes_written) throws ConvertError , IOChannelError
public IOStatus write_unichar (unichar thechar) throws ConvertError , IOChannelError