aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/salticidae/conn.h2
-rw-r--r--include/salticidae/network.h4
-rw-r--r--include/salticidae/ref.h2
-rw-r--r--include/salticidae/util.h20
-rw-r--r--src/util.cpp20
5 files changed, 23 insertions, 25 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(); }
diff --git a/src/util.cpp b/src/util.cpp
index 07849fc..6c8866d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -64,26 +64,6 @@ const std::string get_current_datetime() {
SalticidaeError::SalticidaeError() : msg("unknown") {}
-SalticidaeError::SalticidaeError(const std::string &fmt, ...) {
- int guessed_size = 128;
- std::string buff;
- va_list ap;
- for (;;)
- {
- buff.resize(guessed_size);
- va_start(ap, fmt);
- int nwrote = vsnprintf((char *)buff.data(), guessed_size, fmt.c_str(), ap);
- if (nwrote < 0 || nwrote == guessed_size)
- {
- guessed_size <<= 1;
- continue;
- }
- buff.resize(nwrote);
- msg = std::move(buff);
- break;
- }
-}
-
void Logger::write(const char *tag, const char *fmt, va_list ap) {
fprintf(output, "%s [%s %s] ", get_current_datetime().c_str(), prefix, tag);
vfprintf(output, fmt, ap);