Bug 556186 – gpoll.h breaks gmain.h inclusion
[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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
21 #error "Only <glib.h> can be included directly."
22 #endif
23
24 #ifndef __G_POLL_H__
25 #define __G_POLL_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  *
42  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
43  * descriptor as provided by the C runtime) that can be used by
44  * MsgWaitForMultipleObjects. This does *not* include file handles
45  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
46  * WSAEventSelect to signal events when a SOCKET is readable).
47  *
48  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
49  * indicate polling for messages.
50  *
51  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
52  * (GTK) programs, as GDK itself wants to read messages and convert them
53  * to GDK events.
54  *
55  * So, unless you really know what you are doing, it's best not to try
56  * to use the main loop polling stuff for your own needs on
57  * Windows.
58  */
59 typedef struct _GPollFD GPollFD;
60 typedef gint    (*GPollFunc)    (GPollFD *ufds,
61                                  guint    nfsd,
62                                  gint     timeout_);
63
64 struct _GPollFD
65 {
66 #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
67   gint64        fd;
68 #else
69   gint          fd;
70 #endif
71   gushort       events;
72   gushort       revents;
73 };
74
75 #ifdef G_OS_WIN32
76 #if GLIB_SIZEOF_VOID_P == 8
77 #define G_POLLFD_FORMAT "%#I64x"
78 #else
79 #define G_POLLFD_FORMAT "%#x"
80 #endif
81 #else
82 #define G_POLLFD_FORMAT "%d"
83 #endif
84
85 gint g_poll (GPollFD *fds,
86              guint    nfds,
87              gint     timeout);
88
89 G_END_DECLS
90
91 #endif /* __G_POLL_H__ */