1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * giochannel.c: IO Channel abstraction
5 * Copyright 1998 Owen Taylor
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GLib Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GLib at ftp://ftp.gtk.org/pub/gtk/.
42 g_io_channel_init (GIOChannel
*channel
)
44 channel
->channel_flags
= 0;
45 channel
->ref_count
= 1;
50 g_io_channel_ref (GIOChannel
*channel
)
52 g_return_if_fail (channel
!= NULL
);
58 g_io_channel_unref (GIOChannel
*channel
)
60 g_return_if_fail (channel
!= NULL
);
63 if (channel
->ref_count
== 0)
64 channel
->funcs
->io_free (channel
);
68 g_io_channel_read (GIOChannel
*channel
,
73 g_return_val_if_fail (channel
!= NULL
, G_IO_ERROR_UNKNOWN
);
75 return channel
->funcs
->io_read (channel
, buf
, count
, bytes_read
);
79 g_io_channel_write (GIOChannel
*channel
,
84 g_return_val_if_fail (channel
!= NULL
, G_IO_ERROR_UNKNOWN
);
86 return channel
->funcs
->io_write (channel
, buf
, count
, bytes_written
);
90 g_io_channel_seek (GIOChannel
*channel
,
94 g_return_val_if_fail (channel
!= NULL
, G_IO_ERROR_UNKNOWN
);
96 return channel
->funcs
->io_seek (channel
, offset
, type
);
100 g_io_channel_close (GIOChannel
*channel
)
102 g_return_if_fail (channel
!= NULL
);
104 channel
->funcs
->io_close (channel
);
108 g_io_create_watch (GIOChannel
*channel
,
109 GIOCondition condition
)
111 g_return_val_if_fail (channel
!= NULL
, NULL
);
113 return channel
->funcs
->io_create_watch (channel
, condition
);
117 g_io_add_watch_full (GIOChannel
*channel
,
119 GIOCondition condition
,
122 GDestroyNotify notify
)
127 g_return_val_if_fail (channel
!= NULL
, 0);
129 source
= g_io_create_watch (channel
, condition
);
131 if (priority
!= G_PRIORITY_DEFAULT
)
132 g_source_set_priority (source
, priority
);
133 g_source_set_callback (source
, (GSourceFunc
)func
, user_data
, notify
);
135 id
= g_source_attach (source
, NULL
);
136 g_source_unref (source
);
142 g_io_add_watch (GIOChannel
*channel
,
143 GIOCondition condition
,
147 return g_io_add_watch_full (channel
, G_PRIORITY_DEFAULT
, condition
, func
, user_data
, NULL
);