docs: Small improvements to glib-mkenums man page
[glib.git] / glib / gpoll.h
blob2cbd6972987733b08e38d2766d0c5681218e6a88
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 Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #ifndef __G_POLL_H__
19 #define __G_POLL_H__
21 #if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
22 #error "Only <glib.h> can be included directly."
23 #endif
25 #include <glibconfig.h>
26 #include <glib/gtypes.h>
28 G_BEGIN_DECLS
30 /* Any definitions using GPollFD or GPollFunc are primarily
31 * for Unix and not guaranteed to be the compatible on all
32 * operating systems on which GLib runs. Right now, the
33 * GLib does use these functions on Win32 as well, but interprets
34 * them in a fairly different way than on Unix. If you use
35 * these definitions, you are should be prepared to recode
36 * for different operating systems.
38 * Note that on systems with a working poll(2), that function is used
39 * in place of g_poll(). Thus g_poll() must have the same signature as
40 * poll(), meaning GPollFD must have the same layout as struct pollfd.
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).
48 * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
49 * indicate polling for messages.
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.
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.
59 typedef struct _GPollFD GPollFD;
61 /**
62 * GPollFunc:
63 * @ufds: an array of #GPollFD elements
64 * @nfsd: the number of elements in @ufds
65 * @timeout_: the maximum time to wait for an event of the file descriptors.
66 * A negative value indicates an infinite timeout.
68 * Specifies the type of function passed to g_main_context_set_poll_func().
69 * The semantics of the function should match those of the poll() system call.
71 * Returns: the number of #GPollFD elements which have events or errors
72 * reported, or -1 if an error occurred.
74 typedef gint (*GPollFunc) (GPollFD *ufds,
75 guint nfsd,
76 gint timeout_);
78 /**
79 * GPollFD:
80 * @fd: the file descriptor to poll (or a HANDLE on Win32)
81 * @events: a bitwise combination from #GIOCondition, specifying which
82 * events should be polled for. Typically for reading from a file
83 * descriptor you would use %G_IO_IN | %G_IO_HUP | %G_IO_ERR, and
84 * for writing you would use %G_IO_OUT | %G_IO_ERR.
85 * @revents: a bitwise combination of flags from #GIOCondition, returned
86 * from the poll() function to indicate which events occurred.
88 * Represents a file descriptor, which events to poll for, and which events
89 * occurred.
91 struct _GPollFD
93 #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
94 #ifndef __GTK_DOC_IGNORE__
95 gint64 fd;
96 #endif
97 #else
98 gint fd;
99 #endif
100 gushort events;
101 gushort revents;
105 * G_POLLFD_FORMAT:
107 * A format specifier that can be used in printf()-style format strings
108 * when printing the @fd member of a #GPollFD.
110 /* defined in glibconfig.h */
112 GLIB_AVAILABLE_IN_ALL
113 gint
114 g_poll (GPollFD *fds,
115 guint nfds,
116 gint timeout);
118 G_END_DECLS
120 #endif /* __G_POLL_H__ */