1 //===-- TCPSocket.h ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_TCPSocket_h_ 11 #define liblldb_TCPSocket_h_ 12 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 Status Accept(Socket *&conn_socket) override; 45 46 Status CreateSocket(int domain); 47 48 bool IsValid() const override; 49 50 private: 51 TCPSocket(NativeSocket socket, const TCPSocket &listen_socket); 52 53 void CloseListenSockets(); 54 55 std::map<int, SocketAddress> m_listen_sockets; 56 }; 57 } 58 59 #endif // ifndef liblldb_TCPSocket_h_ 60