Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 1 | // 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 | |
| 9 | namespace openscreen { |
| 10 | namespace platform { |
| 11 | |
| 12 | void TlsConnection::OnWriteBlocked() { |
| 13 | if (!client_) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | task_runner_->PostTask([this]() { |
Takumi Fujimoto | ebcffae | 2019-10-21 10:56:21 -0700 | [diff] [blame] | 18 | // TODO(crbug.com/openscreen/71): |this| may be invalid at this point. |
Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 19 | this->client_->OnWriteBlocked(this); |
| 20 | }); |
| 21 | } |
| 22 | |
| 23 | void TlsConnection::OnWriteUnblocked() { |
| 24 | if (!client_) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | task_runner_->PostTask([this]() { |
Takumi Fujimoto | ebcffae | 2019-10-21 10:56:21 -0700 | [diff] [blame] | 29 | // TODO(crbug.com/openscreen/71): |this| may be invalid at this point. |
Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 30 | this->client_->OnWriteUnblocked(this); |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | void TlsConnection::OnError(Error error) { |
| 35 | if (!client_) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | task_runner_->PostTask([e = std::move(error), this]() mutable { |
Takumi Fujimoto | ebcffae | 2019-10-21 10:56:21 -0700 | [diff] [blame] | 40 | // TODO(crbug.com/openscreen/71): |this| may be invalid at this point. |
Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 41 | this->client_->OnError(this, std::move(e)); |
| 42 | }); |
| 43 | } |
| 44 | |
Jordan Bayles | f46c0a6 | 2019-09-20 11:37:42 -0700 | [diff] [blame] | 45 | void TlsConnection::OnRead(std::vector<uint8_t> block) { |
Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 46 | if (!client_) { |
| 47 | return; |
| 48 | } |
| 49 | |
Jordan Bayles | f46c0a6 | 2019-09-20 11:37:42 -0700 | [diff] [blame] | 50 | task_runner_->PostTask([b = std::move(block), this]() mutable { |
Takumi Fujimoto | ebcffae | 2019-10-21 10:56:21 -0700 | [diff] [blame] | 51 | // TODO(crbug.com/openscreen/71): |this| may be invalid at this point. |
Jordan Bayles | f46c0a6 | 2019-09-20 11:37:42 -0700 | [diff] [blame] | 52 | this->client_->OnRead(this, std::move(b)); |
Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 53 | }); |
| 54 | } |
| 55 | |
| 56 | } // namespace platform |
| 57 | } // namespace openscreen |