1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef dap_socket_h
16#define dap_socket_h
17
18#include "dap/io.h"
19
20#include <atomic>
21#include <memory>
22
23namespace dap {
24
25class Socket {
26 public:
27 class Shared;
28
29 // connect() connects to the given TCP address and port.
30 // If timeoutMillis is non-zero and no connection was made before
31 // timeoutMillis milliseconds, then nullptr is returned.
32 static std::shared_ptr<ReaderWriter> connect(const char* address,
33 const char* port,
34 uint32_t timeoutMillis);
35
36 Socket(const char* address, const char* port);
37 bool isOpen() const;
38 std::shared_ptr<ReaderWriter> accept() const;
39 void close() const;
40
41 private:
42 std::shared_ptr<Shared> shared;
43};
44
45} // namespace dap
46
47#endif // dap_socket_h
48