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_
14 #include <sys/socket.h>
15 #include <sys/types.h>
16 #include <netinet/in.h>
19 // Other libraries and framework includes
21 #include "lldb/Core/Connection.h"
22 #include "lldb/Host/Mutex.h"
23 #include "lldb/Host/Predicate.h"
24 #include "lldb/Host/SocketAddress.h"
26 namespace lldb_private {
28 class ConnectionFileDescriptor :
33 ConnectionFileDescriptor ();
35 ConnectionFileDescriptor (int fd, bool owns_fd);
38 ~ConnectionFileDescriptor ();
43 virtual lldb::ConnectionStatus
44 Connect (const char *s, Error *error_ptr);
46 virtual lldb::ConnectionStatus
47 Disconnect (Error *error_ptr);
52 uint32_t timeout_usec,
53 lldb::ConnectionStatus &status,
57 Write (const void *src,
59 lldb::ConnectionStatus &status,
62 // If the read file descriptor is a socket, then return
63 // the port number that is being used by the socket.
67 // If the write file descriptor is a socket, then return
68 // the port number that is being used by the socket.
70 GetWritePort () const;
80 lldb::ConnectionStatus
81 BytesAvailable (uint32_t timeout_usec, Error *error_ptr);
83 lldb::ConnectionStatus
84 SocketListen (uint16_t listen_port_num, Error *error_ptr);
86 lldb::ConnectionStatus
87 ConnectTCP (const char *host_and_port, Error *error_ptr);
89 lldb::ConnectionStatus
90 ConnectUDP (const char *args, Error *error_ptr);
92 lldb::ConnectionStatus
93 NamedSocketAccept (const char *socket_name, Error *error_ptr);
95 lldb::ConnectionStatus
96 NamedSocketConnect (const char *socket_name, Error *error_ptr);
98 lldb::ConnectionStatus
99 Close (int& fd, Error *error);
103 eFDTypeFile, // Other FD requireing read/write
104 eFDTypeSocket, // Socket requiring send/recv
105 eFDTypeSocketUDP // Unconnected UDP socket requiring sendto/recvfrom
110 FDType m_fd_send_type;
111 FDType m_fd_recv_type;
112 SocketAddress m_udp_send_sockaddr;
113 bool m_should_close_fd; // True if this class should close the file descriptor when it goes away.
114 uint32_t m_socket_timeout_usec;
115 int m_pipe_read; // A pipe that we select on the reading end of along with
116 int m_pipe_write; // m_fd_recv so we can force ourselves out of the select.
118 bool m_shutting_down; // This marks that we are shutting down so if we get woken up from BytesAvailable
119 // to disconnect, we won't try to read again.
122 GetSocketPort (int fd);
125 GetSocketOption(int fd, int level, int option_name, int &option_value);
128 SetSocketOption(int fd, int level, int option_name, int option_value);
131 SetSocketReceiveTimeout (uint32_t timeout_usec);
134 DISALLOW_COPY_AND_ASSIGN (ConnectionFileDescriptor);
137 } // namespace lldb_private
139 #endif // liblldb_ConnectionFileDescriptor_h_