blob: c0be7c724c6e5b59a1a12af3d54f626db9c0fb38 [file] [log] [blame]
Vitaly Bukacad20f02015-10-16 17:27:15 -07001// 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 Buka493f6042015-08-12 16:17:16 -070014
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 Vakulenko41705852015-10-13 10:12:06 -070022#include <brillo/streams/stream.h>
Alex Vakulenko94f8eba2015-10-14 08:52:45 -070023#include <weave/provider/network.h>
Vitaly Buka493f6042015-08-12 16:17:16 -070024#include <weave/stream.h>
25
26namespace buffet {
27
28class SocketStream : public weave::Stream {
29 public:
Alex Vakulenko41705852015-10-13 10:12:06 -070030 explicit SocketStream(brillo::StreamPtr ptr) : ptr_{std::move(ptr)} {}
Vitaly Buka493f6042015-08-12 16:17:16 -070031
32 ~SocketStream() override = default;
33
Alex Vakulenko0fef8152015-09-25 08:45:22 -070034 void Read(void* buffer,
35 size_t size_to_read,
Alex Vakulenko94f8eba2015-10-14 08:52:45 -070036 const ReadCallback& callback) override;
Vitaly Buka493f6042015-08-12 16:17:16 -070037
Alex Vakulenko0fef8152015-09-25 08:45:22 -070038 void Write(const void* buffer,
39 size_t size_to_write,
Alex Vakulenko94f8eba2015-10-14 08:52:45 -070040 const WriteCallback& callback) override;
Vitaly Buka493f6042015-08-12 16:17:16 -070041
Alex Vakulenko0fef8152015-09-25 08:45:22 -070042 void CancelPendingOperations() override;
Vitaly Buka493f6042015-08-12 16:17:16 -070043
44 static std::unique_ptr<weave::Stream> ConnectBlocking(const std::string& host,
45 uint16_t port);
46
Alex Vakulenko94f8eba2015-10-14 08:52:45 -070047 static void TlsConnect(
48 std::unique_ptr<weave::Stream> socket,
49 const std::string& host,
50 const weave::provider::Network::OpenSslSocketCallback& callback);
Vitaly Buka493f6042015-08-12 16:17:16 -070051
52 private:
Alex Vakulenko41705852015-10-13 10:12:06 -070053 brillo::StreamPtr ptr_;
Vitaly Buka493f6042015-08-12 16:17:16 -070054 DISALLOW_COPY_AND_ASSIGN(SocketStream);
55};
56
57} // namespace buffet
58
59#endif // BUFFET_SOCKET_STREAM_H_