TCPSocket.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef LLDB_HOST_COMMON_TCPSOCKET_H
  9. #define LLDB_HOST_COMMON_TCPSOCKET_H
  10. #include "lldb/Host/Socket.h"
  11. #include "lldb/Host/SocketAddress.h"
  12. #include <map>
  13. namespace lldb_private {
  14. class TCPSocket : public Socket {
  15. public:
  16. TCPSocket(bool should_close, bool child_processes_inherit);
  17. TCPSocket(NativeSocket socket, bool should_close,
  18. bool child_processes_inherit);
  19. ~TCPSocket() override;
  20. // returns port number or 0 if error
  21. uint16_t GetLocalPortNumber() const;
  22. // returns ip address string or empty string if error
  23. std::string GetLocalIPAddress() const;
  24. // must be connected
  25. // returns port number or 0 if error
  26. uint16_t GetRemotePortNumber() const;
  27. // must be connected
  28. // returns ip address string or empty string if error
  29. std::string GetRemoteIPAddress() const;
  30. int SetOptionNoDelay();
  31. int SetOptionReuseAddress();
  32. Status Connect(llvm::StringRef name) override;
  33. Status Listen(llvm::StringRef name, int backlog) override;
  34. Status Accept(Socket *&conn_socket) override;
  35. Status CreateSocket(int domain);
  36. bool IsValid() const override;
  37. std::string GetRemoteConnectionURI() const override;
  38. private:
  39. TCPSocket(NativeSocket socket, const TCPSocket &listen_socket);
  40. void CloseListenSockets();
  41. std::map<int, SocketAddress> m_listen_sockets;
  42. };
  43. }
  44. #endif // LLDB_HOST_COMMON_TCPSOCKET_H