Android-cuttlefish cvd tool
client.h
Go to the documentation of this file.
1//
2// Copyright (C) 2022 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <chrono>
19
21
22namespace cuttlefish {
23namespace socket_proxy {
24
25class Client {
26 public:
27 virtual SharedFD Start() = 0;
28 virtual std::string Describe() const = 0;
29 virtual ~Client() = default;
30};
31
32class TcpClient : public Client {
33 public:
34 TcpClient(std::string host, int port, std::chrono::seconds timeout = std::chrono::seconds(0));
35 SharedFD Start() override;
36 std::string Describe() const override;
37
38 private:
39 std::string host_;
40 int port_;
41 std::chrono::seconds timeout_;
43};
44
45class VsockClient : public Client {
46 public:
47 VsockClient(int id, int port, bool vhost_user_vsock);
48 SharedFD Start() override;
49 std::string Describe() const override;
50
51 private:
52 int id_;
53 int port_;
56};
57
58}
59}
Definition: shared_fd.h:129
Definition: client.h:25
virtual SharedFD Start()=0
virtual std::string Describe() const =0
SharedFD Start() override
Definition: client.cpp:63
int port_
Definition: client.h:40
std::chrono::seconds timeout_
Definition: client.h:41
TcpClient(std::string host, int port, std::chrono::seconds timeout=std::chrono::seconds(0))
Definition: client.cpp:58
std::string host_
Definition: client.h:39
std::string Describe() const override
Definition: client.cpp:87
int last_failure_reason_
Definition: client.h:42
SharedFD Start() override
Definition: client.cpp:94
bool vhost_user_vsock_
Definition: client.h:54
int port_
Definition: client.h:53
int id_
Definition: client.h:52
std::string Describe() const override
Definition: client.cpp:112
int last_failure_reason_
Definition: client.h:55
VsockClient(int id, int port, bool vhost_user_vsock)
Definition: client.cpp:91
Definition: alloc_utils.cpp:23