Skip to content

Commit

Permalink
And ran the top-level clang-format-10, let's see ...
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorolev committed Mar 5, 2022
1 parent ced2506 commit 7988966
Show file tree
Hide file tree
Showing 223 changed files with 5,310 additions and 5,457 deletions.
4 changes: 2 additions & 2 deletions blocks/html/html.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct HTMLGeneratorOStreamScope final : HTMLGeneratorScope {
#define CURRENT_HTML_SWITCH(x, y) x y
#define HTML(...) CURRENT_HTML_SWITCH(CURRENT_HTML_SWITCH_N(CURRENT_HTML_NARGS(__VA_ARGS__)), (__VA_ARGS__))

} // namespace current::html
} // namespace html
} // namespace current

// The `htmltag` namespace is intentionally in the global scope, not within `::current`, so that it can be amended to.
Expand All @@ -168,7 +168,7 @@ struct _ final {
}
};

} // namespace ::htmltag
} // namespace htmltag

#include "tags.h"

Expand Down
2 changes: 1 addition & 1 deletion blocks/html/html_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct HTMLGeneratorHTTPResponseScope final : HTMLGeneratorScope {
std::ostream& OutputStream() override { return html_contents; }
};

} // namespace current::html
} // namespace html
} // namespace current

#endif // BLOCKS_HTML_HTTP_H
3 changes: 1 addition & 2 deletions blocks/html/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ namespace htmltag {
#define CURRENT_HTML_TAG(...) \
CURRENT_HTML_TAG_SWITCH(CURRENT_HTML_TAG_SWITCH_N(CURRENT_HTML_TAG_NARGS(__VA_ARGS__)), (__VA_ARGS__))


// clang-format off

#define CURRENT_HTML_START_ONLY_TAG_COUNT_3(tag, param1, param2) \
Expand Down Expand Up @@ -148,6 +147,6 @@ CURRENT_HTML_TAG(table, border, cellpadding);
CURRENT_HTML_TAG(tr);
CURRENT_HTML_TAG(td, align, colspan, valign);

} // namespace ::htmltag
} // namespace htmltag

