Woman, Life, Freedom


Async BSD Sockets Library
Library protected and public interface header documentation
poller.h
1#ifndef POLLER_H
2#define POLLER_H
3
4#include <map>
5#include <mutex>
6#include <functional>
7#include "./tcp_listener.h"
8
9namespace AsyncBsdSocketLib
10{
12 class Poller
13 {
14 private:
15 std::mutex mMutex;
16 int mFileDescriptor;
17 size_t mEventCounter;
18 std::map<int, std::function<void()>> mListeners;
19 std::map<int, std::function<void()>> mSenders;
20 std::map<int, std::function<void()>> mReceivers;
21
22 bool tryModifyAsSenderReceiver(int connectionDescriptor);
23
24 public:
28
29 ~Poller() noexcept;
30
36 bool TryAddListener(TcpListener *tcpListener, std::function<void()> callback);
37
43 bool TryAddSender(Communicator *communicator, std::function<void()> callback);
44
50 bool TryAddReceiver(Communicator *communicator, std::function<void()> callback);
51
56 bool TryRemoveListener(TcpListener *tcpListener);
57
62 bool TryRemoveSender(Communicator *communicator);
63
68 bool TryRemoveReceiver(Communicator *communicator);
69
75 bool TryPoll(int timeout = 0) const;
76 };
77}
78
79#endif
Communication method (i.e., network sockets and named pipes)
Definition: communicator.h:10
Communicator poller.
Definition: poller.h:13
bool TryRemoveReceiver(Communicator *communicator)
Try to remove the receiver from the poller.
bool TryRemoveSender(Communicator *communicator)
Try to remove the sender from the poller.
bool TryAddSender(Communicator *communicator, std::function< void()> callback)
Try to add a sender to the poller.
bool TryAddListener(TcpListener *tcpListener, std::function< void()> callback)
Try to add a TCP listener to the poller.
bool TryAddReceiver(Communicator *communicator, std::function< void()> callback)
Try to add a receiver to the poller.
bool TryRemoveListener(TcpListener *tcpListener)
Try to remove the TCP listener from the poller.
bool TryPoll(int timeout=0) const
Try to perform an explicit polling over all the added communicators.
TCP listener (server) to accept a TcpClient.
Definition: tcp_listener.h:14