mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 01:57:14 +02:00
gpoll: introduce new ghandle type
We've long discussed having a ghandle type corresponding to HANDLE on windows and an int (fd) elsewhere. Let's add that now. We continue to maintain the 'fd' field as being an integer on Windows in order to avoid warnings about implicit casts in existing software. 'ghandleint' was introduced for that purpose.
This commit is contained in:
@@ -544,6 +544,10 @@ g_child_watch_add
|
||||
g_child_watch_add_full
|
||||
|
||||
<SUBSECTION>
|
||||
ghandle
|
||||
ghandleint
|
||||
%G_HANDLE_NULL
|
||||
g_handle_is_valid
|
||||
GPollFD
|
||||
g_poll
|
||||
G_POLLFD_FORMAT
|
||||
|
38
glib/docs.c
38
glib/docs.c
@@ -2370,5 +2370,43 @@
|
||||
* Since: 2.6
|
||||
*/
|
||||
|
||||
/* ghandle {{{1 */
|
||||
/**
|
||||
* ghandle:
|
||||
*
|
||||
* Corresponds to a HANDLE on Windows and a file descriptor elsewhere.
|
||||
*
|
||||
* Since: 2.44
|
||||
*/
|
||||
|
||||
/**
|
||||
* ghandleint:
|
||||
*
|
||||
* An integer with the same size as #ghandle. Used in #GPollFD as the
|
||||
* 'fd' field.
|
||||
*
|
||||
* Since: 2.44
|
||||
*/
|
||||
|
||||
/**
|
||||
* G_HANDLE_INVALID:
|
||||
*
|
||||
* A value used to denote an invalid handle. Can always be safely
|
||||
* compared to #ghandle.
|
||||
*
|
||||
* See also g_handle_is_valid().
|
||||
*
|
||||
* Since: 2.44
|
||||
*/
|
||||
|
||||
/**
|
||||
* g_handle_is_valid:
|
||||
* @handle: a #ghandle
|
||||
*
|
||||
* Checks if a #ghandle is valid (ie: not equal to G_HANDLE_NULL).
|
||||
*
|
||||
* Since: 2.44
|
||||
*/
|
||||
|
||||
/* Epilogue {{{1 */
|
||||
/* vim: set foldmethod=marker: */
|
||||
|
26
glib/gpoll.h
26
glib/gpoll.h
@@ -74,6 +74,24 @@ typedef gint (*GPollFunc) (GPollFD *ufds,
|
||||
guint nfsd,
|
||||
gint timeout_);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
typedef gintptr ghandleint;
|
||||
typedef gpointer ghandle;
|
||||
#define G_HANDLE_NULL (NULL)
|
||||
#else
|
||||
typedef gint ghandleint;
|
||||
typedef gint ghandle;
|
||||
#define G_HANDLE_NULL (-1)
|
||||
#endif
|
||||
|
||||
G_STATIC_ASSERT(sizeof (ghandle) == sizeof (ghandleint));
|
||||
|
||||
static inline gboolean
|
||||
g_handle_is_valid (ghandle handle)
|
||||
{
|
||||
return handle != G_HANDLE_NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* GPollFD:
|
||||
* @fd: the file descriptor to poll (or a HANDLE on Win32)
|
||||
@@ -89,13 +107,7 @@ typedef gint (*GPollFunc) (GPollFD *ufds,
|
||||
*/
|
||||
struct _GPollFD
|
||||
{
|
||||
#if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
|
||||
#ifndef __GTK_DOC_IGNORE__
|
||||
gint64 fd;
|
||||
#endif
|
||||
#else
|
||||
gint fd;
|
||||
#endif
|
||||
ghandleint fd;
|
||||
gushort events;
|
||||
gushort revents;
|
||||
};
|
||||
|
Reference in New Issue
Block a user