dvbd / select.h @ bfdb7446
History | View | Annotate | Download (1.45 KB)
1 |
// -*- c++ -*-
|
---|---|
2 |
/*
|
3 |
Copyright 2003 John Knottenbelt
|
4 |
|
5 |
This program is free software; you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation; either version 2 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program; if not, write to the Free Software
|
17 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
18 |
*/
|
19 |
|
20 |
|
21 |
#if !defined __SELECT_H
|
22 |
#define __SELECT_H
|
23 |
|
24 |
#include <sys/select.h> // for fd_set below |
25 |
|
26 |
class Select; |
27 |
|
28 |
// Selectable interface
|
29 |
class Selectable { |
30 |
public:
|
31 |
virtual void addSelectFDs(Select &) const = 0; |
32 |
virtual bool isReady(const Select &) const = 0; |
33 |
}; |
34 |
|
35 |
// Class wrapping select() system call
|
36 |
class Select { |
37 |
public:
|
38 |
|
39 |
Select(); |
40 |
|
41 |
void clearFDs();
|
42 |
|
43 |
void addReadFD(int fd); |
44 |
void addWriteFD(int fd); |
45 |
void addExceptFD(int fd); |
46 |
void addAlarm(long tv_sec, long tv_usec); |
47 |
|
48 |
int wait();
|
49 |
|
50 |
bool readyToRead(int fd) const; |
51 |
bool readyToWrite(int fd) const; |
52 |
bool readyToExcept(int fd) const; |
53 |
|
54 |
private:
|
55 |
int maxFD;
|
56 |
fd_set readfds, writefds, exceptfds; |
57 |
long tv_sec, tv_usec;
|
58 |
|
59 |
void setMaxFD(int fd); |
60 |
}; |
61 |
|
62 |
#endif
|