mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-07-15 01:23:14 -07:00
More threading improvements in root, more DNS TXT and multicast work (in progress)
This commit is contained in:
parent
9f9032ae36
commit
e08fc81397
10 changed files with 317 additions and 95 deletions
43
node/Str.hpp
43
node/Str.hpp
|
@ -151,14 +151,35 @@ public:
|
|||
return ((*this) << a.toString(tmp));
|
||||
}
|
||||
|
||||
ZT_ALWAYS_INLINE Str &append(const char *s,const unsigned int max)
|
||||
{
|
||||
if (likely(s != (const char *)0)) {
|
||||
unsigned long l = _l;
|
||||
unsigned int c = 0;
|
||||
while (*s) {
|
||||
if (c++ >= max) break;
|
||||
if (unlikely(l >= ZT_STR_CAPACITY)) {
|
||||
_s[ZT_STR_CAPACITY] = 0;
|
||||
_l = ZT_STR_CAPACITY;
|
||||
throw ZT_EXCEPTION_OUT_OF_BOUNDS;
|
||||
}
|
||||
_s[l++] = *s;
|
||||
++s;
|
||||
}
|
||||
_s[l] = 0;
|
||||
_l = (uint8_t)l;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ZT_ALWAYS_INLINE operator bool() const { return (_l != 0); }
|
||||
|
||||
ZT_ALWAYS_INLINE bool operator==(const Str &s) const { return ((_l == s._l)&&(strcmp(_s,s._s) == 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator!=(const Str &s) const { return ((_l != s._l)||(strcmp(_s,s._s) != 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator<(const Str &s) const { return ((_l < s._l)&&(strcmp(_s,s._s) < 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator>(const Str &s) const { return ((_l > s._l)&&(strcmp(_s,s._s) > 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator<=(const Str &s) const { return ((_l <= s._l)&&(strcmp(_s,s._s) <= 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator>=(const Str &s) const { return ((_l >= s._l)&&(strcmp(_s,s._s) >= 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator==(const Str &s) const { return ((_l == s._l)&&(memcmp(_s,s._s,_l) == 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator!=(const Str &s) const { return ((_l != s._l)||(memcmp(_s,s._s,_l) != 0)); }
|
||||
ZT_ALWAYS_INLINE bool operator<(const Str &s) const { return ( (_l < s._l) ? true : ((_l == s._l) ? (memcmp(_s,s._s,_l) < 0) : false) ); }
|
||||
ZT_ALWAYS_INLINE bool operator>(const Str &s) const { return (s < *this); }
|
||||
ZT_ALWAYS_INLINE bool operator<=(const Str &s) const { return !(s < *this); }
|
||||
ZT_ALWAYS_INLINE bool operator>=(const Str &s) const { return !(*this < s); }
|
||||
|
||||
ZT_ALWAYS_INLINE bool operator==(const char *s) const { return (strcmp(_s,s) == 0); }
|
||||
ZT_ALWAYS_INLINE bool operator!=(const char *s) const { return (strcmp(_s,s) != 0); }
|
||||
|
@ -167,6 +188,16 @@ public:
|
|||
ZT_ALWAYS_INLINE bool operator<=(const char *s) const { return (strcmp(_s,s) <= 0); }
|
||||
ZT_ALWAYS_INLINE bool operator>=(const char *s) const { return (strcmp(_s,s) >= 0); }
|
||||
|
||||
ZT_ALWAYS_INLINE unsigned long hashCode() const
|
||||
{
|
||||
const char *p = _s;
|
||||
unsigned long h = 0;
|
||||
char c;
|
||||
while ((c = *(p++)))
|
||||
h = (31 * h) + (unsigned long)c;
|
||||
return h;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t _l;
|
||||
char _s[ZT_STR_CAPACITY+1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue