LLVM  14.0.0git
FDRawByteChannel.h
Go to the documentation of this file.
1 //===- FDRawByteChannel.h - File descriptor based byte-channel -*- 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 // File descriptor based RawByteChannel.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_FDRAWBYTECHANNEL_H
14 #define LLVM_EXECUTIONENGINE_ORC_SHARED_FDRAWBYTECHANNEL_H
15 
17 
18 #if !defined(_MSC_VER) && !defined(__MINGW32__)
19 #include <unistd.h>
20 #else
21 #include <io.h>
22 #endif
23 
24 namespace llvm {
25 namespace orc {
26 namespace shared {
27 
28 /// Serialization channel that reads from and writes from file descriptors.
29 class FDRawByteChannel final : public RawByteChannel {
30 public:
31  FDRawByteChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
32 
33  llvm::Error readBytes(char *Dst, unsigned Size) override {
34  assert(Dst && "Attempt to read into null.");
35  ssize_t Completed = 0;
36  while (Completed < static_cast<ssize_t>(Size)) {
37  ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
38  if (Read <= 0) {
39  auto ErrNo = errno;
40  if (ErrNo == EAGAIN || ErrNo == EINTR)
41  continue;
42  else
44  std::error_code(errno, std::generic_category()));
45  }
46  Completed += Read;
47  }
48  return llvm::Error::success();
49  }
50 
51  llvm::Error appendBytes(const char *Src, unsigned Size) override {
52  assert(Src && "Attempt to append from null.");
53  ssize_t Completed = 0;
54  while (Completed < static_cast<ssize_t>(Size)) {
55  ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
56  if (Written < 0) {
57  auto ErrNo = errno;
58  if (ErrNo == EAGAIN || ErrNo == EINTR)
59  continue;
60  else
62  std::error_code(errno, std::generic_category()));
63  }
64  Completed += Written;
65  }
66  return llvm::Error::success();
67  }
68 
69  llvm::Error send() override { return llvm::Error::success(); }
70 
71 private:
72  int InFD, OutFD;
73 };
74 
75 } // namespace shared
76 } // namespace orc
77 } // namespace llvm
78 
79 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_FDRAWBYTECHANNEL_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::orc::shared::FDRawByteChannel
Serialization channel that reads from and writes from file descriptors.
Definition: FDRawByteChannel.h:29
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::orc::shared::FDRawByteChannel::readBytes
llvm::Error readBytes(char *Dst, unsigned Size) override
Read Size bytes from the stream into *Dst.
Definition: FDRawByteChannel.h:33
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
Definition: DWP.cpp:535
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
llvm::orc::shared::FDRawByteChannel::FDRawByteChannel
FDRawByteChannel(int InFD, int OutFD)
Definition: FDRawByteChannel.h:31
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::shared::RawByteChannel
Interface for byte-streams to be used with ORC Serialization.
Definition: RawByteChannel.h:26
llvm::orc::shared::FDRawByteChannel::appendBytes
llvm::Error appendBytes(const char *Src, unsigned Size) override
Read size bytes from *Src and append them to the stream.
Definition: FDRawByteChannel.h:51
llvm::support::endian::read
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition: Endian.h:63
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
RawByteChannel.h
llvm::orc::shared::FDRawByteChannel::send
llvm::Error send() override
Flush the stream if possible.
Definition: FDRawByteChannel.h:69