Move HandshakeActor methods to cpp.

This commit is contained in:
levlam 2021-07-22 19:03:34 +03:00
parent 562af8b4f6
commit 7f617254f0
2 changed files with 30 additions and 17 deletions

View File

@ -49,6 +49,26 @@ void HandshakeActor::loop() {
}
}
void HandshakeActor::hangup() {
finish(Status::Error(1, "Canceled"));
stop();
}
void HandshakeActor::timeout_expired() {
finish(Status::Error("Timeout expired"));
stop();
}
void HandshakeActor::tear_down() {
finish(Status::OK());
}
void HandshakeActor::finish(Status status) {
// NB: order may be important for parent
return_connection(std::move(status));
return_handshake();
}
void HandshakeActor::return_connection(Status status) {
auto raw_connection = connection_->move_as_raw_connection();
if (!raw_connection) {

View File

@ -18,7 +18,7 @@
namespace td {
namespace mtproto {
// Has Raw connection. Generates new auth key. And returns it and raw_connection. Or error...
// Owns RawConnection. Generates new auth key. And returns it and RawConnection. Or error...
class HandshakeActor final : public Actor {
public:
HandshakeActor(unique_ptr<AuthKeyHandshake> handshake, unique_ptr<RawConnection> raw_connection,
@ -36,26 +36,19 @@ class HandshakeActor final : public Actor {
Promise<unique_ptr<AuthKeyHandshake>> handshake_promise_;
void start_up() final;
void tear_down() final {
finish(Status::OK());
}
void hangup() final {
finish(Status::Error(1, "Canceled"));
stop();
}
void timeout_expired() final {
finish(Status::Error("Timeout expired"));
stop();
}
void tear_down() final;
void hangup() final;
void timeout_expired() final;
void loop() final;
void finish(Status status) {
// NB: order may be important for parent
return_connection(std::move(status));
return_handshake();
}
void finish(Status status);
void return_connection(Status status);
void return_handshake();
};