diff options
| author | levlam <levlam@telegram.org> | 2021-11-06 23:45:02 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2021-11-06 23:45:02 +0300 |
| commit | 8c3d9a7710dccc2ef47d2cb39b0e9e4f7d0ed987 (patch) | |
| tree | c1254973b341f6b66438b1d8130871d7850baf0b /benchmark/bench_http_server_fast.cpp | |
| parent | eb346f5573040803d4424049dd2ba8aaa039fa56 (diff) | |
Move benchmarks out of namespace td.
Diffstat (limited to 'benchmark/bench_http_server_fast.cpp')
| -rw-r--r-- | benchmark/bench_http_server_fast.cpp | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/benchmark/bench_http_server_fast.cpp b/benchmark/bench_http_server_fast.cpp index 28881160e..50cc753a7 100644 --- a/benchmark/bench_http_server_fast.cpp +++ b/benchmark/bench_http_server_fast.cpp @@ -20,31 +20,29 @@ #include "td/utils/Slice.h" #include "td/utils/Status.h" -namespace td { - -class HttpEchoConnection final : public Actor { +class HttpEchoConnection final : public td::Actor { public: - explicit HttpEchoConnection(SocketFd fd) : fd_(std::move(fd)) { + explicit HttpEchoConnection(td::SocketFd fd) : fd_(std::move(fd)) { } private: - BufferedFd<SocketFd> fd_; - HttpReader reader_; - HttpQuery query_; + td::BufferedFd<td::SocketFd> fd_; + td::HttpReader reader_; + td::HttpQuery query_; void start_up() final { - Scheduler::subscribe(fd_.get_poll_info().extract_pollable_fd(this)); + td::Scheduler::subscribe(fd_.get_poll_info().extract_pollable_fd(this)); reader_.init(&fd_.input_buffer(), 1024 * 1024, 0); } void tear_down() final { - Scheduler::unsubscribe_before_close(fd_.get_poll_info().get_pollable_fd_ref()); + td::Scheduler::unsubscribe_before_close(fd_.get_poll_info().get_pollable_fd_ref()); fd_.close(); } void handle_query() { - query_ = HttpQuery(); - HttpHeaderCreator hc; - Slice content = "hello world"; - //auto content = BufferSlice("hello world"); + query_ = td::HttpQuery(); + td::HttpHeaderCreator hc; + td::Slice content = "hello world"; + //auto content = td::BufferSlice("hello world"); hc.init_ok(); hc.set_keep_alive(); hc.set_content_size(content.size()); @@ -60,13 +58,13 @@ class HttpEchoConnection final : public Actor { auto status = [&] { TRY_STATUS(loop_read()); TRY_STATUS(loop_write()); - return Status::OK(); + return td::Status::OK(); }(); if (status.is_error() || can_close_local(fd_)) { stop(); } } - Status loop_read() { + td::Status loop_read() { TRY_STATUS(fd_.flush_read()); while (true) { TRY_RESULT(need, reader_.read_next(&query_)); @@ -76,24 +74,25 @@ class HttpEchoConnection final : public Actor { break; } } - return Status::OK(); + return td::Status::OK(); } - Status loop_write() { + td::Status loop_write() { TRY_STATUS(fd_.flush_write()); - return Status::OK(); + return td::Status::OK(); } }; const int N = 8; -class Server final : public TcpListener::Callback { +class Server final : public td::TcpListener::Callback { public: void start_up() final { - listener_ = create_actor<TcpListener>("Listener", 8082, ActorOwn<TcpListener::Callback>(actor_id(this))); + listener_ = + td::create_actor<td::TcpListener>("Listener", 8082, td::ActorOwn<td::TcpListener::Callback>(actor_id(this))); } - void accept(SocketFd fd) final { + void accept(td::SocketFd fd) final { pos_++; auto scheduler_id = pos_ % (N != 0 ? N : 1) + (N != 0); - create_actor_on_scheduler<HttpEchoConnection>("HttpEchoConnection", scheduler_id, std::move(fd)).release(); + td::create_actor_on_scheduler<HttpEchoConnection>("HttpEchoConnection", scheduler_id, std::move(fd)).release(); } void hangup() final { LOG(ERROR) << "Hanging up.."; @@ -101,13 +100,13 @@ class Server final : public TcpListener::Callback { } private: - ActorOwn<TcpListener> listener_; + td::ActorOwn<td::TcpListener> listener_; int pos_{0}; }; int main() { SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - auto scheduler = make_unique<ConcurrentScheduler>(); + auto scheduler = td::make_unique<td::ConcurrentScheduler>(); scheduler->init(N); scheduler->create_actor_unsafe<Server>(0, "Server").release(); scheduler->start(); @@ -117,8 +116,3 @@ int main() { scheduler->finish(); return 0; } -} // namespace td - -int main() { - return td::main(); -} |
