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 #include "common/libs/utils/result.h"
22 
23 namespace cuttlefish {
24 namespace socket_proxy {
25 
26 class Server {
27  public:
28   virtual Result<SharedFD> Start() = 0;
29   virtual std::string Describe() const = 0;
30   virtual ~Server() = default;
31 };
32 
33 class TcpServer : public Server {
34  public:
35   TcpServer(int port, int retries_count = 1,
36             std::chrono::milliseconds retries_delay = std::chrono::milliseconds(0));
37   Result<SharedFD> Start() override;
38   std::string Describe() const override;
39 
40  private:
41   int port_;
42   int retries_count_;
43   std::chrono::milliseconds retries_delay_;
44 };
45 
46 class VsockServer : public Server {
47  public:
48   VsockServer(int port, std::optional<int> vhost_user_vsock_cid);
49   Result<SharedFD> Start() override;
50   std::string Describe() const override;
51 
52  private:
53   int port_;
54   std::optional<int> vhost_user_vsock_cid_;
55 };
56 
57 class DupServer : public Server {
58  public:
59   DupServer(int fd);
60   Result<SharedFD> Start() override;
61   std::string Describe() const override;
62 
63  private:
64   int fd_;
65   SharedFD sfd_;
66 };
67 
68 }
69 }