21#ifndef G_NET_EVENT_HANDLER_LIST_H
22#define G_NET_EVENT_HANDLER_LIST_H
33 class EventHandlerList ;
89 Iterator(
const std::vector<Value> & ,
bool ) noexcept ;
90 Iterator( std::vector<Value>::const_iterator , std::vector<Value>::const_iterator ) noexcept ;
92 const Value & operator*()
const noexcept ;
93 bool operator==(
const Iterator & )
const noexcept ;
94 bool operator!=(
const Iterator & )
const noexcept ;
99 void raiseEvent(
void (
EventHandler::*method)(EventHandler::Reason) , EventHandler::Reason ) ;
100 std::vector<Value>::const_iterator m_p ;
101 std::vector<Value>::const_iterator m_end ;
109 void operator=(
const Lock & ) = delete ;
110 void operator=(
Lock && ) = delete ;
160 void getHandles( std::vector<HANDLE> & ) const ;
164 std::
size_t size() const noexcept ;
176 using List = std::vector<
Value> ;
178 static
bool disable( List & list ,
Descriptor fd ) noexcept ;
180 static
void getHandles( const List & , std::vector<HANDLE> & ) ;
182 void commitPending() ;
183 void collectGarbage() ;
188 List m_pending_list ;
189 unsigned int m_lock ;
196 m_event_handler(event_handler),
202GNet::EventHandlerList::Value::Value(
Descriptor fd ) noexcept :
204 m_event_handler(
nullptr),
222GNet::EventHandlerList::Iterator::Iterator( std::vector<Value>::const_iterator p ,
223 std::vector<Value>::const_iterator
end ) noexcept :
230GNet::EventHandlerList::Iterator::Iterator(
const std::vector<Value> & v ,
bool end ) noexcept :
231 m_p(
end?v.end():v.begin()) ,
234 while( m_p != m_end && (*m_p).m_event_handler ==
nullptr )
242 while( m_p != m_end && (*m_p).m_event_handler ==
nullptr )
262 return (*m_p).m_event_handler ;
272bool GNet::EventHandlerList::Iterator::operator==(
const Iterator & other )
const noexcept
274 return m_p == other.m_p ;
278bool GNet::EventHandlerList::Iterator::operator!=(
const Iterator & other )
const noexcept
280 return !(*
this == other) ;
A class that encapsulates a network socket file descriptor and an associated windows event handle.
A class that maps from a file descriptor to an event handler and exception handler,...
Iterator begin() const noexcept
Returns a forward iterator.
Iterator find(Descriptor fd) const
Finds an entry in the list.
void lock()
To be called at the start of an begin()/end() iteration if the list might change during the iteration...
bool unlock()
Called at the end of a begin()/end() iteration to match a call to lock().
std::size_t size() const noexcept
Returns the size of the list, ignoring any changes while lock()ed.
EventHandlerList(const std::string &type)
Constructor.
void disarm(ExceptionHandler *) noexcept
Resets any matching ExceptionHandler pointers, so exceptions thrown out of the relevant file descript...
Iterator end() const noexcept
Returns an end iterator.
bool contains(Descriptor fd) const noexcept
Returns true if the list, taking account of any pending changes, contains the given descriptor.
void getHandles(std::vector< HANDLE > &) const
Adds unique, non-zero Descriptor handles to the given sorted list, including any add()ed while lock()...
void remove(Descriptor fd) noexcept
Removes a file-descriptor from the list.
void add(Descriptor fd, EventHandler *handler, ExceptionSink)
Adds a file-descriptor/handler tuple to the list.
A base class for classes that handle asynchronous events from the event loop.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket/future event...
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
An iterator for GNet::EventHandlerList.
A RAII class to lock and unlock GNet::EventHandlerList.
A tuple for GNet::EventHandlerList.