]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/ConnectionFileDescriptor.h
MFC r258054: Update LLDB to upstream r194122 snapshot
[FreeBSD/stable/10.git] / contrib / llvm / tools / lldb / include / lldb / Core / ConnectionFileDescriptor.h
1 //===-- ConnectionFileDescriptor.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_ConnectionFileDescriptor_h_
11 #define liblldb_ConnectionFileDescriptor_h_
12
13 // C Includes
14 #ifdef _WIN32
15 typedef unsigned short in_port_t;
16 #else
17 #include <sys/socket.h>
18 #include <sys/types.h>
19 #include <netinet/in.h>
20 #endif
21
22 // C++ Includes
23 #include <memory>
24
25 // Other libraries and framework includes
26 // Project includes
27 #include "lldb/Core/Connection.h"
28 #include "lldb/Host/Mutex.h"
29 #include "lldb/Host/Predicate.h"
30
31 namespace lldb_private {
32
33 class SocketAddress;
34
35 class ConnectionFileDescriptor :
36     public Connection
37 {
38 public:
39
40     ConnectionFileDescriptor ();
41
42     ConnectionFileDescriptor (int fd, bool owns_fd);
43
44     virtual
45     ~ConnectionFileDescriptor ();
46
47     virtual bool
48     IsConnected () const;
49
50     virtual lldb::ConnectionStatus
51     Connect (const char *s, Error *error_ptr);
52
53     virtual lldb::ConnectionStatus
54     Disconnect (Error *error_ptr);
55
56     virtual size_t
57     Read (void *dst, 
58           size_t dst_len, 
59           uint32_t timeout_usec,
60           lldb::ConnectionStatus &status, 
61           Error *error_ptr);
62
63     virtual size_t
64     Write (const void *src, 
65            size_t src_len, 
66            lldb::ConnectionStatus &status, 
67            Error *error_ptr);
68
69     // If the read file descriptor is a socket, then return
70     // the port number that is being used by the socket.
71     in_port_t
72     GetReadPort () const;
73     
74     // If the write file descriptor is a socket, then return
75     // the port number that is being used by the socket.
76     in_port_t
77     GetWritePort () const;
78
79 protected:
80
81     typedef enum
82     {
83         eFDTypeFile,        // Other FD requireing read/write
84         eFDTypeSocket,      // Socket requiring send/recv
85         eFDTypeSocketUDP    // Unconnected UDP socket requiring sendto/recvfrom
86     } FDType;
87     
88     void
89     OpenCommandPipe ();
90     
91     void
92     CloseCommandPipe ();
93
94     lldb::ConnectionStatus
95     BytesAvailable (uint32_t timeout_usec, Error *error_ptr);
96     
97     lldb::ConnectionStatus
98     SocketListen (uint16_t listen_port_num, Error *error_ptr);
99
100     lldb::ConnectionStatus
101     ConnectTCP (const char *host_and_port, Error *error_ptr);
102     
103     lldb::ConnectionStatus
104     ConnectUDP (const char *args, Error *error_ptr);
105     
106     lldb::ConnectionStatus
107     NamedSocketAccept (const char *socket_name, Error *error_ptr);
108
109     lldb::ConnectionStatus
110     NamedSocketConnect (const char *socket_name, Error *error_ptr);
111     
112     lldb::ConnectionStatus
113     Close (int& fd, FDType type, Error *error);
114     
115     int m_fd_send;
116     int m_fd_recv;
117     FDType m_fd_send_type;
118     FDType m_fd_recv_type;
119     std::unique_ptr<SocketAddress> m_udp_send_sockaddr;
120     bool m_should_close_fd;     // True if this class should close the file descriptor when it goes away.
121     uint32_t m_socket_timeout_usec;
122     int m_pipe_read;            // A pipe that we select on the reading end of along with
123     int m_pipe_write;           // m_fd_recv so we can force ourselves out of the select.
124     Mutex m_mutex;          
125     bool m_shutting_down;       // This marks that we are shutting down so if we get woken up from BytesAvailable
126                                 // to disconnect, we won't try to read again.
127     
128     static in_port_t
129     GetSocketPort (int fd);
130
131     static int
132     GetSocketOption(int fd, int level, int option_name, int &option_value);
133
134     static int
135     SetSocketOption(int fd, int level, int option_name, int option_value);
136
137     bool
138     SetSocketReceiveTimeout (uint32_t timeout_usec);
139
140 private:
141     DISALLOW_COPY_AND_ASSIGN (ConnectionFileDescriptor);
142 };
143
144 } // namespace lldb_private
145
146 #endif  // liblldb_ConnectionFileDescriptor_h_