|
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 |
| 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/MainLoopBase.h" |
| 13 | +#include "lldb/Host/Socket.h" |
| 14 | +#include "lldb/Host/SocketAddress.h" |
| 15 | +#include <map> |
| 16 | + |
| 17 | +namespace lldb_private { |
| 18 | +class TCPSocket : public Socket { |
| 19 | +public: |
| 20 | + TCPSocket(bool should_close, bool child_processes_inherit); |
| 21 | + TCPSocket(NativeSocket socket, bool should_close, |
| 22 | + bool child_processes_inherit); |
| 23 | + ~TCPSocket() override; |
| 24 | + |
| 25 | + // returns port number or 0 if error |
| 26 | + uint16_t GetLocalPortNumber() const; |
| 27 | + |
| 28 | + // returns ip address string or empty string if error |
| 29 | + std::string GetLocalIPAddress() const; |
| 30 | + |
| 31 | + // must be connected |
| 32 | + // returns port number or 0 if error |
| 33 | + uint16_t GetRemotePortNumber() const; |
| 34 | + |
| 35 | + // must be connected |
| 36 | + // returns ip address string or empty string if error |
| 37 | + std::string GetRemoteIPAddress() const; |
| 38 | + |
| 39 | + int SetOptionNoDelay(); |
| 40 | + int SetOptionReuseAddress(); |
| 41 | + |
| 42 | + Status Connect(llvm::StringRef name) override; |
| 43 | + Status Listen(llvm::StringRef name, int backlog) override; |
| 44 | + |
| 45 | + // Use the provided main loop instance to accept new connections. The callback |
| 46 | + // will be called (from MainLoop::Run) for each new connection. This function |
| 47 | + // does not block. |
| 48 | + llvm::Expected<std::vector<MainLoopBase::ReadHandleUP>> |
| 49 | + Accept(MainLoopBase &loop, |
| 50 | + std::function<void(std::unique_ptr<TCPSocket> socket)> sock_cb); |
| 51 | + |
| 52 | + // Accept a single connection and "return" it in the pointer argument. This |
| 53 | + // function blocks until the connection arrives. |
| 54 | + Status Accept(Socket *&conn_socket) override; |
| 55 | + |
| 56 | + Status CreateSocket(int domain); |
| 57 | + |
| 58 | + bool IsValid() const override; |
| 59 | + |
| 60 | + std::string GetRemoteConnectionURI() const override; |
| 61 | + |
| 62 | +private: |
| 63 | + TCPSocket(NativeSocket socket, const TCPSocket &listen_socket); |
| 64 | + |
| 65 | + void CloseListenSockets(); |
| 66 | + |
| 67 | + std::map<int, SocketAddress> m_listen_sockets; |
| 68 | +}; |
| 69 | +} // namespace lldb_private |
| 70 | + |
| 71 | +#endif // LLDB_HOST_COMMON_TCPSOCKET_H |
0 commit comments