Beam-lib  2.16.3
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) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef BPOLL_H
8 #define BPOLL_H 1
9 
10 #include <BList.h>
11 #include <BError.h>
12 
13 #if TARGET_win32 || TARGET_win64
14 //#undef _WIN32_WINNT
15 //#define _WIN32_WINNT WindowsVista
16 #include <winsock2.h>
17 #define POLLRDNORM 0x0100
18 #define POLLRDBAND 0x0200
19 #define POLLIN (POLLRDNORM | POLLRDBAND)
20 #define POLLPRI 0x0400
21 
22 #define POLLWRNORM 0x0010
23 #define POLLOUT (POLLWRNORM)
24 #define POLLWRBAND 0x0020
25 
26 #define POLLERR 0x0001
27 #define POLLHUP 0x0002
28 #define POLLNVAL 0x0004
29 #define NFDBITS (8 * sizeof(int))
30 
31 struct pollfd {
32  int fd; /* File descriptor to poll. */
33  short int events; /* Types of events poller cares about. */
34  short int revents; /* Types of events that actually occurred. */
35 };
36 
37 #else
38 #include <sys/poll.h>
39 #endif
40 
43 class BPoll {
44 public:
45  typedef struct pollfd PollFd;
46 
47  BPoll();
48  ~BPoll();
49 
50  void append(int fd, int events = POLLIN|POLLERR|POLLHUP|POLLNVAL);
51  void delFd(int fd);
52 
53  BError doPoll(int& fd, int timeoutUs = -1);
54  BError doPollEvents(int& fd, int& events, int timeoutUs = -1);
55 
56  int getPollFdsNum();
57  PollFd* getPollFds();
58  void clear();
59 private:
60  int nextFd(int i);
61 
62  int ofdsNum;
63  PollFd* ofds;
64  int ofdsNext;
65 };
66 
67 #endif
BPoll()
Definition: BPoll.cpp:146
int getPollFdsNum()
Definition: BPoll.cpp:193
BError doPoll(int &fd, int timeoutUs=-1)
Perform polling operation.
Definition: BPoll.cpp:201
BError doPollEvents(int &fd, int &events, int timeoutUs=-1)
Perform polling operation and return events.
Definition: BPoll.cpp:240
struct pollfd PollFd
Definition: BPoll.h:45
This class provides an interface for polling a number of file descriptors. It uses round robin pollin...
Definition: BPoll.h:43
~BPoll()
Definition: BPoll.cpp:152
PollFd * getPollFds()
Definition: BPoll.cpp:197
void append(int fd, int events=POLLIN|POLLERR|POLLHUP|POLLNVAL)
Append a file descriptor to polling list.
Definition: BPoll.cpp:160
void delFd(int fd)
Remove a file descriptor from polling list.
Definition: BPoll.cpp:168
void clear()
Definition: BPoll.cpp:280
Definition: BError.h:25