From e1ec72eab6d00b3ba38e5932bc88920f103b6e4a Mon Sep 17 00:00:00 2001 From: aunsane Date: Fri, 27 Apr 2018 21:33:17 +0300 Subject: Telegram: initial commit - tdlib moved to telegram dir --- .../Telegram/tdlib/td/benchmark/bench_http.cpp | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 protocols/Telegram/tdlib/td/benchmark/bench_http.cpp (limited to 'protocols/Telegram/tdlib/td/benchmark/bench_http.cpp') diff --git a/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp b/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp new file mode 100644 index 0000000000..6958a5b313 --- /dev/null +++ b/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp @@ -0,0 +1,78 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/actor/actor.h" + +#include "td/net/HttpOutboundConnection.h" +#include "td/net/HttpQuery.h" + +#include "td/utils/buffer.h" +#include "td/utils/logging.h" +#include "td/utils/port/IPAddress.h" +#include "td/utils/port/SocketFd.h" +#include "td/utils/Status.h" + +#include +#include + +namespace td { + +std::atomic counter; +class HttpClient : public HttpOutboundConnection::Callback { + void start_up() override { + IPAddress addr; + addr.init_ipv4_port("127.0.0.1", 8082).ensure(); + auto fd = SocketFd::open(addr); + CHECK(fd.is_ok()) << fd.error(); + connection_ = + create_actor("Connect", fd.move_as_ok(), std::numeric_limits::max(), 0, 0, + ActorOwn(actor_id(this))); + yield(); + cnt_ = 100000; + counter++; + } + void tear_down() override { + if (--counter == 0) { + Scheduler::instance()->finish(); + } + } + void loop() override { + if (cnt_-- < 0) { + return stop(); + } + send_closure(connection_, &HttpOutboundConnection::write_next, BufferSlice("GET / HTTP/1.1\r\n\r\n")); + send_closure(connection_, &HttpOutboundConnection::write_ok); + LOG(INFO) << "SEND"; + } + void handle(HttpQueryPtr result) override { + loop(); + } + void on_connection_error(Status error) override { + LOG(ERROR) << "ERROR: " << error; + } + + ActorOwn connection_; + int cnt_; +}; + +int main() { + SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); + auto scheduler = make_unique(); + scheduler->init(0); + scheduler->create_actor_unsafe(0, "Client1").release(); + scheduler->create_actor_unsafe(0, "Client2").release(); + scheduler->start(); + while (scheduler->run_main(10)) { + // empty + } + scheduler->finish(); + return 0; +} +} // namespace td + +int main() { + return td::main(); +} -- cgit v1.2.3