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 
20 #include "common/libs/fs/shared_fd.h"
21 
22 namespace cuttlefish {
23 namespace socket_proxy {
24 
25 class Client {
26  public:
27   virtual SharedFD Start() = 0;
28   virtual std::string Describe() const = 0;
29   virtual ~Client() = default;
30 };
31 
32 class 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_;
42   int last_failure_reason_ = 0;
43 };
44 
45 class 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_;
54   bool vhost_user_vsock_;
55   int last_failure_reason_ = 0;
56 };
57 
58 }
59 }