1 | //===-- TCPSocket.h ---------------------------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLDB_HOST_COMMON_TCPSOCKET_H |
10 | #define LLDB_HOST_COMMON_TCPSOCKET_H |
11 | |
12 | #include "lldb/Host/Socket.h" |
13 | #include "lldb/Host/SocketAddress.h" |
14 | #include <map> |
15 | |
16 | namespace lldb_private { |
17 | class TCPSocket : public Socket { |
18 | public: |
19 | TCPSocket(bool should_close, bool child_processes_inherit); |
20 | TCPSocket(NativeSocket socket, bool should_close, |
21 | bool child_processes_inherit); |
22 | ~TCPSocket() override; |
23 | |
24 | // returns port number or 0 if error |
25 | uint16_t GetLocalPortNumber() const; |
26 | |
27 | // returns ip address string or empty string if error |
28 | std::string GetLocalIPAddress() const; |
29 | |
30 | // must be connected |
31 | // returns port number or 0 if error |
32 | uint16_t GetRemotePortNumber() const; |
33 | |
34 | // must be connected |
35 | // returns ip address string or empty string if error |
36 | std::string GetRemoteIPAddress() const; |
37 | |
38 | int SetOptionNoDelay(); |
39 | int SetOptionReuseAddress(); |
40 | |
41 | Status Connect(llvm::StringRef name) override; |
42 | Status Listen(llvm::StringRef name, int backlog) override; |
43 | Status Accept(Socket *&conn_socket) override; |
44 | |
45 | Status CreateSocket(int domain); |
46 | |
47 | bool IsValid() const override; |
48 | |
49 | std::string GetRemoteConnectionURI() const override; |
50 | |
51 | private: |
52 | TCPSocket(NativeSocket socket, const TCPSocket &listen_socket); |
53 | |
54 | void CloseListenSockets(); |
55 | |
56 | std::map<int, SocketAddress> m_listen_sockets; |
57 | }; |
58 | } |
59 | |
60 | #endif // LLDB_HOST_COMMON_TCPSOCKET_H |
61 | |