Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

118 строки
3.9 KiB

  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 Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 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. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
  20. #error "Only <glib.h> can be included directly."
  21. #endif
  22. #ifndef __G_POLL_H__
  23. #define __G_POLL_H__
  24. #include <glib/gtypes.h>
  25. G_BEGIN_DECLS
  26. /* Any definitions using GPollFD or GPollFunc are primarily
  27. * for Unix and not guaranteed to be the compatible on all
  28. * operating systems on which GLib runs. Right now, the
  29. * GLib does use these functions on Win32 as well, but interprets
  30. * them in a fairly different way than on Unix. If you use
  31. * these definitions, you are should be prepared to recode
  32. * for different operating systems.
  33. *
  34. * Note that on systems with a working poll(2), that function is used
  35. * in place of g_poll(). Thus g_poll() must have the same signature as
  36. * poll(), meaning GPollFD must have the same layout as struct pollfd.
  37. *
  38. *
  39. * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
  40. * descriptor as provided by the C runtime) that can be used by
  41. * MsgWaitForMultipleObjects. This does *not* include file handles
  42. * from CreateFile, SOCKETs, nor pipe handles. (But you can use
  43. * WSAEventSelect to signal events when a SOCKET is readable).
  44. *
  45. * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
  46. * indicate polling for messages.
  47. *
  48. * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
  49. * (GTK) programs, as GDK itself wants to read messages and convert them
  50. * to GDK events.
  51. *
  52. * So, unless you really know what you are doing, it's best not to try
  53. * to use the main loop polling stuff for your own needs on
  54. * Windows.
  55. */
  56. typedef struct _GPollFD GPollFD;
  57. /**
  58. * GPollFunc:
  59. * @ufds: an array of #GPollFD elements
  60. * @nfsd: the number of elements in @ufds
  61. * @timeout_: the maximum time to wait for an event of the file descriptors.
  62. * A negative value indicates an infinite timeout.
  63. *
  64. * Specifies the type of function passed to g_main_context_set_poll_func().
  65. * The semantics of the function should match those of the poll() system call.
  66. *
  67. * Returns: the number of #GPollFD elements which have events or errors
  68. * reported, or -1 if an error occurred.
  69. */
  70. typedef gint (*GPollFunc) (GPollFD *ufds,
  71. guint nfsd,
  72. gint timeout_);
  73. /**
  74. * GPollFD:
  75. * @fd: the file descriptor to poll (or a <type>HANDLE</type> on Win32)
  76. * @events: a bitwise combination from #GIOCondition, specifying which
  77. * events should be polled for. Typically for reading from a file
  78. * descriptor you would use %G_IO_IN | %G_IO_HUP | %G_IO_ERR, and
  79. * for writing you would use %G_IO_OUT | %G_IO_ERR.
  80. * @revents: a bitwise combination of flags from #GIOCondition, returned
  81. * from the poll() function to indicate which events occurred.
  82. */
  83. struct _GPollFD
  84. {
  85. #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
  86. gint64 fd;
  87. #else
  88. gint fd;
  89. #endif
  90. gushort events;
  91. gushort revents;
  92. };
  93. #ifdef G_OS_WIN32
  94. #if GLIB_SIZEOF_VOID_P == 8
  95. #define G_POLLFD_FORMAT "%#I64x"
  96. #else
  97. #define G_POLLFD_FORMAT "%#x"
  98. #endif
  99. #else
  100. #define G_POLLFD_FORMAT "%d"
  101. #endif
  102. gint g_poll (GPollFD *fds,
  103. guint nfds,
  104. gint timeout);
  105. G_END_DECLS
  106. #endif /* __G_POLL_H__ */