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#include <sys/_timeval.h>
31
32/* Newlib used to define fd_set and friends in <sys/types.h>, but at some point
33 that stopped being the case... This should tell us whether we need to define
34 it here or not... */
35#ifndef _SYS_TYPES_FD_SET
36
37#define _SYS_TYPES_FD_SET
38
39#define NFDBITS 32
40
41/** \brief Represents a set of file descriptors */
42typedef struct fd_set {
43 unsigned long fds_bits[FD_SETSIZE / NFDBITS];
44} fd_set;
45
46#define FD_SET(n, p) ((p)->fds_bits[(n) / NFDBITS] |= (1 << ((n) % NFDBITS)))
47#define FD_CLR(n, p) ((p)->fds_bits[(n) / NFDBITS] &= ~(1 << ((n) % NFDBITS)))
48#define FD_ISSET(n, p) ((p)->fds_bits[(n) / NFDBITS] & (1 << ((n) % NFDBITS)))
49#define FD_ZERO(p) \
50 do { \
51 int __i; \
52 for(__i = 0; __i < FD_SETSIZE / NFDBITS; ++__i) { \
53 (p)->fds_bits[__i] = 0; \
54 } \
55 } while(0)
56
57#endif /* !_SYS_TYPES_FD_SET */
58
59/** \brief Wait for activity on a group of file descriptors.
60
61 This function will check the specified group of file descriptors for activity
62 and wait for activity (up to the timeout specified) if there is not any
63 pending events already.
64
65 \param nfds The maximum fd specified in any of the sets, plus 1.
66 \param readfds File descriptors to check for the ability to read
67 without blocking.
68 \param writefds File descriptors to check for the ability to write
69 without blocking.
70 \param errorfds File descriptors to check for error/exceptional
71 conditions.
72 \param timeout Maximum amount of time to block. Passing a 0 timeout
73 will make the function not block, Passing NULL here will
74 make the function block indefinitely.
75 \return -1 on error (sets errno as appropriate), or the number
76 of bits set in the fd sets on success (this may be 0 if
77 the timeout expires).
78*/
79int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
80 struct timeval *timeout);
81
82__END_DECLS
83
84#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:139
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:39
Represents a set of file descriptors.
Definition select.h:42
unsigned long fds_bits[FD_SETSIZE/NFDBITS]
Definition select.h:43