summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
commit0ece30dc7c0e34b4c5911969b8fa99c33c6d023c (patch)
tree671325d3fec09b999411e4e3ab84ef8259261818 /protocols/Telegram/tdlib/td/benchmark/bench_http.cpp
parent46c53ffc6809c67e4607e99951a2846c382b63b2 (diff)
Telegram: update for TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/benchmark/bench_http.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/benchmark/bench_http.cpp59
1 files changed, 29 insertions, 30 deletions
diff --git a/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp b/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp
index 6958a5b313..70fdb909c2 100644
--- a/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp
+++ b/protocols/Telegram/tdlib/td/benchmark/bench_http.cpp
@@ -1,15 +1,18 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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/net/SslStream.h"
+
+#include "td/actor/actor.h"
+#include "td/actor/ConcurrentScheduler.h"
#include "td/utils/buffer.h"
+#include "td/utils/BufferedFd.h"
#include "td/utils/logging.h"
#include "td/utils/port/IPAddress.h"
#include "td/utils/port/SocketFd.h"
@@ -18,50 +21,52 @@
#include <atomic>
#include <limits>
-namespace td {
-
std::atomic<int> counter;
-class HttpClient : public HttpOutboundConnection::Callback {
- void start_up() override {
- IPAddress addr;
+
+class HttpClient final : public td::HttpOutboundConnection::Callback {
+ void start_up() final {
+ td::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<HttpOutboundConnection>("Connect", fd.move_as_ok(), std::numeric_limits<size_t>::max(), 0, 0,
- ActorOwn<HttpOutboundConnection::Callback>(actor_id(this)));
+ auto fd = td::SocketFd::open(addr);
+ LOG_CHECK(fd.is_ok()) << fd.error();
+ connection_ = td::create_actor<td::HttpOutboundConnection>(
+ "Connect", td::BufferedFd<td::SocketFd>(fd.move_as_ok()), td::SslStream{}, std::numeric_limits<size_t>::max(),
+ 0, 0, td::ActorOwn<td::HttpOutboundConnection::Callback>(actor_id(this)));
yield();
cnt_ = 100000;
counter++;
}
- void tear_down() override {
+
+ void tear_down() final {
if (--counter == 0) {
- Scheduler::instance()->finish();
+ td::Scheduler::instance()->finish();
}
}
- void loop() override {
+
+ void loop() final {
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);
+ send_closure(connection_, &td::HttpOutboundConnection::write_next, td::BufferSlice("GET / HTTP/1.1\r\n\r\n"));
+ send_closure(connection_, &td::HttpOutboundConnection::write_ok);
LOG(INFO) << "SEND";
}
- void handle(HttpQueryPtr result) override {
+
+ void handle(td::unique_ptr<td::HttpQuery> result) final {
loop();
}
- void on_connection_error(Status error) override {
+
+ void on_connection_error(td::Status error) final {
LOG(ERROR) << "ERROR: " << error;
}
- ActorOwn<HttpOutboundConnection> connection_;
- int cnt_;
+ td::ActorOwn<td::HttpOutboundConnection> connection_;
+ int cnt_ = 0;
};
int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
- auto scheduler = make_unique<ConcurrentScheduler>();
- scheduler->init(0);
+ auto scheduler = td::make_unique<td::ConcurrentScheduler>(0, 0);
scheduler->create_actor_unsafe<HttpClient>(0, "Client1").release();
scheduler->create_actor_unsafe<HttpClient>(0, "Client2").release();
scheduler->start();
@@ -69,10 +74,4 @@ int main() {
// empty
}
scheduler->finish();
- return 0;
-}
-} // namespace td
-
-int main() {
- return td::main();
}