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,
35 std::chrono::seconds timeout = std::chrono::seconds(0));
36 SharedFD Start() override;
37 std::string Describe() const override;
38
39 private:
40 std::string host_;
41 int port_;
42 std::chrono::seconds timeout_;
44};
45
46class VsockClient : public Client {
47 public:
48 VsockClient(int id, int port, bool vhost_user_vsock);
49 SharedFD Start() override;
50 std::string Describe() const override;
51
52 private:
53 int id_;
54 int port_;
57};
58
59} // namespace socket_proxy
60} // namespace cuttlefish
Definition: shared_fd.h:124
Definition: client.h:25
virtual SharedFD Start()=0
virtual std::string Describe() const =0
SharedFD Start() override
Definition: client.cpp:73
int port_
Definition: client.h:41
std::chrono::seconds timeout_
Definition: client.h:42
TcpClient(std::string host, int port, std::chrono::seconds timeout=std::chrono::seconds(0))
Definition: client.cpp:70
std::string host_
Definition: client.h:40
std::string Describe() const override
Definition: client.cpp:97
int last_failure_reason_
Definition: client.h:43
SharedFD Start() override
Definition: client.cpp:104
bool vhost_user_vsock_
Definition: client.h:55
int port_
Definition: client.h:54
int id_
Definition: client.h:53
std::string Describe() const override
Definition: client.cpp:122
int last_failure_reason_
Definition: client.h:56
VsockClient(int id, int port, bool vhost_user_vsock)
Definition: client.cpp:101
Definition: alloc_driver.h:20