1 //===-- ConnectionFileDescriptor.h ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ConnectionFileDescriptor_h_
11 #define liblldb_ConnectionFileDescriptor_h_
15 #include <sys/socket.h>
16 #include <sys/types.h>
17 #include <netinet/in.h>
23 // Other libraries and framework includes
25 #include "lldb/Core/Connection.h"
26 #include "lldb/Host/Mutex.h"
27 #include "lldb/Host/Predicate.h"
29 namespace lldb_private {
33 class ConnectionFileDescriptor :
38 ConnectionFileDescriptor ();
40 ConnectionFileDescriptor (int fd, bool owns_fd);
43 ~ConnectionFileDescriptor ();
48 virtual lldb::ConnectionStatus
49 Connect (const char *s, Error *error_ptr);
51 virtual lldb::ConnectionStatus
52 Disconnect (Error *error_ptr);
57 uint32_t timeout_usec,
58 lldb::ConnectionStatus &status,
62 Write (const void *src,
64 lldb::ConnectionStatus &status,
67 // If the read file descriptor is a socket, then return
68 // the port number that is being used by the socket.
72 // If the write file descriptor is a socket, then return
73 // the port number that is being used by the socket.
75 GetWritePort () const;
78 GetBoundPort (uint32_t timeout_sec);
84 eFDTypeFile, // Other FD requireing read/write
85 eFDTypeSocket, // Socket requiring send/recv
86 eFDTypeSocketUDP // Unconnected UDP socket requiring sendto/recvfrom
95 lldb::ConnectionStatus
96 BytesAvailable (uint32_t timeout_usec, Error *error_ptr);
98 lldb::ConnectionStatus
99 SocketListen (const char *host_and_port, Error *error_ptr);
101 lldb::ConnectionStatus
102 ConnectTCP (const char *host_and_port, Error *error_ptr);
104 lldb::ConnectionStatus
105 ConnectUDP (const char *args, Error *error_ptr);
107 lldb::ConnectionStatus
108 NamedSocketAccept (const char *socket_name, Error *error_ptr);
110 lldb::ConnectionStatus
111 NamedSocketConnect (const char *socket_name, Error *error_ptr);
113 lldb::ConnectionStatus
114 Close (int& fd, FDType type, Error *error);
118 FDType m_fd_send_type;
119 FDType m_fd_recv_type;
120 std::unique_ptr<SocketAddress> m_udp_send_sockaddr;
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.
125 Predicate<uint16_t> m_port_predicate; // Used when binding to port zero to wait for the thread that creates the socket, binds and listens to resolve the port number
126 bool m_should_close_fd; // True if this class should close the file descriptor when it goes away.
127 bool m_shutting_down; // This marks that we are shutting down so if we get woken up from BytesAvailable
128 // to disconnect, we won't try to read again.
131 GetSocketPort (int fd);
134 GetSocketOption(int fd, int level, int option_name, int &option_value);
137 SetSocketOption(int fd, int level, int option_name, int option_value);
140 SetSocketReceiveTimeout (uint32_t timeout_usec);
143 DISALLOW_COPY_AND_ASSIGN (ConnectionFileDescriptor);
146 } // namespace lldb_private
148 #endif // liblldb_ConnectionFileDescriptor_h_