/usr/include/bobcat/selector is in libbobcat-dev 2.20.01-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #ifndef INCLUDED_BOBCAT_SELECTOR_
#define INCLUDED_BOBCAT_SELECTOR_
#include <sys/select.h>
namespace FBB
{
class Selector
{
fd_set d_read;
fd_set d_write;
fd_set d_except;
fd_set d_ret_read;
fd_set d_ret_write;
fd_set d_ret_except;
timeval d_alarm;
int d_max;
int d_ret;
int d_readidx;
int d_writeidx;
int d_exceptidx;
public:
Selector();
int wait(); // nReady() and the get...() members
// perform defined behavior only after
// wait() returns.
int nReady(); // number of available fd's. 0: timeout
// occurred, -1: select() failed.
int exceptFd();
int readFd(); // -1 if no more available descriptors
// otherwise the next available fd
// in each category
int writeFd();
void setAlarm(int sec, int usec = 0);
void noAlarm();
void addReadFd(int fd);
void addWriteFd(int fd);
void addExceptFd(int fd);
void rmReadFd(int fd);
void rmWriteFd(int fd);
void rmExceptFd(int fd);
private:
int checkSet(int *index, fd_set &set);
void addFd(fd_set *set, int fd);
};
inline int Selector::nReady()
{
return d_ret;
}
inline int Selector::exceptFd()
{
return checkSet(&d_exceptidx, d_ret_except);
}
inline int Selector::readFd()
{
return checkSet(&d_readidx, d_ret_read);
}
inline int Selector::writeFd()
{
return checkSet(&d_writeidx, d_ret_write);
}
inline void Selector::noAlarm()
{
d_alarm.tv_sec = d_alarm.tv_usec = -1;
}
inline void Selector::addReadFd(int fd)
{
addFd(&d_read, fd);
}
inline void Selector::addWriteFd(int fd)
{
addFd(&d_write, fd);
}
inline void Selector::addExceptFd(int fd)
{
addFd(&d_except, fd);
}
inline void Selector::rmReadFd(int fd)
{
FD_CLR(fd, &d_read);
}
inline void Selector::rmWriteFd(int fd)
{
FD_CLR(fd, &d_write);
}
inline void Selector::rmExceptFd(int fd)
{
FD_CLR(fd, &d_except);
}
} // FBB
#endif
|