diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/salticidae/conn.h | 2 | ||||
-rw-r--r-- | include/salticidae/network.h | 4 | ||||
-rw-r--r-- | include/salticidae/ref.h | 2 | ||||
-rw-r--r-- | include/salticidae/util.h | 20 |
4 files changed, 23 insertions, 5 deletions
diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h index 4cc8b11..d93f787 100644 --- a/include/salticidae/conn.h +++ b/include/salticidae/conn.h @@ -136,7 +136,7 @@ class SegBuffer { } }; -class ConnPoolError: public SalticidaeError { +struct ConnPoolError: public SalticidaeError { using SalticidaeError::SalticidaeError; }; diff --git a/include/salticidae/network.h b/include/salticidae/network.h index ec112ad..4e966d1 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -207,8 +207,8 @@ class ClientNetwork: public MsgNetwork<OpcodeType> { void send_msg(const MsgType &msg, const NetAddr &addr); }; -class PeerNetworkError: public SalticidaeError { - using SalticidaeError::SalticidaeError; +class PeerNetworkError: public ConnPoolError { + using ConnPoolError::ConnPoolError; }; /** Peer-to-peer network where any two nodes could hold a bi-diretional message diff --git a/include/salticidae/ref.h b/include/salticidae/ref.h index f97bd43..44eb01e 100644 --- a/include/salticidae/ref.h +++ b/include/salticidae/ref.h @@ -171,7 +171,7 @@ struct _RCCtl { struct _ARCCtl { std::atomic_size_t ref_cnt; std::atomic_size_t weak_cnt; - std::atomic_uint8_t dcnt; + std::atomic<std::uint8_t> dcnt; void add_ref() { ref_cnt++; } void add_weak() { weak_cnt++; } bool release_ref() { diff --git a/include/salticidae/util.h b/include/salticidae/util.h index 39a3683..4e6825a 100644 --- a/include/salticidae/util.h +++ b/include/salticidae/util.h @@ -52,7 +52,25 @@ class SalticidaeError: public std::exception { std::string msg; public: SalticidaeError(); - SalticidaeError(const std::string &fmt, ...); + + template<typename... Args> + SalticidaeError(const std::string &fmt, Args... args) { + int guessed_size = 128; + std::string buff; + for (;;) + { + buff.resize(guessed_size); + int nwrote = snprintf((char *)buff.data(), guessed_size, fmt.c_str(), args...); + if (nwrote < 0 || nwrote == guessed_size) + { + guessed_size <<= 1; + continue; + } + buff.resize(nwrote); + msg = std::move(buff); + break; + } + } operator std::string() const { return msg; } const char *what() const throw() override { return msg.c_str(); } |