Skip to content

Commit

Permalink
Merge branch 'v0.21'
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed May 13, 2024
2 parents 16c917f + 5c1f5e9 commit 81f005b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/impl/certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ Certificate Certificate::FromString(string crt_pem, string key_pem) {

mbedtls::check(mbedtls_x509_crt_parse(crt.get(),
reinterpret_cast<const unsigned char *>(crt_pem.c_str()),
crt_pem.length()),
crt_pem.size() + 1),
"Failed to parse certificate");
mbedtls::check(mbedtls_pk_parse_key(pk.get(),
reinterpret_cast<const unsigned char *>(key_pem.c_str()),
key_pem.size(), NULL, 0, NULL, 0),
key_pem.size() + 1, NULL, 0, NULL, 0),
"Failed to parse key");

return Certificate(std::move(crt), std::move(pk));
Expand Down
2 changes: 1 addition & 1 deletion src/impl/internals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const size_t DEFAULT_REMOTE_MAX_MESSAGE_SIZE = 65536; // Remote max message

const size_t DEFAULT_WS_MAX_MESSAGE_SIZE = 256 * 1024; // Default max message size for WebSockets

const size_t RECV_QUEUE_LIMIT = 1024 * 1024; // Max per-channel queue size
const size_t RECV_QUEUE_LIMIT = 1024; // Max per-channel queue size (messages)

const int MIN_THREADPOOL_SIZE = 4; // Minimum number of threads in the global thread pool (>= 2)

Expand Down
12 changes: 5 additions & 7 deletions src/impl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ template <typename T> class Queue {
public:
using amount_function = std::function<size_t(const T &element)>;

Queue(size_t limit = 0, amount_function func = nullptr);
Queue(size_t limit = 0, // elements (0 means no limit)
amount_function func = nullptr);
~Queue();

void stop();
Expand All @@ -50,10 +51,7 @@ template <typename T> class Queue {

template <typename T>
Queue<T>::Queue(size_t limit, amount_function func) : mLimit(limit), mAmount(0) {
mAmountFunction = func ? func : [](const T &element) -> size_t {
static_cast<void>(element);
return 1;
};
mAmountFunction = func ? func : []([[maybe_unused]] const T &element) -> size_t { return 1; };
}

template <typename T> Queue<T>::~Queue() { stop(); }
Expand All @@ -76,7 +74,7 @@ template <typename T> bool Queue<T>::empty() const {

template <typename T> bool Queue<T>::full() const {
std::lock_guard lock(mMutex);
return mQueue.size() >= mLimit;
return mLimit > 0 && mQueue.size() >= mLimit;
}

template <typename T> size_t Queue<T>::size() const {
Expand All @@ -91,7 +89,7 @@ template <typename T> size_t Queue<T>::amount() const {

template <typename T> void Queue<T>::push(T element) {
std::unique_lock lock(mMutex);
mPushCondition.wait(lock, [this]() { return !mLimit || mQueue.size() < mLimit || mStopping; });
mPushCondition.wait(lock, [this]() { return mLimit == 0 || mQueue.size() < mLimit || mStopping; });
if (mStopping)
return;

Expand Down

0 comments on commit 81f005b

Please sign in to comment.