Skip to content

Commit af1a975

Browse files
committed
Fix cpplint style issues
- Move opening brace to end of line in policy_callback - Replace using-directive with using-declaration for chrono_literals - Use static_cast instead of C-style cast - Use rand_r instead of rand for thread safety
1 parent 4ff6dfa commit af1a975

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/webserver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ MHD_Result policy_callback(void *cls, const struct sockaddr* addr, socklen_t add
463463
const bool is_allowed = ws->allowances.count(ip_representation(addr));
464464

465465
if ((ws->default_policy == http_utils::ACCEPT && is_banned && !is_allowed) ||
466-
(ws->default_policy == http_utils::REJECT && (!is_allowed || is_banned)))
467-
{
466+
(ws->default_policy == http_utils::REJECT && (!is_allowed || is_banned))) {
468467
return MHD_NO;
469468
}
470469

test/integ/basic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,19 +1581,19 @@ LT_BEGIN_AUTO_TEST(basic_suite, thread_safety)
15811581
std::atomic_bool done = false;
15821582
auto register_thread = std::thread([&]() {
15831583
int i = 0;
1584-
using namespace std::chrono;
15851584
while (!done) {
15861585
ws->register_resource(
15871586
std::string("/route") + std::to_string(++i), &resource);
15881587
}
15891588
});
15901589

15911590
auto get_thread = std::thread([&](){
1591+
unsigned int seed = 42;
15921592
while (!done) {
15931593
CURL *curl = curl_easy_init();
15941594
std::string s;
15951595
std::string url = "localhost:" PORT_STRING "/route" + std::to_string(
1596-
(int)((rand() * 10000000.0) / RAND_MAX));
1596+
static_cast<int>((rand_r(&seed) * 10000000.0) / RAND_MAX));
15971597
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
15981598
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
15991599
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
@@ -1603,7 +1603,7 @@ LT_BEGIN_AUTO_TEST(basic_suite, thread_safety)
16031603
}
16041604
});
16051605

1606-
using namespace std::chrono_literals;
1606+
using std::chrono_literals::operator""s;
16071607
std::this_thread::sleep_for(10s);
16081608
done = true;
16091609
if (register_thread.joinable()) {

0 commit comments

Comments
 (0)