blob: e233a00150c84971923fd6dcf8d869a6018e851e [file] [log] [blame]
Ryan Keanefdebe6c2019-09-06 14:12:51 -07001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "platform/api/tls_connection.h"
6
7#include "platform/api/task_runner.h"
8
9namespace openscreen {
10namespace platform {
11
12void TlsConnection::OnWriteBlocked() {
13 if (!client_) {
14 return;
15 }
16
17 task_runner_->PostTask([this]() {
Takumi Fujimotoebcffae2019-10-21 10:56:21 -070018 // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
Ryan Keanefdebe6c2019-09-06 14:12:51 -070019 this->client_->OnWriteBlocked(this);
20 });
21}
22
23void TlsConnection::OnWriteUnblocked() {
24 if (!client_) {
25 return;
26 }
27
28 task_runner_->PostTask([this]() {
Takumi Fujimotoebcffae2019-10-21 10:56:21 -070029 // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
Ryan Keanefdebe6c2019-09-06 14:12:51 -070030 this->client_->OnWriteUnblocked(this);
31 });
32}
33
34void TlsConnection::OnError(Error error) {
35 if (!client_) {
36 return;
37 }
38
39 task_runner_->PostTask([e = std::move(error), this]() mutable {
Takumi Fujimotoebcffae2019-10-21 10:56:21 -070040 // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
Ryan Keanefdebe6c2019-09-06 14:12:51 -070041 this->client_->OnError(this, std::move(e));
42 });
43}
44
Jordan Baylesf46c0a62019-09-20 11:37:42 -070045void TlsConnection::OnRead(std::vector<uint8_t> block) {
Ryan Keanefdebe6c2019-09-06 14:12:51 -070046 if (!client_) {
47 return;
48 }
49
Jordan Baylesf46c0a62019-09-20 11:37:42 -070050 task_runner_->PostTask([b = std::move(block), this]() mutable {
Takumi Fujimotoebcffae2019-10-21 10:56:21 -070051 // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
Jordan Baylesf46c0a62019-09-20 11:37:42 -070052 this->client_->OnRead(this, std::move(b));
Ryan Keanefdebe6c2019-09-06 14:12:51 -070053 });
54}
55
56} // namespace platform
57} // namespace openscreen