[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / glib / gpoll.h
1 /* gpoll.h - poll(2) support
2  * Copyright (C) 2008 Red Hat, Inc.
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __G_POLL_H__
19 #define __G_POLL_H__
20
21 #if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
22 #error "Only <glib.h> can be included directly."
23 #endif
24
25 #include <glib/gtypes.h>
26
27 G_BEGIN_DECLS
28
29 /* Any definitions using GPollFD or GPollFunc are primarily
30  * for Unix and not guaranteed to be the compatible on all
31  * operating systems on which GLib runs. Right now, the
32  * GLib does use these functions on Win32 as well, but interprets
33  * them in a fairly different way than on Unix. If you use
34  * these definitions, you are should be prepared to recode
35  * for different operating systems.
36  *
37  * Note that on systems with a working poll(2), that function is used
38  * in place of g_poll(). Thus g_poll() must have the same signature as
39  * poll(), meaning GPollFD must have the same layout as struct pollfd.
40  *
41  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
42  * descriptor as provided by the C runtime) that can be used by
43  * MsgWaitForMultipleObjects. This does *not* include file handles
44  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
45  * WSAEventSelect to signal events when a SOCKET is readable).
46  *
47  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
48  * indicate polling for messages.
49  *
50  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
51  * (GTK) programs, as GDK itself wants to read messages and convert them
52  * to GDK events.
53  *
54  * So, unless you really know what you are doing, it's best not to try
55  * to use the main loop polling stuff for your own needs on
56  * Windows.
57  */
58 typedef struct _GPollFD GPollFD;
59
60 /**
61  * GPollFunc:
62  * @ufds: an array of #GPollFD elements
63  * @nfsd: the number of elements in @ufds
64  * @timeout_: the maximum time to wait for an event of the file descriptors.
65  *     A negative value indicates an infinite timeout.
66  *
67  * Specifies the type of function passed to g_main_context_set_poll_func().
68  * The semantics of the function should match those of the poll() system call.
69  *
70  * Returns: the number of #GPollFD elements which have events or errors
71  *     reported, or -1 if an error occurred.
72  */
73 typedef gint    (*GPollFunc)    (GPollFD *ufds,
74                                  guint    nfsd,
75                                  gint     timeout_);
76
77 /**
78  * GPollFD:
79  * @fd: the file descriptor to poll (or a HANDLE on Win32)
80  * @events: a bitwise combination from #GIOCondition, specifying which
81  *     events should be polled for. Typically for reading from a file
82  *     descriptor you would use %G_IO_IN | %G_IO_HUP | %G_IO_ERR, and
83  *     for writing you would use %G_IO_OUT | %G_IO_ERR.
84  * @revents: a bitwise combination of flags from #GIOCondition, returned
85  *     from the poll() function to indicate which events occurred.
86  *
87  * Represents a file descriptor, which events to poll for, and which events
88  * occurred.
89  */
90 struct _GPollFD
91 {
92 #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
93 #ifndef __GTK_DOC_IGNORE__
94   gint64        fd;
95 #endif
96 #else
97   gint          fd;
98 #endif
99   gushort       events;
100   gushort       revents;
101 };
102
103 /**
104  * G_POLLFD_FORMAT:
105  *
106  * A format specifier that can be used in printf()-style format strings
107  * when printing the @fd member of a #GPollFD.
108  */
109 #ifdef G_OS_WIN32
110 #if GLIB_SIZEOF_VOID_P == 8
111 #define G_POLLFD_FORMAT "%#I64x"
112 #else
113 #define G_POLLFD_FORMAT "%#x"
114 #endif
115 #else
116 #define G_POLLFD_FORMAT "%d"
117 #endif
118
119 GLIB_AVAILABLE_IN_ALL
120 gint
121 g_poll (GPollFD *fds,
122         guint    nfds,
123         gint     timeout);
124
125 G_END_DECLS
126
127 #endif /* __G_POLL_H__ */