File: selector

package info (click to toggle)
bobcat 6.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,960 kB
  • sloc: cpp: 18,954; fortran: 5,617; makefile: 2,787; sh: 659; perl: 401; ansic: 26
file content (71 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download | duplicates (3)
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
#ifndef INCLUDED_BOBCAT_SELECTOR_
#define INCLUDED_BOBCAT_SELECTOR_

#include <sys/select.h>

#include <bobcat/exception>

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    .f
                                // occurred, -1: select() failed.

        int exceptFd();                                                 // .f
        int readFd();               // -1 if no more available             .f
                                    // descriptors otherwise the next
                                    // available fd in each category
        int writeFd();                                                  // .f
        void setAlarm(int sec, int usec = 0);
        void noAlarm();                                                 // .f
        void addReadFd(int fd);                                         // .f
        void addWriteFd(int fd);                                        // .f
        void addExceptFd(int fd);                                       // .f
        void rmReadFd(int fd);                                          // .f
        void rmWriteFd(int fd);                                         // .f
        void rmExceptFd(int fd);                                        // .f

    private:
        int checkSet(int *index, fd_set const &set);
        void addFd(fd_set *set, int fd);

        static bool isEmpty(fd_set const &set);
};

#include "addexceptfd.f"
#include "addreadfd.f"
#include "addwritefd.f"
#include "exceptfd.f"
#include "noalarm.f"
#include "nready.f"
#include "readfd.f"
#include "rmexceptfd.f"
#include "rmreadfd.f"
#include "rmwritefd.f"
#include "writefd.f"

} // FBB

#endif