1 
2 // Copyright (C) 2021 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 #pragma once
16 #include <chrono>
17 #include <string>
18 
19 #include "net/async_data_channel.h"
20 
21 namespace android {
22 namespace net {
23 
24 using namespace std::chrono_literals;
25 
26 // An AsyncDataChannelConnector is capable of connecting to a remote server.
27 class AsyncDataChannelConnector {
28  public:
29   virtual ~AsyncDataChannelConnector() = default;
30 
31   // Blocks and waits until a connection to the remote server has been
32   // established, or a timeout has been reached. This function should
33   // not return nullptr, but a DataChannel in disconnected state in case of
34   // failure.
35   //
36   // In case of a disconnected DataChannel (socket->Connected() == false)
37   // the errno variable can be set with the encountered error.
38   virtual std::shared_ptr<AsyncDataChannel> ConnectToRemoteServer(
39       const std::string& server, int port,
40       std::chrono::milliseconds timeout = 5000ms) = 0;
41 };
42 }  // namespace net
43 }  // namespace android
44