KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
poll.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 poll.h
4 Copyright (C) 2012 Lawrence Sebald
5*/
6
7/** \file poll.h
8 \brief Definitions for the poll() function.
9 \ingroup threading_polling
10
11 This file contains the definitions needed for using the poll() function, as
12 directed by the POSIX 2008 standard (aka The Open Group Base Specifications
13 Issue 7). Currently the functionality defined herein only works for sockets,
14 and that is likely how it will stay for some time.
15
16 The poll() function works quite similarly to the select() function that it
17 is quite likely that you'd be more familiar with.
18
19 \author Lawrence Sebald
20*/
21
22#ifndef __POLL_H
23#define __POLL_H
24
25#include <sys/cdefs.h>
26#include <sys/types.h>
27
28__BEGIN_DECLS
29
30/** \defgroup threading_polling Polling
31 \brief Implementation of POSIX polling.
32 \ingroup threading_posix
33 @{
34*/
35
36/** \brief Type representing a number of file descriptors.
37 \ingroup threading_polling
38 */
39typedef __uint32_t nfds_t;
40
41/** \brief Structure representing a single file descriptor used by poll().
42 \ingroup threading_polling
43 \headerfile poll.h
44*/
45struct pollfd {
46 int fd; /**< \brief The file descriptor in question. */
47 short events; /**< \brief Events to poll for on input. */
48 short revents; /**< \brief Events signalled for output. */
49};
50
51/** \defgroup poll_events Events for the poll() function
52 \brief Masks representing event types for poll()
53 \ingroup threading_polling
54
55 These are the events that can be set in the events or revents fields of the
56 struct pollfd.
57
58 @{
59*/
60#define POLLRDNORM (1 << 0) /**< \brief Normal data may be read */
61#define POLLRDBAND (1 << 1) /**< \brief Priority data may be read */
62#define POLLPRI (1 << 2) /**< \brief High-priority data may be read */
63#define POLLOUT (1 << 3) /**< \brief Normal data may be written */
64#define POLLWRNORM POLLOUT /**< \brief Normal data may be written */
65#define POLLWRBAND (1 << 4) /**< \brief Priority data may be written */
66#define POLLERR (1 << 5) /**< \brief Error has occurred (revents only) */
67#define POLLHUP (1 << 6) /**< \brief Peer disconnected (revents only) */
68#define POLLNVAL (1 << 7) /**< \brief Invalid fd (revents only) */
69
70/** \brief Data other than high-priority data may be read */
71#define POLLIN (POLLRDNORM | POLLRDBAND)
72/** @} */
73
74/** \brief Poll a group of file descriptors for activity.
75 \ingroup threading_polling
76
77 This function will poll a group of file descriptors to check for the events
78 specified on them. The function shall block for the specified period of time
79 (in milliseconds) waiting for an event to occur. The function shall return
80 as soon as at least one fd matches the events specified (or one of the error
81 conditions), or when timeout expires.
82
83 \param fds The file descriptors to check, and what events to look
84 for on each.
85 \param nfds Number of elements in fds.
86 \param timeout Maximum amount of time to block, in milliseconds. Pass
87 0 to ensure the function does not block and -1 to block
88 for an "infinite" amount of time, until an event occurs.
89
90 \return -1 on error (sets errno as appropriate), or the number
91 of file descriptors that matched the event flags before
92 the function returns.
93
94 \sa poll_events
95*/
96int poll(struct pollfd fds[], nfds_t nfds, int timeout);
97
98/** @} */
99
100__END_DECLS
101
102#endif /* !POLL_H */
__uint32_t nfds_t
Type representing a number of file descriptors.
Definition poll.h:39
int poll(struct pollfd fds[], nfds_t nfds, int timeout)
Poll a group of file descriptors for activity.
Structure representing a single file descriptor used by poll().
Definition poll.h:45
int fd
The file descriptor in question.
Definition poll.h:46
short revents
Events signalled for output.
Definition poll.h:48
short events
Events to poll for on input.
Definition poll.h:47