[ntcore] Match standard handle layout, only allow 16 instances (#3577)

Now that there are only 16 instances, store them all statically.

Make tests more reliable by using different ports for each connection in listener tests.
This commit is contained in:
Peter Johnson
2021-09-17 12:11:00 -07:00
committed by GitHub
parent 263a248119
commit 161e211734
7 changed files with 44 additions and 75 deletions

View File

@@ -10,8 +10,8 @@
namespace nt {
// Handle data layout:
// Bits 30-28: Type
// Bits 27-20: Instance index
// Bits 30-24: Type
// Bits 23-20: Instance index
// Bits 19-0: Handle index (0/unused for instance handles)
class Handle {
@@ -40,15 +40,15 @@ class Handle {
m_handle = 0;
return;
}
m_handle = ((static_cast<int>(type) & 0xf) << 27) | ((inst & 0x7f) << 20) |
m_handle = ((static_cast<int>(type) & 0x7f) << 24) | ((inst & 0xf) << 20) |
(index & 0xfffff);
}
int GetIndex() const { return static_cast<int>(m_handle) & 0xfffff; }
Type GetType() const {
return static_cast<Type>((static_cast<int>(m_handle) >> 27) & 0xf);
return static_cast<Type>((static_cast<int>(m_handle) >> 24) & 0x7f);
}
int GetInst() const { return (static_cast<int>(m_handle) >> 20) & 0x7f; }
int GetInst() const { return (static_cast<int>(m_handle) >> 20) & 0xf; }
bool IsType(Type type) const { return type == GetType(); }
int GetTypedIndex(Type type) const { return IsType(type) ? GetIndex() : -1; }
int GetTypedInst(Type type) const { return IsType(type) ? GetInst() : -1; }