KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
select.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 sys/select.h
4 Copyright (C) 2012 Lawrence Sebald
5
6*/
7
8/** \file select.h
9 \brief Definitions for the select() function.
10 \ingroup networking_sockets
11
12 This file contains the definitions needed for using the select() function,
13 as directed by the POSIX 2008 standard (aka The Open Group Base
14 Specifications Issue 7). Currently the functionality defined herein only
15 really works for sockets, and that is likely how it will stay for some time.
16
17 \author Lawrence Sebald
18*/
19
20#ifndef __SYS_SELECT_H
21#define __SYS_SELECT_H
22
23#include <sys/cdefs.h>
24#include <sys/types.h>
25
26__BEGIN_DECLS
27
28#include <newlib.h>
29#include <kos/opts.h>
30
31#if __NEWLIB__ > 2 || (__NEWLIB__ == 2 && __NEWLIB_MINOR__ > 2)
32#include <sys/_timeval.h>
33#else
34#include <time.h>
35#include <sys/time.h>
36#endif
37
38/* Newlib used to define fd_set and friends in <sys/types.h>, but at some point
39 that stopped being the case... This should tell us whether we need to define
40 it here or not... */
41#ifndef _SYS_TYPES_FD_SET
42
43#define _SYS_TYPES_FD_SET
44
45#define NFDBITS 32
46
47/** \brief Represents a set of file descriptors */
48typedef struct fd_set {
49 unsigned long fds_bits[FD_SETSIZE / NFDBITS];
50} fd_set;
51
52#define FD_SET(n, p) ((p)->fds_bits[(n) / NFDBITS] |= (1 << ((n) % NFDBITS)))
53#define FD_CLR(n, p) ((p)->fds_bits[(n) / NFDBITS] &= ~(1 << ((n) % NFDBITS)))
54#define FD_ISSET(n, p) ((p)->fds_bits[(n) / NFDBITS] & (1 << ((n) % NFDBITS)))
55#define FD_ZERO(p) \
56 do { \
57 int __i; \
58 for(__i = 0; __i < FD_SETSIZE / NFDBITS; ++__i) { \
59 (p)->fds_bits[__i] = 0; \
60 } \
61 } while(0)
62
63#endif /* !_SYS_TYPES_FD_SET */
64
65/** \brief Wait for activity on a group of file descriptors.
66
67 This function will check the specified group of file descriptors for activity
68 and wait for activity (up to the timeout specified) if there is not any
69 pending events already.
70
71 \param nfds The maximum fd specified in any of the sets, plus 1.
72 \param readfds File descriptors to check for the ability to read
73 without blocking.
74 \param writefds File descriptors to check for the ability to write
75 without blocking.
76 \param errorfds File descriptors to check for error/exceptional
77 conditions.
78 \param timeout Maximum amount of time to block. Passing a 0 timeout
79 will make the function not block, Passing NULL here will
80 make the function block indefinitely.
81 \return -1 on error (sets errno as appropriate), or the number
82 of bits set in the fd sets on success (this may be 0 if
83 the timeout expires).
84*/
85int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
86 struct timeval *timeout);
87
88__END_DECLS
89
90#endif /* !__SYS_SELECT_H */
#define FD_SETSIZE
The number of distinct file descriptors, including files and network sockets, that can be in use at a...
Definition opts.h:136
Compile-time options regarding debugging and other topics.
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
Wait for activity on a group of file descriptors.
#define NFDBITS
Definition select.h:45
Represents a set of file descriptors.
Definition select.h:48
unsigned long fds_bits[FD_SETSIZE/NFDBITS]
Definition select.h:49
KOS-implementation of select C11 and POSIX extensions.