GSimpleProxyResolver: convert docs to markdown
[glib.git] / glib / gpoll.h
blob779095799eb0796abc3594f8bb513059f75b90b7
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, 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 <glib/gtypes.h>
27 G_BEGIN_DECLS
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.
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.
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 <type>HANDLE</type> 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 gint64 fd;
95 #else
96 gint fd;
97 #endif
98 gushort events;
99 gushort revents;
102 #ifdef G_OS_WIN32
103 #if GLIB_SIZEOF_VOID_P == 8
104 #define G_POLLFD_FORMAT "%#I64x"
105 #else
106 #define G_POLLFD_FORMAT "%#x"
107 #endif
108 #else
109 #define G_POLLFD_FORMAT "%d"
110 #endif
112 GLIB_AVAILABLE_IN_ALL
113 gint g_poll (GPollFD *fds,
114 guint nfds,
115 gint timeout);
117 G_END_DECLS
119 #endif /* __G_POLL_H__ */