1 //===-- IOObject.h ----------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_UTILITY_IOOBJECT_H 10 #define LLDB_UTILITY_IOOBJECT_H 11 12 #include <cstdarg> 13 #include <cstdio> 14 #include <sys/types.h> 15 16 #include "lldb/lldb-private.h" 17 #include "lldb/lldb-types.h" 18 19 namespace lldb_private { 20 21 class IOObject { 22 public: 23 enum FDType { 24 eFDTypeFile, // Other FD requiring read/write 25 eFDTypeSocket, // Socket requiring send/recv 26 }; 27 28 // A handle for integrating with the host event loop model. 29 using WaitableHandle = lldb::file_t; 30 31 static const WaitableHandle kInvalidHandleValue; 32 IOObject(FDType type)33 IOObject(FDType type) : m_fd_type(type) {} 34 virtual ~IOObject(); 35 36 virtual Status Read(void *buf, size_t &num_bytes) = 0; 37 virtual Status Write(const void *buf, size_t &num_bytes) = 0; 38 virtual bool IsValid() const = 0; 39 virtual Status Close() = 0; 40 GetFdType()41 FDType GetFdType() const { return m_fd_type; } 42 43 virtual WaitableHandle GetWaitableHandle() = 0; 44 45 protected: 46 FDType m_fd_type; 47 48 private: 49 IOObject(const IOObject &) = delete; 50 const IOObject &operator=(const IOObject &) = delete; 51 }; 52 } // namespace lldb_private 53 54 #endif 55