Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions net/net-acceptor.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public:
for(const auto& address : local_address)
{
socket s{address.ai_family, address.ai_socktype, address.ai_protocol};
if(!s) continue;
if(not s) continue;
auto yes = 1;
if(posix::setsockopt(s, posix::sol_socket, posix::so_reuseaddr, &yes, sizeof yes) < 0) continue;
if(posix::bind(s, address.ai_addr, address.ai_addrlen) < 0) continue;
Expand All @@ -44,7 +44,7 @@ public:
auto sas = posix::sockaddr_storage{};
auto saslen = posix::socklen_t{sizeof sas};
socket s = posix::accept(fd, reinterpret_cast<posix::sockaddr*>(&sas), &saslen);
if(!s) throw std::system_error{posix::get_errno(), std::system_category(),"accept failed"};
if(not s) throw std::system_error{posix::get_errno(), std::system_category(),"accept failed"};

char hbuf[posix::ni_maxhost];
char sbuf[posix::ni_maxserv];
Expand Down Expand Up @@ -88,7 +88,7 @@ private:
static_cast<decltype(tv.tv_sec)>(m_timeout.count() / 1000),
static_cast<decltype(tv.tv_usec)>(m_timeout.count() % 1000 * 1000)
};
if(!posix::select(max_fd+1, &fds, nullptr, nullptr, &tv))
if(not posix::select(max_fd+1, &fds, nullptr, nullptr, &tv))
throw std::system_error{posix::get_errno(), std::system_category(), "accept timeouted"};
}
else
Expand Down
12 changes: 6 additions & 6 deletions net/net-acceptor.test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inline bool network_tests_enabled()

