network_condition_variable.h
1
2 #pragma once
3
4 #include <memory>
5 #include <vector>
6 #include <mutex>
7
8 namespace clan
9 {
10 class SocketHandle;
11 class NetworkConditionVariableImpl;
12
14 class NetworkEvent
15 {
16 protected:
17 virtual SocketHandle *get_socket_handle() = 0;
18
19 friend class NetworkConditionVariable;
20 };
21
23 class NetworkConditionVariable
24 {
25 public:
26 NetworkConditionVariable();
27
29 template<typename Lock>
30 bool wait(Lock &lock, int count, NetworkEvent **events, int timeout = -1)
31 {
32 lock.unlock();
33 try
34 {
35 bool result = wait_impl(count, events, timeout);
36 lock.lock();
37 return result;
38 }
39 catch (...)
40 {
41 lock.lock();
42 throw;
43 }
44 }
45
47 void notify();
48
49 private:
50 bool wait_impl(int count, NetworkEvent **events, int timeout);
51
52 std::shared_ptr<NetworkConditionVariableImpl> impl;
53 };
54 }
clan::NetworkConditionVariable::wait
bool wait(Lock &lock, int count, NetworkEvent **events, int timeout=-1)
Waits for event changes or until notify is called.
Definition: network_condition_variable.h:30
clan
Definition: clanapp.h:35
clan::NetworkEvent::get_socket_handle
virtual SocketHandle * get_socket_handle()=0
clan::NetworkConditionVariable::notify
void notify()
Awakens any thread waiting for event changes.
clan::NetworkConditionVariable::NetworkConditionVariable
NetworkConditionVariable()
clan::NetworkConditionVariable
Condition variable that also awaken on network events.
Definition: network_condition_variable.h:23
clan::NetworkEvent
Base class for all classes that generate network events.
Definition: network_condition_variable.h:14