ConnectionFileDescriptor.h revision 8d2ea2888a4acb7f140f9af64ddd2b16b2dee870
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#include <sys/socket.h> 15#include <sys/types.h> 16#include <netinet/in.h> 17 18// C++ Includes 19// Other libraries and framework includes 20// Project includes 21#include "lldb/Core/Connection.h" 22 23namespace lldb_private { 24 25class ConnectionFileDescriptor : 26 public Connection 27{ 28public: 29 30 ConnectionFileDescriptor (); 31 32 ConnectionFileDescriptor (int fd, bool owns_fd); 33 34 virtual 35 ~ConnectionFileDescriptor (); 36 37 virtual bool 38 IsConnected () const; 39 40 virtual lldb::ConnectionStatus 41 Connect (const char *s, Error *error_ptr); 42 43 virtual lldb::ConnectionStatus 44 Disconnect (Error *error_ptr); 45 46 virtual size_t 47 Read (void *dst, 48 size_t dst_len, 49 uint32_t timeout_usec, 50 lldb::ConnectionStatus &status, 51 Error *error_ptr); 52 53 virtual size_t 54 Write (const void *src, 55 size_t src_len, 56 lldb::ConnectionStatus &status, 57 Error *error_ptr); 58 59 // If the read file descriptor is a socket, then return 60 // the port number that is being used by the socket. 61 in_port_t 62 GetReadPort () const; 63 64 // If the write file descriptor is a socket, then return 65 // the port number that is being used by the socket. 66 in_port_t 67 GetWritePort () const; 68 69protected: 70 71 lldb::ConnectionStatus 72 BytesAvailable (uint32_t timeout_usec, Error *error_ptr); 73 74 lldb::ConnectionStatus 75 SocketListen (uint16_t listen_port_num, Error *error_ptr); 76 77 lldb::ConnectionStatus 78 ConnectTCP (const char *host_and_port, Error *error_ptr); 79 80 lldb::ConnectionStatus 81 ConnectUDP (const char *args, Error *error_ptr); 82 83 lldb::ConnectionStatus 84 NamedSocketAccept (const char *socket_name, Error *error_ptr); 85 86 lldb::ConnectionStatus 87 NamedSocketConnect (const char *socket_name, Error *error_ptr); 88 89 lldb::ConnectionStatus 90 Close (int& fd, Error *error); 91 92 typedef enum 93 { 94 eFDTypeFile, // Other FD requireing read/write 95 eFDTypeSocket, // Socket requiring send/recv 96 eFDTypeSocketUDP // Unconnected UDP socket requiring sendto/recvfrom 97 } FDType; 98 99 typedef union sockaddr_tag 100 { 101 struct sockaddr sa; 102 struct sockaddr_in sa_ipv4; 103 struct sockaddr_in6 sa_ipv6; 104 struct sockaddr_storage sa_storage; 105 } sockaddr_t; 106 107 108 int m_fd_send; 109 int m_fd_recv; 110 FDType m_fd_send_type; 111 FDType m_fd_recv_type; 112 sockaddr_t 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 116 static in_port_t 117 GetSocketPort (int fd); 118 119 static int 120 GetSocketOption(int fd, int level, int option_name, int &option_value); 121 122 static int 123 SetSocketOption(int fd, int level, int option_name, int option_value); 124 125 bool 126 SetSocketReceiveTimeout (uint32_t timeout_usec); 127 128private: 129 DISALLOW_COPY_AND_ASSIGN (ConnectionFileDescriptor); 130}; 131 132} // namespace lldb_private 133 134#endif // liblldb_ConnectionFileDescriptor_h_ 135