1 //===-- IOObject.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_Host_Common_IOObject_h_ 11 #define liblldb_Host_Common_IOObject_h_ 12 13 #include <stdarg.h> 14 #include <stdio.h> 15 #include <sys/types.h> 16 17 #include "lldb/lldb-private.h" 18 19 namespace lldb_private { 20 21 class IOObject 22 { 23 public: 24 typedef enum 25 { 26 eFDTypeFile, // Other FD requiring read/write 27 eFDTypeSocket, // Socket requiring send/recv 28 } FDType; 29 30 // TODO: On Windows this should be a HANDLE, and wait should use 31 // WaitForMultipleObjects 32 typedef int WaitableHandle; 33 static const WaitableHandle kInvalidHandleValue; 34 IOObject(FDType type,bool should_close)35 IOObject(FDType type, bool should_close) 36 : m_fd_type(type) 37 , m_should_close_fd(should_close) 38 { 39 } ~IOObject()40 virtual ~IOObject() {} 41 42 virtual Error Read (void *buf, size_t &num_bytes) = 0; 43 virtual Error Write (const void *buf, size_t &num_bytes) = 0; 44 virtual bool IsValid() const = 0; 45 virtual Error Close() = 0; 46 GetFdType()47 FDType GetFdType() const { return m_fd_type; } 48 49 virtual WaitableHandle GetWaitableHandle() = 0; 50 51 protected: 52 FDType m_fd_type; 53 bool m_should_close_fd; // True if this class should close the file descriptor when it goes away. 54 55 private: 56 DISALLOW_COPY_AND_ASSIGN (IOObject); 57 }; 58 59 } 60 61 #endif 62