Blame glib/gpoll.h

Packit ae235b
/* gpoll.h - poll(2) support
Packit ae235b
 * Copyright (C) 2008 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public License
Packit ae235b
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#ifndef __G_POLL_H__
Packit ae235b
#define __G_POLL_H__
Packit ae235b
Packit ae235b
#if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
Packit ae235b
#error "Only <glib.h> can be included directly."
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <glibconfig.h>
Packit ae235b
#include <glib/gtypes.h>
Packit ae235b
Packit ae235b
G_BEGIN_DECLS
Packit ae235b
Packit ae235b
/* Any definitions using GPollFD or GPollFunc are primarily
Packit ae235b
 * for Unix and not guaranteed to be the compatible on all
Packit ae235b
 * operating systems on which GLib runs. Right now, the
Packit ae235b
 * GLib does use these functions on Win32 as well, but interprets
Packit ae235b
 * them in a fairly different way than on Unix. If you use
Packit ae235b
 * these definitions, you are should be prepared to recode
Packit ae235b
 * for different operating systems.
Packit ae235b
 *
Packit ae235b
 * Note that on systems with a working poll(2), that function is used
Packit ae235b
 * in place of g_poll(). Thus g_poll() must have the same signature as
Packit ae235b
 * poll(), meaning GPollFD must have the same layout as struct pollfd.
Packit ae235b
 *
Packit ae235b
 * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
Packit ae235b
 * descriptor as provided by the C runtime) that can be used by
Packit ae235b
 * MsgWaitForMultipleObjects. This does *not* include file handles
Packit ae235b
 * from CreateFile, SOCKETs, nor pipe handles. (But you can use
Packit ae235b
 * WSAEventSelect to signal events when a SOCKET is readable).
Packit ae235b
 *
Packit ae235b
 * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
Packit ae235b
 * indicate polling for messages.
Packit ae235b
 *
Packit ae235b
 * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
Packit ae235b
 * (GTK) programs, as GDK itself wants to read messages and convert them
Packit ae235b
 * to GDK events.
Packit ae235b
 *
Packit ae235b
 * So, unless you really know what you are doing, it's best not to try
Packit ae235b
 * to use the main loop polling stuff for your own needs on
Packit ae235b
 * Windows.
Packit ae235b
 */
Packit ae235b
typedef struct _GPollFD GPollFD;
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GPollFunc:
Packit ae235b
 * @ufds: an array of #GPollFD elements
Packit ae235b
 * @nfsd: the number of elements in @ufds
Packit ae235b
 * @timeout_: the maximum time to wait for an event of the file descriptors.
Packit ae235b
 *     A negative value indicates an infinite timeout.
Packit ae235b
 *
Packit ae235b
 * Specifies the type of function passed to g_main_context_set_poll_func().
Packit ae235b
 * The semantics of the function should match those of the poll() system call.
Packit ae235b
 *
Packit ae235b
 * Returns: the number of #GPollFD elements which have events or errors
Packit ae235b
 *     reported, or -1 if an error occurred.
Packit ae235b
 */
Packit ae235b
typedef gint    (*GPollFunc)    (GPollFD *ufds,
Packit ae235b
                                 guint    nfsd,
Packit ae235b
                                 gint     timeout_);
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GPollFD:
Packit ae235b
 * @fd: the file descriptor to poll (or a HANDLE on Win32)
Packit ae235b
 * @events: a bitwise combination from #GIOCondition, specifying which
Packit ae235b
 *     events should be polled for. Typically for reading from a file
Packit ae235b
 *     descriptor you would use %G_IO_IN | %G_IO_HUP | %G_IO_ERR, and
Packit ae235b
 *     for writing you would use %G_IO_OUT | %G_IO_ERR.
Packit ae235b
 * @revents: a bitwise combination of flags from #GIOCondition, returned
Packit ae235b
 *     from the poll() function to indicate which events occurred.
Packit ae235b
 *
Packit ae235b
 * Represents a file descriptor, which events to poll for, and which events
Packit ae235b
 * occurred.
Packit ae235b
 */
Packit ae235b
struct _GPollFD
Packit ae235b
{
Packit ae235b
#if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
Packit ae235b
#ifndef __GTK_DOC_IGNORE__
Packit ae235b
  gint64	fd;
Packit ae235b
#endif
Packit ae235b
#else
Packit ae235b
  gint		fd;
Packit ae235b
#endif
Packit ae235b
  gushort 	events;
Packit ae235b
  gushort 	revents;
Packit ae235b
};
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_POLLFD_FORMAT:
Packit ae235b
 *
Packit ae235b
 * A format specifier that can be used in printf()-style format strings
Packit ae235b
 * when printing the @fd member of a #GPollFD.
Packit ae235b
 */
Packit ae235b
/* defined in glibconfig.h */
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint
Packit ae235b
g_poll (GPollFD *fds,
Packit ae235b
	guint    nfds,
Packit ae235b
	gint     timeout);
Packit ae235b
Packit ae235b
G_END_DECLS
Packit ae235b
Packit ae235b
#endif /* __G_POLL_H__ */