1 /* gpoll.h - poll(2) support
2 * Copyright (C) 2008 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
21 #error "Only <glib.h> can be included directly."
27 #include <glib/gtypes.h>
31 /* Any definitions using GPollFD or GPollFunc are primarily
32 * for Unix and not guaranteed to be the compatible on all
33 * operating systems on which GLib runs. Right now, the
34 * GLib does use these functions on Win32 as well, but interprets
35 * them in a fairly different way than on Unix. If you use
36 * these definitions, you are should be prepared to recode
37 * for different operating systems.
39 * Note that on systems with a working poll(2), that function is used
40 * in place of g_poll(). Thus g_poll() must have the same signature as
41 * poll(), meaning GPollFD must have the same layout as struct pollfd.
44 * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
45 * descriptor as provided by the C runtime) that can be used by
46 * MsgWaitForMultipleObjects. This does *not* include file handles
47 * from CreateFile, SOCKETs, nor pipe handles. (But you can use
48 * WSAEventSelect to signal events when a SOCKET is readable).
50 * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
51 * indicate polling for messages.
53 * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
54 * (GTK) programs, as GDK itself wants to read messages and convert them
57 * So, unless you really know what you are doing, it's best not to try
58 * to use the main loop polling stuff for your own needs on
61 typedef struct _GPollFD GPollFD;
65 * @ufds: an array of #GPollFD elements
66 * @nfsd: the number of elements in @ufds
67 * @timeout_: the maximum time to wait for an event of the file descriptors.
68 * A negative value indicates an infinite timeout.
70 * Specifies the type of function passed to g_main_context_set_poll_func().
71 * The semantics of the function should match those of the poll() system call.
73 * Returns: the number of #GPollFD elements which have events or errors
74 * reported, or -1 if an error occurred.
76 typedef gint (*GPollFunc) (GPollFD *ufds,
82 * @fd: the file descriptor to poll (or a <type>HANDLE</type> on Win32)
83 * @events: a bitwise combination from #GIOCondition, specifying which
84 * events should be polled for. Typically for reading from a file
85 * descriptor you would use %G_IO_IN | %G_IO_HUP | %G_IO_ERR, and
86 * for writing you would use %G_IO_OUT | %G_IO_ERR.
87 * @revents: a bitwise combination of flags from #GIOCondition, returned
88 * from the poll() function to indicate which events occurred.
90 * Represents a file descriptor, which events to poll for, and which events
95 #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
105 #if GLIB_SIZEOF_VOID_P == 8
106 #define G_POLLFD_FORMAT "%#I64x"
108 #define G_POLLFD_FORMAT "%#x"
111 #define G_POLLFD_FORMAT "%d"
114 gint g_poll (GPollFD *fds,
120 #endif /* __G_POLL_H__ */