blob: 9b2b9cfcfec0ff1252873f05865cee94a7710ef1 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===-- 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
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02009#ifndef LLDB_UTILITY_IOOBJECT_H
10#define LLDB_UTILITY_IOOBJECT_H
Andrew Walbran3d2c1972020-04-07 12:24:26 +010011
12#include <stdarg.h>
13#include <stdio.h>
14#include <sys/types.h>
15
16#include "lldb/lldb-private.h"
17
18namespace lldb_private {
19
20class IOObject {
21public:
22 enum FDType {
23 eFDTypeFile, // Other FD requiring read/write
24 eFDTypeSocket, // Socket requiring send/recv
25 };
26
27 // TODO: On Windows this should be a HANDLE, and wait should use
28 // WaitForMultipleObjects
29 typedef int WaitableHandle;
30 static const WaitableHandle kInvalidHandleValue;
31
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020032 IOObject(FDType type) : m_fd_type(type) {}
Andrew Walbran3d2c1972020-04-07 12:24:26 +010033 virtual ~IOObject();
34
35 virtual Status Read(void *buf, size_t &num_bytes) = 0;
36 virtual Status Write(const void *buf, size_t &num_bytes) = 0;
37 virtual bool IsValid() const = 0;
38 virtual Status Close() = 0;
39
40 FDType GetFdType() const { return m_fd_type; }
41
42 virtual WaitableHandle GetWaitableHandle() = 0;
43
44protected:
45 FDType m_fd_type;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010046
47private:
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020048 IOObject(const IOObject &) = delete;
49 const IOObject &operator=(const IOObject &) = delete;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010050};
51} // namespace lldb_private
52
53#endif