blob: ee0258c2dd6640fa13296d2943b50ae530f80c96 [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]() {
18 // TODO(issues/71): |this| may be invalid at this point.
19 this->client_->OnWriteBlocked(this);
20 });
21}
22
23void TlsConnection::OnWriteUnblocked() {
24 if (!client_) {
25 return;
26 }
27
28 task_runner_->PostTask([this]() {
29 // TODO(issues/71): |this| may be invalid at this point.
30 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 {
40 // TODO(issues/71): |this| may be invalid at this point.
41 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 {
Ryan Keanefdebe6c2019-09-06 14:12:51 -070051 // TODO(issues/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