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 typedef unsigned short in_port_t;
17 #include <sys/socket.h>
18 #include <sys/types.h>
19 #include <netinet/in.h>
25 // Other libraries and framework includes
27 #include "lldb/Core/Connection.h"
28 #include "lldb/Host/Mutex.h"
29 #include "lldb/Host/Predicate.h"
31 namespace lldb_private {
35 class ConnectionFileDescriptor :
40 ConnectionFileDescriptor ();
42 ConnectionFileDescriptor (int fd, bool owns_fd);
45 ~ConnectionFileDescriptor ();
50 virtual lldb::ConnectionStatus
51 Connect (const char *s, Error *error_ptr);
53 virtual lldb::ConnectionStatus
54 Disconnect (Error *error_ptr);
59 uint32_t timeout_usec,
60 lldb::ConnectionStatus &status,
64 Write (const void *src,
66 lldb::ConnectionStatus &status,
69 // If the read file descriptor is a socket, then return
70 // the port number that is being used by the socket.
74 // If the write file descriptor is a socket, then return
75 // the port number that is being used by the socket.
77 GetWritePort () const;
83 eFDTypeFile, // Other FD requireing read/write
84 eFDTypeSocket, // Socket requiring send/recv
85 eFDTypeSocketUDP // Unconnected UDP socket requiring sendto/recvfrom
94 lldb::ConnectionStatus
95 BytesAvailable (uint32_t timeout_usec, Error *error_ptr);
97 lldb::ConnectionStatus
98 SocketListen (uint16_t listen_port_num, Error *error_ptr);
100 lldb::ConnectionStatus
101 ConnectTCP (const char *host_and_port, Error *error_ptr);
103 lldb::ConnectionStatus
104 ConnectUDP (const char *args, Error *error_ptr);
106 lldb::ConnectionStatus
107 NamedSocketAccept (const char *socket_name, Error *error_ptr);
109 lldb::ConnectionStatus
110 NamedSocketConnect (const char *socket_name, Error *error_ptr);
112 lldb::ConnectionStatus
113 Close (int& fd, FDType type, Error *error);
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.
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.
129 GetSocketPort (int fd);
132 GetSocketOption(int fd, int level, int option_name, int &option_value);
135 SetSocketOption(int fd, int level, int option_name, int option_value);
138 SetSocketReceiveTimeout (uint32_t timeout_usec);
141 DISALLOW_COPY_AND_ASSIGN (ConnectionFileDescriptor);
144 } // namespace lldb_private
146 #endif // liblldb_ConnectionFileDescriptor_h_