| 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 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. | 
| 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 |  * Lesser General Public License for more details. | 
| 13 |  * | 
| 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/>. | 
| 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 <glibconfig.h> | 
| 26 | #include <glib/gtypes.h> | 
| 27 |  | 
| 28 | G_BEGIN_DECLS | 
| 29 |  | 
| 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. | 
| 37 |  * | 
| 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. | 
| 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 |  | 
| 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. | 
| 67 |  * | 
| 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. | 
| 70 |  * | 
| 71 |  * Returns: the number of #GPollFD elements which have events or errors | 
| 72 |  *     reported, or -1 if an error occurred. | 
| 73 |  */ | 
| 74 | typedef gint    (*GPollFunc)    (GPollFD *ufds, | 
| 75 |                                  guint    nfsd, | 
| 76 |                                  gint     timeout_); | 
| 77 |  | 
| 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. | 
| 87 |  * | 
| 88 |  * Represents a file descriptor, which events to poll for, and which events | 
| 89 |  * occurred. | 
| 90 |  */ | 
| 91 | struct _GPollFD | 
| 92 | { | 
| 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; | 
| 102 | }; | 
| 103 |  | 
| 104 | /** | 
| 105 |  * G_POLLFD_FORMAT: | 
| 106 |  * | 
| 107 |  * A format specifier that can be used in printf()-style format strings | 
| 108 |  * when printing the @fd member of a #GPollFD. | 
| 109 |  */ | 
| 110 | /* defined in glibconfig.h */ | 
| 111 |  | 
| 112 | GLIB_AVAILABLE_IN_ALL | 
| 113 | gint | 
| 114 | g_poll (GPollFD *fds, | 
| 115 | 	guint    nfds, | 
| 116 | 	gint     timeout); | 
| 117 |  | 
| 118 | G_END_DECLS | 
| 119 |  | 
| 120 | #endif /* __G_POLL_H__ */ | 
| 121 |  |