Beamlib  3.0.1
This is the Beam C++ class library.
BPoll.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BPoll.h File poll class
3  * T.Barnaby, BEAM Ltd, 01/4/05
4  * Copyright (c) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5  * For license see LICENSE.txt at the root of the beamlib source tree.
6  *******************************************************************************
7  */
8 #ifndef BPOLL_H
9 #define BPOLL_H 1
10 
11 #include <BList.h>
12 #include <BError.h>
13 
14 #if TARGET_win32 || TARGET_win64
15 //#undef _WIN32_WINNT
16 //#define _WIN32_WINNT WindowsVista
17 #include <winsock2.h>
18 
19 #ifdef ZAP
20 #define POLLRDNORM 0x0100
21 #define POLLRDBAND 0x0200
22 #define POLLIN (POLLRDNORM | POLLRDBAND)
23 #define POLLPRI 0x0400
24 
25 #define POLLWRNORM 0x0010
26 #define POLLOUT (POLLWRNORM)
27 #define POLLWRBAND 0x0020
28 
29 #define POLLERR 0x0001
30 #define POLLHUP 0x0002
31 #define POLLNVAL 0x0004
32 
33 struct pollfd {
34  int fd; /* File descriptor to poll. */
35  short int events; /* Types of events poller cares about. */
36  short int revents; /* Types of events that actually occurred. */
37 };
38 #endif
39 
40 #define NFDBITS (8 * sizeof(int))
41 
42 #else
43 #include <sys/poll.h>
44 #endif
45 
48 class BPoll {
49 public:
50  typedef struct pollfd PollFd;
51 
52  BPoll();
53  ~BPoll();
54 
55  void append(int fd, int events = POLLIN|POLLERR|POLLHUP|POLLNVAL);
56  void delFd(int fd);
57 
58  BError doPoll(int& fd, int timeoutUs = -1);
59  BError doPollEvents(int& fd, int& events, int timeoutUs = -1);
60 
61  int getPollFdsNum();
62  PollFd* getPollFds();
63  void clear();
64 private:
65  int nextFd(int i);
66 
67  int ofdsNum;
68  PollFd* ofds;
69  int ofdsNext;
70 };
71 
72 #endif
Error return class. This class is used to return the error status from a function....
Definition: BError.h:31
This class provides an interface for polling a number of file descriptors. It uses round robin pollin...
Definition: BPoll.h:48
void delFd(int fd)
Remove a file descriptor from polling list.
Definition: BPoll.cpp:169
void clear()
Definition: BPoll.cpp:282
BError doPoll(int &fd, int timeoutUs=-1)
Perform polling operation.
Definition: BPoll.cpp:202
void append(int fd, int events=POLLIN|POLLERR|POLLHUP|POLLNVAL)
Append a file descriptor to polling list.
Definition: BPoll.cpp:161
int getPollFdsNum()
Definition: BPoll.cpp:194
struct pollfd PollFd
Definition: BPoll.h:50
PollFd * getPollFds()
Definition: BPoll.cpp:198
BPoll()
Definition: BPoll.cpp:147
~BPoll()
Definition: BPoll.cpp:153
BError doPollEvents(int &fd, int &events, int timeoutUs=-1)
Perform polling operation and return events.
Definition: BPoll.cpp:241