diff --git a/rak/error_number.h b/rak/error_number.h index d808dc39..224c3b0b 100644 --- a/rak/error_number.h +++ b/rak/error_number.h @@ -44,6 +44,12 @@ namespace rak { class error_number { public: + static const int e_again = EAGAIN; + static const int e_intr = EINTR; + static const int e_deadlk = EDEADLK; + static const int e_connreset = ECONNRESET; + static const int e_connaborted = ECONNABORTED; + error_number() : m_errno(0) {} error_number(int e) : m_errno(e) {} @@ -52,10 +58,10 @@ public: int value() const { return m_errno; } const char* c_str() const { return strerror(m_errno); } - bool is_blocked_momentary() const { return m_errno == EAGAIN || m_errno == EINTR; } - bool is_blocked_prolonged() const { return m_errno == EDEADLK; } + bool is_blocked_momentary() const { return m_errno == e_again || m_errno == e_intr; } + bool is_blocked_prolonged() const { return m_errno == e_deadlk; } - bool is_closed() const { return m_errno == ECONNRESET || m_errno == ECONNABORTED; } + bool is_closed() const { return m_errno == e_connreset || m_errno == e_connaborted; } static error_number current() { return errno; } static void clear_global() { errno = 0; } diff --git a/rak/ranges.h b/rak/ranges.h index a2440ceb..cd563962 100644 --- a/rak/ranges.h +++ b/rak/ranges.h @@ -67,13 +67,14 @@ public: // void erase(value_type r); // Find the first ranges that has an end greater than index. - inline iterator find(Type index); + iterator find(Type index); + const_iterator find(Type index) const; // Use find with no closest match. - inline bool has(Type index); + bool has(Type index) const; private: - inline void unify(iterator itr); + void unify(iterator itr); }; template @@ -109,10 +110,16 @@ ranges::find(Type index) { return std::find_if(begin(), end(), rak::less(index, rak::mem_ptr_ref(&value_type::second))); } +template +inline typename ranges::const_iterator +ranges::find(Type index) const { + return std::find_if(begin(), end(), rak::less(index, rak::mem_ptr_ref(&value_type::second))); +} + // Use find with no closest match. template inline bool -ranges::has(Type index) { +ranges::has(Type index) const { const_iterator itr = find(index); return itr != end() && index >= itr->first;