giochannel.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00022  * file for a list of people on the GLib Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #ifndef __G_IOCHANNEL_H__
00028 #define __G_IOCHANNEL_H__
00029 
00030 #include <gmain.h>
00031 #include <g_types.h>
00032 
00033 G_BEGIN_DECLS
00034 
00035 /* GIOChannel
00036  */
00037 
00038 typedef struct _GIOChannel      GIOChannel;
00039 typedef struct _GIOFuncs        GIOFuncs;
00040 typedef enum
00041 {
00042   G_IO_ERROR_NONE,
00043   G_IO_ERROR_AGAIN,
00044   G_IO_ERROR_INVAL,
00045   G_IO_ERROR_UNKNOWN
00046 } GIOError;
00047 typedef enum
00048 {
00049   G_SEEK_CUR,
00050   G_SEEK_SET,
00051   G_SEEK_END
00052 } GSeekType;
00053 typedef enum
00054 {
00055   G_IO_IN       GLIB_SYSDEF_POLLIN,
00056   G_IO_OUT      GLIB_SYSDEF_POLLOUT,
00057   G_IO_PRI      GLIB_SYSDEF_POLLPRI,
00058   G_IO_ERR      GLIB_SYSDEF_POLLERR,
00059   G_IO_HUP      GLIB_SYSDEF_POLLHUP,
00060   G_IO_NVAL     GLIB_SYSDEF_POLLNVAL
00061 } GIOCondition;
00062 
00063 struct _GIOChannel
00064 {
00065   guint channel_flags;
00066   guint ref_count;
00067   GIOFuncs *funcs;
00068 };
00069 
00070 typedef gboolean (*GIOFunc) (GIOChannel   *source,
00071                              GIOCondition  condition,
00072                              gpointer      data);
00073 struct _GIOFuncs
00074 {
00075   GIOError  (*io_read)         (GIOChannel   *channel, 
00076                                 gchar        *buf, 
00077                                 guint         count,
00078                                 guint        *bytes_read);
00079   GIOError  (*io_write)        (GIOChannel   *channel, 
00080                                 gchar        *buf, 
00081                                 guint         count,
00082                                 guint        *bytes_written);
00083   GIOError  (*io_seek)         (GIOChannel   *channel, 
00084                                 gint          offset, 
00085                                 GSeekType     type);
00086   void      (*io_close)        (GIOChannel   *channel);
00087   GSource * (*io_create_watch) (GIOChannel   *channel,
00088                                 GIOCondition  condition);
00089   void      (*io_free)         (GIOChannel   *channel);
00090 };
00091 
00092 void        g_io_channel_init   (GIOChannel    *channel);
00093 void        g_io_channel_ref    (GIOChannel    *channel);
00094 void        g_io_channel_unref  (GIOChannel    *channel);
00095 GIOError    g_io_channel_read   (GIOChannel    *channel, 
00096                                  gchar         *buf, 
00097                                  guint          count,
00098                                  guint         *bytes_read);
00099 GIOError  g_io_channel_write    (GIOChannel    *channel, 
00100                                  gchar         *buf, 
00101                                  guint          count,
00102                                  guint         *bytes_written);
00103 GIOError  g_io_channel_seek     (GIOChannel    *channel,
00104                                  gint           offset, 
00105                                  GSeekType      type);
00106 void      g_io_channel_close    (GIOChannel    *channel);
00107 guint     g_io_add_watch_full   (GIOChannel    *channel,
00108                                  gint           priority,
00109                                  GIOCondition   condition,
00110                                  GIOFunc        func,
00111                                  gpointer       user_data,
00112                                  GDestroyNotify notify);
00113 GSource *g_io_create_watch      (GIOChannel   *channel,
00114                                  GIOCondition  condition);
00115 guint    g_io_add_watch         (GIOChannel    *channel,
00116                                  GIOCondition   condition,
00117                                  GIOFunc        func,
00118                                  gpointer       user_data);
00119 
00120 /* On Unix, IO channels created with this function for any file
00121  * descriptor or socket.
00122  *
00123  * On Win32, use this only for files opened with the MSVCRT (the
00124  * Microsoft run-time C library) _open() or _pipe, including file
00125  * descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr).
00126  *
00127  * The term file descriptor as used in the context of Win32 refers to
00128  * the emulated Unix-like file descriptors MSVCRT provides. The native
00129  * corresponding concept is file HANDLE. There isn't as of yet a way to
00130  * get GIOChannels for file HANDLEs.
00131  */
00132 GIOChannel* g_io_channel_unix_new    (int         fd);
00133 gint        g_io_channel_unix_get_fd (GIOChannel *channel);
00134 
00135 #ifdef G_OS_WIN32
00136 
00137 #define G_WIN32_MSG_HANDLE 19981206
00138 
00139 /* Use this to get a GPollFD from a GIOChannel, so that you can call
00140  * g_io_channel_win32_poll(). After calling this you should only use
00141  * g_io_channel_read() to read from the GIOChannel, i.e. never read()
00142  * or recv() from the underlying file descriptor or SOCKET.
00143  */
00144 void        g_io_channel_win32_make_pollfd (GIOChannel   *channel,
00145                                             GIOCondition  condition,
00146                                             GPollFD      *fd);
00147 
00148 /* This can be used to wait a until at least one of the channels is readable.
00149  * On Unix you would do a select() on the file descriptors of the channels.
00150  * This should probably be available for all platforms?
00151  */
00152 gint        g_io_channel_win32_poll   (GPollFD    *fds,
00153                                        gint        n_fds,
00154                                        gint        timeout);
00155 
00156 /* This is used to add polling for Windows messages. GDK (GTk+) programs
00157  * should *not* use this.
00158  */
00159 void        g_main_poll_win32_msg_add (gint        priority,
00160                                        GPollFD    *fd,
00161                                        guint       hwnd);
00162 
00163 /* An IO channel for Windows messages for window handle hwnd. */
00164 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
00165 
00166 /* An IO channel for C runtime (emulated Unix-like) file
00167  * descriptors. Identical to g_io_channel_unix_new above.
00168  * After calling g_io_add_watch() on a IO channel returned
00169  * by this function, you shouldn't call read() on the file
00170  * descriptor.
00171  */
00172 GIOChannel* g_io_channel_win32_new_fd (int         fd);
00173 
00174 /* Get the C runtime file descriptor of a channel. */
00175 gint        g_io_channel_win32_get_fd (GIOChannel *channel);
00176 
00177 /* An IO channel for a SOCK_STREAM winsock socket. The parameter
00178  * should be a SOCKET. After calling g_io_add_watch() on a IO channel
00179  * returned by this function, you shouldn't call recv() on the SOCKET.
00180  */
00181 GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
00182 
00183 #endif
00184 
00185 G_END_DECLS
00186 
00187 #endif /* __G_IOCHANNEL_H__ */

Generated on Tue Jul 5 14:14:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1