LLDB mainline
TCPSocket.h
Go to the documentation of this file.
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
13#include "lldb/Host/Socket.h"
15#include <map>
16#include <string>
17#include <vector>
18
19namespace lldb_private {
20class TCPSocket : public Socket {
21public:
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();
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
59private:
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
virtual llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > Accept(MainLoopBase &loop, std::function< void(std::unique_ptr< Socket > socket)> sock_cb)=0
An error handling class.
Definition: Status.h:118
std::vector< std::string > GetListeningConnectionURI() const override
Definition: TCPSocket.cpp:118
Status Listen(llvm::StringRef name, int backlog) override
Definition: TCPSocket.cpp:176
bool IsValid() const override
Definition: TCPSocket.cpp:55
uint16_t GetRemotePortNumber() const
Definition: TCPSocket.cpp:88
Status CreateSocket(int domain)
Definition: TCPSocket.cpp:126
std::string GetRemoteConnectionURI() const override
Definition: TCPSocket.cpp:110
llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > Accept(MainLoopBase &loop, std::function< void(std::unique_ptr< Socket > socket)> sock_cb) override
Definition: TCPSocket.cpp:240
std::string GetLocalIPAddress() const
Definition: TCPSocket.cpp:76
std::string GetRemoteIPAddress() const
Definition: TCPSocket.cpp:98
uint16_t GetLocalPortNumber() const
Definition: TCPSocket.cpp:60
std::map< int, SocketAddress > m_listen_sockets
Definition: TCPSocket.h:64
Status Connect(llvm::StringRef name) override
Definition: TCPSocket.cpp:136
A class that represents a running process on the host machine.
int NativeSocket
Definition: Socket.h:41