auto register_acceptor_tests()
{
if(!network_tests_enabled()) return false;
if(not network_tests_enabled()) return false;

tester::bdd::scenario("Basic construction, [net]") = [] {
tester::bdd::given("An acceptor for localhost:54321") = [] {
Expand Down Expand Up @@ -72,25 +72,25 @@ auto register_acceptor_tests()
}};

auto start = std::chrono::steady_clock::now();
while (!accepted && (std::chrono::steady_clock::now() - start) < 5s) {
while (not accepted and (std::chrono::steady_clock::now() - start) < 5s) {
std::this_thread::sleep_for(100ms);
}

if (!accepted) {
if (not accepted) {
failed("Accept test timed out");
}

t1.join();
t2.join();

check_true(!accept_threw);
check_true(!connect_threw);
check_true(not accept_threw);
check_true(not connect_threw);
check_true(connect_ok);
check_true(stream_ok);
{
auto lock = std::lock_guard<std::mutex>{host_mutex};
// host might be ::1 on some systems or 127.0.0.1
check_true(host_value == "localhost" || host_value == "::1" || host_value == "127.0.0.1");
check_true(host_value == "localhost" or host_value == "::1" or host_value == "127.0.0.1");
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion net/net-acceptor_connector.test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inline bool network_tests_enabled()

auto register_acceptor_connector_tests()
{
if(!network_tests_enabled()) return false;
if(not network_tests_enabled()) return false;
std::array<int, 100> data;
for (int i = 0; i < 100; ++i) data[i] = i + 1;

Expand Down
6 changes: 3 additions & 3 deletions net/net-address_info.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public:
hints.ai_family = family;
hints.ai_socktype = socktype;

const auto is_any = node.empty() || node == "0.0.0.0" || node == "::";
const auto is_any = node.empty() or node == "0.0.0.0" or node == "::";
const auto node_str = std::string{node};
const auto service_str = std::string{service_or_port};

if (!service_str.empty() && std::isdigit(static_cast<unsigned char>(service_str[0]))) {
if (not service_str.empty() and std::isdigit(static_cast<unsigned char>(service_str[0]))) {
hints.ai_flags |= posix::ai_numericserv;
}
if (!is_any && !node_str.empty() && std::isdigit(static_cast<unsigned char>(node_str[0]))) {
if (not is_any and not node_str.empty() and std::isdigit(static_cast<unsigned char>(node_str[0]))) {
hints.ai_flags |= posix::ai_numericnode;
}

Expand Down
2 changes: 1 addition & 1 deletion net/net-connector.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ endpointstream connect(std::string_view host,
for(const auto& address : remote_address)
{
socket s{address.ai_family, address.ai_socktype, address.ai_protocol};
if(!s) continue;
if(not s) continue;

if (posix::so_nosigpipe > 0) {
// macOS: prevent SIGPIPE on broken pipe writes.
Expand Down
4 changes: 2 additions & 2 deletions net/net-connector.test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline bool network_tests_enabled()

auto register_connector_tests()
{
if(!network_tests_enabled()) return false;
if(not network_tests_enabled()) return false;

tester::bdd::scenario("Basic construction, [net]") = [] {
tester::bdd::given("A connector to google.com:http") = [] {
Expand All @@ -37,7 +37,7 @@ auto register_connector_tests()
tester::bdd::given("A connection to google.com:http") = [] {
check_nothrow([] {
const auto s = net::connect("google.com","http");
check_true(!(!s));
check_true(not(not s));
});
};
};
Expand Down
8 changes: 4 additions & 4 deletions net/net-endpoint_buf.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected:

int_type overflow(int_type ch = traits_type::eof()) override {
if (sync() == -1) return traits_type::eof();
if (!traits_type::eq_int_type(ch, traits_type::eof())) {
if (not traits_type::eq_int_type(ch, traits_type::eof())) {
*pptr() = traits_type::to_char_type(ch);
pbump(1);
return ch;
Expand All @@ -112,7 +112,7 @@ protected:
int sync() override {
auto pending = pptr() - pbase();
if (pending > 0) {
if (!send_all(pbase(), static_cast<std::size_t>(pending))) return -1;
if (not send_all(pbase(), static_cast<std::size_t>(pending))) return -1;
setp(m_output.data(), m_output.data() + N - 1);
}
return 0;
Expand All @@ -126,8 +126,8 @@ private:
if (res <= 0) {
auto err = posix::get_errno();
if (err == posix::eintr) continue;
if (err == posix::ewouldblock || err == posix::eagain) {
if (!const_cast<socket&>(m_socket).wait()) return false;
if (err == posix::ewouldblock or err == posix::eagain) {
if (not const_cast<socket&>(m_socket).wait()) return false;
continue;
}
return false;
Expand Down
14 changes: 7 additions & 7 deletions net/net-endpoint_buf.test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ auto register_endpointbuf_tests()

tester::bdd::scenario("endpointbuf_base construction, [net]") = [] {
tester::bdd::given("A socket") = [] {
if(!network_tests_enabled()) return;
if(not network_tests_enabled()) return;

auto s = socket{posix::af_inet, posix::sock_stream};
check_nothrow([&s] {
Expand All @@ -41,22 +41,22 @@ auto register_endpointbuf_tests()

tester::bdd::scenario("endpointbuf_base wait_for, [net]") = [] {
tester::bdd::given("An endpointbuf_base with a new socket") = [] {
if(!network_tests_enabled()) return;
if(not network_tests_enabled()) return;

auto s = socket{posix::af_inet, posix::sock_stream};
endpointbuf_base buf{std::move(s)};

tester::bdd::when("Calling wait_for with a short timeout") = [&buf] {
using namespace std::chrono_literals;
auto result = buf.wait_for(1ms);
check_true(!result);
check_true(not result);
};
};
};

tester::bdd::scenario("endpointbuf template construction, [net]") = [] {
tester::bdd::given("A socket") = [] {
if(!network_tests_enabled()) return;
if(not network_tests_enabled()) return;

auto s = socket{posix::af_inet, posix::sock_stream};
check_nothrow([&s] {
Expand All @@ -68,7 +68,7 @@ auto register_endpointbuf_tests()

tester::bdd::scenario("Type aliases, [net]") = [] {
tester::bdd::given("TCP and UDP endpointbuf type aliases") = [] {
if(!network_tests_enabled()) return;
if(not network_tests_enabled()) return;

auto s1 = socket{posix::af_inet, posix::sock_stream};
auto s2 = socket{posix::af_inet, posix::sock_dgram};
Expand All @@ -83,7 +83,7 @@ auto register_endpointbuf_tests()

tester::bdd::scenario("endpointbuf buffer initialization, [net]") = [] {
tester::bdd::given("An endpointbuf with a socket") = [] {
if(!network_tests_enabled()) return;
if(not network_tests_enabled()) return;

auto s = socket{posix::af_inet, posix::sock_stream};
endpointbuf<512> buf{std::move(s)};
Expand All @@ -99,7 +99,7 @@ auto register_endpointbuf_tests()

tester::bdd::scenario("endpointbuf construction with different sizes, [net]") = [] {
tester::bdd::given("Sockets for different buffer sizes") = [] {
if(!network_tests_enabled()) return;
if(not network_tests_enabled()) return;

tester::bdd::when("Creating endpointbuf with different buffer sizes") = [] {
check_nothrow([] {
Expand Down
4 changes: 2 additions & 2 deletions net/net-endpoint_stream.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public:
~iendpointstream() override { if(m_buf) delete m_buf; }
iendpointstream& operator=(iendpointstream&& s) noexcept { if(m_buf) delete m_buf; m_buf = s.m_buf; s.m_buf = nullptr; init(m_buf); return *this; }
void close() noexcept { if(m_buf) { delete m_buf; m_buf = nullptr; } }
bool wait_for(const std::chrono::milliseconds& timeout) { return m_buf->wait_for(timeout) && peek() != std::char_traits<char>::eof(); }
bool wait_for(const std::chrono::milliseconds& timeout) { return m_buf->wait_for(timeout) and peek() != std::char_traits<char>::eof(); }
private:
iendpointstream(const iendpointstream&) = delete;
gsl::owner<endpointbuf_base*> m_buf;
Expand All @@ -41,7 +41,7 @@ public:
~endpointstream() override { if(m_buf) delete m_buf; }
endpointstream& operator=(endpointstream&& s) noexcept { if(m_buf) delete m_buf; m_buf = s.m_buf; s.m_buf = nullptr; init(m_buf); return *this; }
void close() noexcept { if(m_buf) { delete m_buf; m_buf = nullptr; } }
bool wait_for(const std::chrono::milliseconds& timeout) { return m_buf->wait_for(timeout) && peek() != std::char_traits<char>::eof(); }
bool wait_for(const std::chrono::milliseconds& timeout) { return m_buf->wait_for(timeout) and peek() != std::char_traits<char>::eof(); }
private:
endpointstream(const endpointstream&) = delete;
gsl::owner<endpointbuf_base*> m_buf;
Expand Down
2 changes: 1 addition & 1 deletion net/net-endpoint_stream.test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inline bool network_tests_enabled()

auto register_endpointstream_tests()
{
if(!network_tests_enabled()) return false;
if(not network_tests_enabled()) return false;

tester::bdd::scenario("Join and Distribute (Dgram), [net]") = [] {
tester::bdd::given("A multicast join and distribute") = [] {
Expand Down
2 changes: 1 addition & 1 deletion net/net-gsl.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public:

bool operator==(const T& rhs) const {return m_ptr == rhs;}

bool operator!=(const T& rhs) const {return !(*this == rhs);}
bool operator!=(const T& rhs) const {return not(*this == rhs);}

private:

Expand Down
6 changes: 3 additions & 3 deletions net/net-http_base64.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export namespace http::base64 {
constexpr char to_index(char c)
{
if(c == '=') return 64;
if(c >= 'a' && c <= 'z') return ('Z'-'A') + 1 + (c - 'a');
if(c >= 'A' && c <= 'Z') return (c - 'A');
if(c >= '0' && c <= '9') return ('Z'-'A') + ('z'-'a') + 2 + (c - '0');
if(c >= 'a' and c <= 'z') return ('Z'-'A') + 1 + (c - 'a');
if(c >= 'A' and c <= 'Z') return (c - 'A');
if(c >= '0' and c <= '9') return ('Z'-'A') + ('z'-'a') + 2 + (c - '0');
if(c == '+') return 62;
if(c == '/') return 63;
return 64;
Expand Down
2 changes: 1 addition & 1 deletion net/net-http_escape.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace detail {

inline constexpr bool url_unreserved(unsigned char c)
{
return std::isalnum(c) != 0 || c == '-' || c == '_' || c == '.' || c == '~';
return std::isalnum(c) != 0 or c == '-' or c == '_' or c == '.' or c == '~';
}

inline void write_html_escaped(std::ostream& os, std::string_view value)
Expand Down
8 changes: 4 additions & 4 deletions net/net-http_headers.c++m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inline std::istream& operator >> (std::istream &is, headers &hdrs)
while(is.good() and is.peek() != '\r' and is.peek() != '\n')
{
std::string line;
if (!std::getline(is, line) || line == "\r" || line.empty()) break;
if (not std::getline(is, line) or line == "\r" or line.empty()) break;

auto sv = std::string_view{line};
auto pos = sv.find(':');
Expand Down Expand Up @@ -73,11 +73,11 @@ inline bool accepts_json(const headers& hdr)
{
using namespace std::string_literals;
using namespace std::string_view_literals;
if(!hdr.contains("accept"s))
if(not hdr.contains("accept"s))
return true; // No Accept header means accept anything
const auto accept_value = hdr["accept"s];
return accept_value.contains("*/*"sv) ||
accept_value.contains("application/json"sv) ||
return accept_value.contains("*/*"sv) or
accept_value.contains("application/json"sv) or
accept_value.contains("application/*"sv);
}

Expand Down
Loading
Loading