25#include <boost/shared_ptr.hpp>
26#include <boost/enable_shared_from_this.hpp>
27#include <boost/any.hpp>
251 public boost::enable_shared_from_this<Event_set>,
253 private boost::noncopyable
317 S_PEER_SOCKET_READABLE,
328 S_PEER_SOCKET_WRITABLE,
339 S_SERVER_SOCKET_ACCEPTABLE
342 class Socket_as_any_hash;
343 class Socket_as_any_equals;
446 template<
typename Socket>
463 template<
typename Socket>
593 template<
typename Rep,
typename Period>
594 bool sync_wait(
const boost::chrono::duration<Rep, Period>& max_wait,
Error_code* err_code = 0);
956 size_t operator()(
const boost::any& sock_as_any)
const;
977 bool operator()(
const boost::any& sock_as_any1,
const boost::any& sock_as_any2)
const;
1014template<
typename Socket>
1027 FLOW_LOG_TRACE(
"Object [" << sock <<
"] wanted for event type [" << ev_type <<
"] in Event_set [" <<
this <<
"].");
1041 "Expecting amortized constant time insertion sockets container.");
1042 if (!
m_want[ev_type].insert(any(sock)).second)
1051template<
typename Socket>
1064 FLOW_LOG_TRACE(
"Object [" << sock <<
"] no longer wanted for event type [" << ev_type <<
"] in "
1065 "Event_set [" <<
this <<
"].");
1078 const any sock_as_any = sock;
1080 const bool did_erase = want_set.
erase(sock_as_any) == 1;
1091template<
typename Rep,
typename Period>
1094 assert(max_wait.count() > 0);
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns...
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Equality predicate class used in storing various sockets of types wrapped as boost::anys in the Socke...
bool operator()(const boost::any &sock_as_any1, const boost::any &sock_as_any2) const
Returns whether the two objects, which must be stored in Sockets objects, are equal by value.
Hasher class used in storing various sockets of types wrapped as boost::anys in the Sockets type.
size_t operator()(const boost::any &sock_as_any) const
Returns hash value of the given object which must be stored in a Sockets object.
A user-set collection of sockets and desired conditions on those sockets (such as: "socket has data t...
Mutex m_mutex
Mutex protecting ALL data in this object.
static void clear_ev_type_to_socks_map(Ev_type_to_socks_map *ev_type_to_socks_map)
Helper that clears each Sockets set inside an Ev_type_to_socks_map.
bool sync_wait(Error_code *err_code=0)
Blocks indefinitely until one or more of the previously described events hold – or the wait is interr...
bool sync_wait_impl(const Fine_duration &max_wait, Error_code *err_code)
Same as the public sync_wait(max_wait) but uses a Fine_clock-based Fine_duration non-template type fo...
Event_type
Type of event or condition of interest supported by class Event_set.
static std::string ev_type_to_socks_map_sizes_to_str(const Ev_type_to_socks_map &ev_type_to_socks_map)
Helper that returns a loggable string summarizing the sizes of the socket sets, by type,...
State
A state of an Event_set.
bool async_wait_finish(Error_code *err_code=0)
Moves object from State::S_WAITING to State::S_INACTIVE, and forgets any handler saved by async_wait(...
bool events_detected(Error_code *err_code=0) const
Returns true if and only if the last wait, if any, detected at least one event.
bool poll(Error_code *err_code=0)
Checks for all previously described events that currently hold, saves them for retrieval via emit_res...
bool async_wait(const Event_handler &on_event, Error_code *err_code=0)
Moves object to State::S_WAITING state, saves the given handler to be executed later (in a different,...
util::Mutex_recursive Mutex
Short-hand for reentrant mutex type.
bool add_wanted_socket(typename Socket::Ptr sock, Event_type ev_type, Error_code *err_code=0)
Adds the given socket to the set of sockets we want to know are "ready" by the definition of the give...
State m_state
See state(). Should be set before user gets access to *this. Must not be modified by non-W threads af...
Event_handler m_on_event
During State::S_WAITING, stores the handler (a void function with 1 bool argument) that will be calle...
bool swap_wanted_sockets(Sockets *target_set, Event_type ev_type, Error_code *err_code)
Efficiently exchanges the current set of sockets we want to know are "ready" by the definiton of the ...
bool emit_result_sockets(Sockets *target_set, Event_type ev_type, Error_code *err_code=0)
Gets the sockets that satisfy the condition of the given Event_type detected during the last wait.
static Ev_type_to_socks_map empty_ev_type_to_socks_map()
Creates a maximally empty Ev_type_to_socks_map: it will have all possible Event_type as keys but only...
Event_set(log::Logger *logger_ptr)
Constructs object; initializes all values to well-defined but possibly meaningless values (0,...
util::Lock_guard< Mutex > Lock_guard
Short-hand for RAII lock guard of Mutex. Use instead of boost::lock_guard for release() at least.
State state() const
Current State of the Event_set.
bool clear_wanted_sockets(Event_type ev_type, Error_code *err_code=0)
Identical to swap_wanted_sockets(&sockets, ev_type, err_code), where originally sockets is empty and ...
bool ok_to_mod_socket_set(Error_code *err_code) const
Helper that ensures the state of *this is such that one may modify the m_can and m_want socket sets.
bool events_wanted(Error_code *err_code=0) const
Returns true if and only if at least one wanted event for at least one socket is registered (via add_...
void close(Error_code *err_code=0)
Clears all stored resources (any desired events, result events, and any handler saved by async_wait()...
static const boost::unordered_map< Event_type, Function< bool(const Node *, const boost::any &)> > S_EV_TYPE_TO_IS_ACTIVE_NODE_MTD
Mapping from each possible Event_type to the Node method that determines whether the condition define...
Node * node() const
Node that produced this Event_set.
bool clear(Error_code *err_code=0)
Forgets all sockets stored in this object in any fashion.
Ev_type_to_socks_map m_can
The sockets, categorized by Event_type of interest, that were found to be "ready" (as defined in the ...
bool remove_wanted_socket(typename Socket::Ptr sock, Event_type ev_type, Error_code *err_code=0)
Opposite of add_wanted_socket().
~Event_set()
Boring destructor. Note that deletion is to be handled exclusively via shared_ptr,...
bool m_baseline_check_pending
While in State::S_WAITING, if this is true, an exhaustive check of all desired events is yet to be pe...
static std::string sock_as_any_to_str(const boost::any &sock_as_any)
Helper that returns a loggable string representing the socket stored in the given boost::any that sto...
static bool ev_type_to_socks_map_entry_is_empty(const Ev_type_to_socks_map::Value &ev_type_and_socks)
Functional helper that checks whether a given pair in an Ev_type_to_socks_map contains an empty set o...
Ev_type_to_socks_map m_want
The sockets, categorized by Event_type of interest, to check for "ready" status (as defined in the do...
Node * m_node
See node(). Should be set before user gets access to *this. Must not be modified by non-W threads aft...
bool clear_result_sockets(Event_type ev_type, Error_code *err_code=0)
Identical to emit_result_sockets(&sockets, ev_type, err_code), where originally sockets is empty and ...
An object of this class is a single Flow-protocol networking node, in the sense that: (1) it has a di...
Properties of various container types.
std::pair< Event_type const, Sockets > Value
Short-hand for key/mapped-value pairs stored in the structure.
An object of this class is a set that combines the lookup speed of an unordered_set<> and ordering an...
Iterator erase(Const_iterator const &it)
Erases the element pointed to by the given valid iterator.
Convenience class template that endows the given subclass T with nested aliases Ptr and Const_ptr ali...
#define FLOW_ERROR_EXEC_AND_THROW_ON_ERROR(ARG_ret_type, ARG_method_name,...)
Narrow-use macro that implements the error code/exception semantics expected of most public-facing Fl...
#define FLOW_ERROR_EMIT_ERROR(ARG_val)
Sets *err_code to ARG_val and logs a warning about the error using FLOW_LOG_WARNING().
#define FLOW_LOG_TRACE(ARG_stream_fragment)
Logs a TRACE message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
@ S_EVENT_SET_EVENT_ALREADY_EXISTS
Attempted to add an event into an event set, but that event already exists.
@ S_EVENT_SET_EVENT_DOES_NOT_EXIST
Attempted to work with an event that does not exist in the event set.
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
std::ostream & operator<<(std::ostream &os, const Congestion_control_selector::Strategy_choice &strategy_choice)
Serializes a Peer_socket_options::Congestion_control_strategy_choice enum to a standard ostream – the...
boost::unique_lock< Mutex > Lock_guard
Short-hand for advanced-capability RAII lock guard for any mutex, ensuring exclusive ownership of tha...
boost::recursive_mutex Mutex_recursive
Short-hand for reentrant, exclusive mutex.
Fine_duration chrono_duration_to_fine_duration(const boost::chrono::duration< Rep, Period > &dur)
Helper that takes a non-negative duration of arbitrary precision/period and converts it to Fine_durat...
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...
Fine_clock::duration Fine_duration
A high-res time duration as computed from two Fine_time_pts.