os/ossrv/glib/glib/gpoll.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* gpoll.h - poll(2) support
sl@0
     2
 * Copyright (C) 2008 Red Hat, Inc.
sl@0
     3
 * Portions copyright (c) 2009 Nokia Corporation.  All rights reserved.
sl@0
     4
 * This library is free software; you can redistribute it and/or
sl@0
     5
 * modify it under the terms of the GNU Library General Public
sl@0
     6
 * License as published by the Free Software Foundation; either
sl@0
     7
 * version 2 of the License, or (at your option) any later version.
sl@0
     8
 *
sl@0
     9
 * This library is distributed in the hope that it will be useful,
sl@0
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
sl@0
    12
 * Library General Public License for more details.
sl@0
    13
 *
sl@0
    14
 * You should have received a copy of the GNU Library General Public
sl@0
    15
 * License along with this library; if not, write to the
sl@0
    16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
sl@0
    17
 * Boston, MA 02111-1307, USA.
sl@0
    18
 */
sl@0
    19
sl@0
    20
#if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
sl@0
    21
#error "Only <glib.h> can be included directly."
sl@0
    22
#endif
sl@0
    23
sl@0
    24
#ifndef __G_POLL_H__
sl@0
    25
#define __G_POLL_H__
sl@0
    26
sl@0
    27
#include <glib/gtypes.h>
sl@0
    28
sl@0
    29
G_BEGIN_DECLS
sl@0
    30
sl@0
    31
/* Any definitions using GPollFD or GPollFunc are primarily
sl@0
    32
 * for Unix and not guaranteed to be the compatible on all
sl@0
    33
 * operating systems on which GLib runs. Right now, the
sl@0
    34
 * GLib does use these functions on Win32 as well, but interprets
sl@0
    35
 * them in a fairly different way than on Unix. If you use
sl@0
    36
 * these definitions, you are should be prepared to recode
sl@0
    37
 * for different operating systems.
sl@0
    38
 *
sl@0
    39
 * Note that on systems with a working poll(2), that function is used
sl@0
    40
 * in place of g_poll(). Thus g_poll() must have the same signature as
sl@0
    41
 * poll(), meaning GPollFD must have the same layout as struct pollfd.
sl@0
    42
 *
sl@0
    43
 *
sl@0
    44
 * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
sl@0
    45
 * descriptor as provided by the C runtime) that can be used by
sl@0
    46
 * MsgWaitForMultipleObjects. This does *not* include file handles
sl@0
    47
 * from CreateFile, SOCKETs, nor pipe handles. (But you can use
sl@0
    48
 * WSAEventSelect to signal events when a SOCKET is readable).
sl@0
    49
 *
sl@0
    50
 * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
sl@0
    51
 * indicate polling for messages.
sl@0
    52
 *
sl@0
    53
 * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
sl@0
    54
 * (GTK) programs, as GDK itself wants to read messages and convert them
sl@0
    55
 * to GDK events.
sl@0
    56
 *
sl@0
    57
 * So, unless you really know what you are doing, it's best not to try
sl@0
    58
 * to use the main loop polling stuff for your own needs on
sl@0
    59
 * Windows.
sl@0
    60
 */
sl@0
    61
typedef struct _GPollFD GPollFD;
sl@0
    62
typedef gint	(*GPollFunc)	(GPollFD *ufds,
sl@0
    63
				 guint	  nfsd,
sl@0
    64
				 gint     timeout_);
sl@0
    65
sl@0
    66
struct _GPollFD
sl@0
    67
{
sl@0
    68
#if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
sl@0
    69
  gint64	fd;
sl@0
    70
#else
sl@0
    71
  gint		fd;
sl@0
    72
#endif
sl@0
    73
  gushort 	events;
sl@0
    74
  gushort 	revents;
sl@0
    75
};
sl@0
    76
sl@0
    77
#ifdef G_OS_WIN32
sl@0
    78
#if GLIB_SIZEOF_VOID_P == 8
sl@0
    79
#define G_POLLFD_FORMAT "%#I64x"
sl@0
    80
#else
sl@0
    81
#define G_POLLFD_FORMAT "%#x"
sl@0
    82
#endif
sl@0
    83
#else
sl@0
    84
#define G_POLLFD_FORMAT "%d"
sl@0
    85
#endif
sl@0
    86
sl@0
    87
IMPORT_C gint g_poll (GPollFD *fds,
sl@0
    88
	     guint    nfds,
sl@0
    89
	     gint     timeout);
sl@0
    90
sl@0
    91
G_END_DECLS
sl@0
    92
sl@0
    93
#endif /* __G_POLL_H__ */