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. 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> 22#include <brillo/streams/stream.h> 23#include <weave/provider/network.h> 24#include <weave/stream.h> 25 26namespace buffet { 27 28class SocketStream : public weave::Stream { 29 public: 30 explicit SocketStream(brillo::StreamPtr ptr) : ptr_{std::move(ptr)} {} 31 32 ~SocketStream() override = default; 33 34 void Read(void* buffer, 35 size_t size_to_read, 36 const ReadCallback& callback) override; 37 38 void Write(const void* buffer, 39 size_t size_to_write, 40 const WriteCallback& callback) override; 41 42 void CancelPendingOperations() override; 43 44 static std::unique_ptr<weave::Stream> ConnectBlocking(const std::string& host, 45 uint16_t port); 46 47 static void TlsConnect( 48 std::unique_ptr<weave::Stream> socket, 49 const std::string& host, 50 const weave::provider::Network::OpenSslSocketCallback& callback); 51 52 private: 53 brillo::StreamPtr ptr_; 54 DISALLOW_COPY_AND_ASSIGN(SocketStream); 55}; 56 57} // namespace buffet 58 59#endif // BUFFET_SOCKET_STREAM_H_ 60