#endif // BLOCKS_HTML_TAGS_H
4 changes: 2 additions & 2 deletions blocks/html/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ TEST(HTMLTest, Smoke) {
{
const auto scope = current::html::HTMLGeneratorOStreamScope(oss);
HTML(table, border(0)); // Number, not a string.
}
}
EXPECT_EQ("<table border='0'></table>", oss.str());
}
{
std::ostringstream oss;
{
const auto scope = current::html::HTMLGeneratorOStreamScope(oss);
HTML(input, value(42)); // Number, not a string.
}
}
EXPECT_EQ("<input value='42'>", oss.str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion blocks/http/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ inline typename current::weed::call_with_type<HTTP_IMPL, TS...> HTTP(TS&&... par

using current::http::HTTP;
using current::http::Request;
using current::http::Response;
using current::http::ReRegisterRoute;
using current::http::Response;
using HTTPRoutesScope = typename HTTP_IMPL::server_impl_t::HTTPRoutesScope;
using HTTPRoutesScopeEntry = current::http::HTTPServerPOSIX::HTTPRoutesScopeEntry;

Expand Down
107 changes: 52 additions & 55 deletions blocks/http/chunked_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ y:0.183947}
#include "../../bricks/strings/printf.h"
#include "../../bricks/time/chrono.h"

using current::time::Now;
using current::strings::Printf;
using current::net::http::Headers;
using current::strings::Printf;
using current::time::Now;

DEFINE_int32(port, 8181, "The port to serve chunked response on.");

Expand Down Expand Up @@ -150,58 +150,55 @@ CURRENT_STRUCT(ExampleMeta) {

// TODO(dkorolev): Finish multithreading. Need to notify active connections and wait for them to finish.
int main() {
HTTP(FLAGS_port)
.Register("/layout",
[](Request r) {
LayoutItem layout;
LayoutItem row;
layout.col.push_back(row);
r(layout,
// "layout", <-- @dkorolev, remove this source file entirely, as it's obsolete.
HTTPResponseCode.OK,
Headers({{"Connection", "close"}, {"Access-Control-Allow-Origin", "*"}}),
"application/json; charset=utf-8");
});
HTTP(FLAGS_port)
.Register("/meta",
[](Request r) {
r(ExampleMeta(),
// "meta", <-- @dkorolev, remove this source file entirely, as it's obsolete.
HTTPResponseCode.OK,
Headers({{"Connection", "close"}, {"Access-Control-Allow-Origin", "*"}}),
"application/json; charset=utf-8");
});
HTTP(FLAGS_port)
.Register("/data",
[](Request r) {
std::thread([](Request&& r) {
// Since we are in another thread, need to catch exceptions ourselves.
try {
auto response = r.connection.SendChunkedHTTPResponse(
HTTPResponseCode.OK,
{{"Connection", "keep-alive"}, {"Access-Control-Allow-Origin", "*"}},
"application/json; charset=utf-8");
std::string data;
const double begin = static_cast<double>(Now().count());
const double t = atof(r.url.query["t"].c_str());
const double end = (t > 0) ? (begin + t * 1e3) : 1e18;
double current;
while ((current = static_cast<double>(Now().count())) < end) {
std::this_thread::sleep_for(std::chrono::milliseconds(rand() % 100 + 100));
const double x = current;
const double y = sin(5e-3 * (current - begin));
data += Printf("{\"x\":%lf,\"y\":%lf}\n", x, y);
const double f = (rand() % 101) * (rand() % 101) * (rand() % 101) * 1e-6;
const size_t n = static_cast<size_t>(data.length() * f);
if (n) {
response.Send(data.substr(0, n));
data = data.substr(n);
}
}
} catch (const current::Exception& e) {
std::cerr << "Exception in data serving thread: " << e.what() << std::endl;
}
}, std::move(r)).detach();
});
HTTP(FLAGS_port).Register("/layout", [](Request r) {
LayoutItem layout;
LayoutItem row;
layout.col.push_back(row);
r(layout,
// "layout", <-- @dkorolev, remove this source file entirely, as it's obsolete.
HTTPResponseCode.OK,
Headers({{"Connection", "close"}, {"Access-Control-Allow-Origin", "*"}}),
"application/json; charset=utf-8");
});
HTTP(FLAGS_port).Register("/meta", [](Request r) {
r(ExampleMeta(),
// "meta", <-- @dkorolev, remove this source file entirely, as it's obsolete.
HTTPResponseCode.OK,
Headers({{"Connection", "close"}, {"Access-Control-Allow-Origin", "*"}}),
"application/json; charset=utf-8");
});
HTTP(FLAGS_port).Register("/data", [](Request r) {
std::thread(
[](Request&& r) {
// Since we are in another thread, need to catch exceptions ourselves.
try {
auto response = r.connection.SendChunkedHTTPResponse(
HTTPResponseCode.OK,
{{"Connection", "keep-alive"}, {"Access-Control-Allow-Origin", "*"}},
"application/json; charset=utf-8");
std::string data;
const double begin = static_cast<double>(Now().count());
const double t = atof(r.url.query["t"].c_str());
const double end = (t > 0) ? (begin + t * 1e3) : 1e18;
double current;
while ((current = static_cast<double>(Now().count())) < end) {
std::this_thread::sleep_for(std::chrono::milliseconds(rand() % 100 + 100));
const double x = current;
const double y = sin(5e-3 * (current - begin));
data += Printf("{\"x\":%lf,\"y\":%lf}\n", x, y);
const double f = (rand() % 101) * (rand() % 101) * (rand() % 101) * 1e-6;
const size_t n = static_cast<size_t>(data.length() * f);
if (n) {
response.Send(data.substr(0, n));
data = data.substr(n);
}
}
} catch (const current::Exception& e) {
std::cerr << "Exception in data serving thread: " << e.what() << std::endl;
}
},
std::move(r))
.detach();
});
HTTP(FLAGS_port).Join();
}
5 changes: 2 additions & 3 deletions blocks/http/impl/posix_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct HTTPRedirectHelper : current::net::HTTPDefaultHelper {
current::net::HTTPDefaultHelper::OnHeader(key, value);
}
};
} // namespace current::http::impl
} // namespace impl

template <class HTTP_HELPER>
class GenericHTTPClientPOSIX final {
Expand Down Expand Up @@ -94,8 +94,7 @@ class GenericHTTPClientPOSIX final {
port = 80;
}
}
current::net::Connection connection(
current::net::Connection(current::net::ClientSocket(parsed_url.host, port)));
current::net::Connection connection(current::net::Connection(current::net::ClientSocket(parsed_url.host, port)));
connection.BlockingWrite(
request_method_ + ' ' + parsed_url.path + parsed_url.ComposeParameters() + " HTTP/1.1\r\n", true);
connection.BlockingWrite("Host: " + parsed_url.host + "\r\n", true);
Expand Down
7 changes: 5 additions & 2 deletions blocks/http/impl/posix_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class HTTPServerPOSIX final {
// Since instances of `HTTPServerPOSIX` are created via a singleton,
// a listening thread will only be created once per port, on the first access to that port.
explicit HTTPServerPOSIX(current::net::BarePort port)
: terminating_(false), port_(static_cast<uint16_t>(port)), thread_([this, port]() { Thread(current::net::Socket(port)); }) {}
: terminating_(false),
port_(static_cast<uint16_t>(port)),
thread_([this, port]() { Thread(current::net::Socket(port)); }) {}
explicit HTTPServerPOSIX(current::net::ReservedLocalPort reserved_port)
: terminating_(false),
port_(reserved_port),
Expand Down Expand Up @@ -223,7 +225,8 @@ class HTTPServerPOSIX final {
const URLPathArgs::CountMask path_args_count_mask,
F& handler) {
std::lock_guard<std::mutex> lock(mutex_);
return DoRegisterHandler(path, [&handler](Request r) { handler(std::move(r)); }, path_args_count_mask, POLICY);
return DoRegisterHandler(
path, [&handler](Request r) { handler(std::move(r)); }, path_args_count_mask, POLICY);
}

template <ReRegisterRoute POLICY = ReRegisterRoute::ThrowOnAttempt>
Expand Down
Loading

0 comments on commit 7988966

Please sign in to comment.