Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:42:02

0001 /* gpoll.h - poll(2) support
0002  * Copyright (C) 2008 Red Hat, Inc.
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public License
0017  * along with this library; if not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef __G_POLL_H__
0021 #define __G_POLL_H__
0022 
0023 #if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
0024 #error "Only <glib.h> can be included directly."
0025 #endif
0026 
0027 #include <glibconfig.h>
0028 #include <glib/gtypes.h>
0029 
0030 G_BEGIN_DECLS
0031 
0032 /* Any definitions using GPollFD or GPollFunc are primarily
0033  * for Unix and not guaranteed to be the compatible on all
0034  * operating systems on which GLib runs. Right now, the
0035  * GLib does use these functions on Win32 as well, but interprets
0036  * them in a fairly different way than on Unix. If you use
0037  * these definitions, you are should be prepared to recode
0038  * for different operating systems.
0039  *
0040  * Note that on systems with a working poll(2), that function is used
0041  * in place of g_poll(). Thus g_poll() must have the same signature as
0042  * poll(), meaning GPollFD must have the same layout as struct pollfd.
0043  *
0044  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
0045  * descriptor as provided by the C runtime) that can be used by
0046  * MsgWaitForMultipleObjects. This does *not* include file handles
0047  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
0048  * WSAEventSelect to signal events when a SOCKET is readable).
0049  *
0050  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
0051  * indicate polling for messages.
0052  *
0053  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
0054  * (GTK) programs, as GDK itself wants to read messages and convert them
0055  * to GDK events.
0056  *
0057  * So, unless you really know what you are doing, it's best not to try
0058  * to use the main loop polling stuff for your own needs on
0059  * Windows.
0060  */
0061 typedef struct _GPollFD GPollFD;
0062 
0063 /**
0064  * GPollFunc:
0065  * @ufds: an array of #GPollFD elements
0066  * @nfsd: the number of elements in @ufds
0067  * @timeout_: the maximum time to wait for an event of the file descriptors.
0068  *     A negative value indicates an infinite timeout.
0069  *
0070  * Specifies the type of function passed to g_main_context_set_poll_func().
0071  * The semantics of the function should match those of the poll() system call.
0072  *
0073  * Returns: the number of #GPollFD elements which have events or errors
0074  *     reported, or -1 if an error occurred.
0075  */
0076 typedef gint    (*GPollFunc)    (GPollFD *ufds,
0077                                  guint    nfsd,
0078                                  gint     timeout_);
0079 
0080 /**
0081  * GPollFD:
0082  * @fd: the file descriptor to poll (or a HANDLE on Win32)
0083  * @events: a bitwise combination from #GIOCondition, specifying which
0084  *     events should be polled for. Typically for reading from a file
0085  *     descriptor you would use %G_IO_IN | %G_IO_HUP | %G_IO_ERR, and
0086  *     for writing you would use %G_IO_OUT | %G_IO_ERR.
0087  * @revents: a bitwise combination of flags from #GIOCondition, returned
0088  *     from the poll() function to indicate which events occurred.
0089  *
0090  * Represents a file descriptor, which events to poll for, and which events
0091  * occurred.
0092  */
0093 struct _GPollFD
0094 {
0095 #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
0096 #ifndef __GTK_DOC_IGNORE__
0097   gint64    fd;
0098 #endif
0099 #else
0100   gint      fd;
0101 #endif
0102   gushort   events;
0103   gushort   revents;
0104 };
0105 
0106 /**
0107  * G_POLLFD_FORMAT:
0108  *
0109  * A format specifier that can be used in printf()-style format strings
0110  * when printing the @fd member of a #GPollFD.
0111  */
0112 /* defined in glibconfig.h */
0113 
0114 GLIB_AVAILABLE_IN_ALL
0115 gint
0116 g_poll (GPollFD *fds,
0117     guint    nfds,
0118     gint     timeout);
0119 
0120 G_END_DECLS
0121 
0122 #endif /* __G_POLL_H__ */