Vitaly Buka | cad20f0 | 2015-10-16 17:27:15 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 14 | |
| 15 | #ifndef BUFFET_SOCKET_STREAM_H_ |
| 16 | #define BUFFET_SOCKET_STREAM_H_ |
| 17 | |
| 18 | #include <string> |
| 19 | |
| 20 | #include <base/callback.h> |
| 21 | #include <base/macros.h> |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 22 | #include <brillo/streams/stream.h> |
Alex Vakulenko | 94f8eba | 2015-10-14 08:52:45 -0700 | [diff] [blame] | 23 | #include <weave/provider/network.h> |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 24 | #include <weave/stream.h> |
| 25 | |
| 26 | namespace buffet { |
| 27 | |
| 28 | class SocketStream : public weave::Stream { |
| 29 | public: |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 30 | explicit SocketStream(brillo::StreamPtr ptr) : ptr_{std::move(ptr)} {} |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 31 | |
| 32 | ~SocketStream() override = default; |
| 33 | |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame] | 34 | void Read(void* buffer, |
| 35 | size_t size_to_read, |
Alex Vakulenko | 94f8eba | 2015-10-14 08:52:45 -0700 | [diff] [blame] | 36 | const ReadCallback& callback) override; |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 37 | |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame] | 38 | void Write(const void* buffer, |
| 39 | size_t size_to_write, |
Alex Vakulenko | 94f8eba | 2015-10-14 08:52:45 -0700 | [diff] [blame] | 40 | const WriteCallback& callback) override; |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 41 | |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame] | 42 | void CancelPendingOperations() override; |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 43 | |
| 44 | static std::unique_ptr<weave::Stream> ConnectBlocking(const std::string& host, |
| 45 | uint16_t port); |
| 46 | |
Alex Vakulenko | 94f8eba | 2015-10-14 08:52:45 -0700 | [diff] [blame] | 47 | static void TlsConnect( |
| 48 | std::unique_ptr<weave::Stream> socket, |
| 49 | const std::string& host, |
| 50 | const weave::provider::Network::OpenSslSocketCallback& callback); |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 51 | |
| 52 | private: |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 53 | brillo::StreamPtr ptr_; |
Vitaly Buka | 493f604 | 2015-08-12 16:17:16 -0700 | [diff] [blame] | 54 | DISALLOW_COPY_AND_ASSIGN(SocketStream); |
| 55 | }; |
| 56 | |
| 57 | } // namespace buffet |
| 58 | |
| 59 | #endif // BUFFET_SOCKET_STREAM_H_ |