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 #include <string> 17 #include <vector> 18 19 namespace lldb_private { 20 class TCPSocket : public Socket { 21 public: 22 explicit TCPSocket(bool should_close); 23 TCPSocket(NativeSocket socket, bool should_close); 24 ~TCPSocket() override; 25 26 // returns port number or 0 if error 27 uint16_t GetLocalPortNumber() const; 28 29 // returns ip address string or empty string if error 30 std::string GetLocalIPAddress() const; 31 32 // must be connected 33 // returns port number or 0 if error 34 uint16_t GetRemotePortNumber() const; 35 36 // must be connected 37 // returns ip address string or empty string if error 38 std::string GetRemoteIPAddress() const; 39 40 int SetOptionNoDelay(); 41 int SetOptionReuseAddress(); 42 43 Status Connect(llvm::StringRef name) override; 44 Status Listen(llvm::StringRef name, int backlog) override; 45 46 using Socket::Accept; 47 llvm::Expected<std::vector<MainLoopBase::ReadHandleUP>> 48 Accept(MainLoopBase &loop, 49 std::function<void(std::unique_ptr<Socket> socket)> sock_cb) override; 50 51 Status CreateSocket(int domain); 52 53 bool IsValid() const override; 54 55 std::string GetRemoteConnectionURI() const override; 56 57 std::vector<std::string> GetListeningConnectionURI() const override; 58 59 private: 60 TCPSocket(NativeSocket socket, const TCPSocket &listen_socket); 61 62 void CloseListenSockets(); 63 64 std::map<int, SocketAddress> m_listen_sockets; 65 }; 66 } 67 68 #endif // LLDB_HOST_COMMON_TCPSOCKET_H 69