4 #include "util/asio/accept_server.h" 5 #include "util/asio/io_context_pool.h" 7 #include "util/http/http_conn_handler.h" 8 #include "util/html/sorted_table.h" 9 #include "util/stats/varz_stats.h" 11 #include "absl/strings/str_join.h" 12 #include "base/init.h" 13 #include "strings/stringpiece.h" 15 DEFINE_int32(port, 8080,
"Port number.");
18 using namespace boost;
20 namespace h2 = beast::http;
25 int main(
int argc,
char** argv) {
26 MainInitGuard guard(&argc, &argv);
31 http::Listener<> listener;
33 http::StringResponse resp = http::MakeStringResponse(h2::status::ok);
36 http::SetMime(http::kTextMime, &resp);
37 resp.set(beast::http::field::server,
"GAIA");
40 return send->Invoke(std::move(resp));
43 listener.RegisterCb(
"/foo",
false, cb);
48 auto cell = [](
auto i,
auto j) {
49 return absl::StrCat(
"Val", i,
"_", j);
53 http::StringResponse resp = http::MakeStringResponse(h2::status::ok);
54 resp.body() = SortedTable::HtmlStart();
55 SortedTable::StartTable({
"Col1",
"Col2",
"Col3",
"Col4"}, &resp.body());
56 for (
size_t i = 0; i < 300; ++i) {
57 SortedTable::Row({cell(1, i), cell(2, i), cell(3, i), cell(4, i)}, &resp.body());
59 SortedTable::EndTable(&resp.body());
60 return send->Invoke(std::move(resp));
62 listener.RegisterCb(
"/table",
false, table_cb);
65 uint16_t port = server.AddListener(FLAGS_port, &listener);
66 LOG(INFO) <<
"Listening on port " << port;
71 LOG(INFO) <<
"Exiting server...";
void Run()
Starts running all IoContext objects in the pool. Does not block.
A pool of IoContext objects, representing and managing CPU resources of the system.