1 //===-- RemoteJITUtils.h - Utilities for remote-JITing with LLI -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Utilities for remote-JITing with LLI.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
14 #define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
16 #include "llvm/ExecutionEngine/Orc/RawByteChannel.h"
17 #include "llvm/Support/Error.h"
20 #include <system_error>
22 #if !defined(_MSC_VER) && !defined(__MINGW32__)
28 /// RPC channel that reads from and writes from file descriptors.
29 class FDRPCChannel final
: public llvm::orc::rpc::RawByteChannel
{
31 FDRPCChannel(int InFD
, int OutFD
) : InFD(InFD
), OutFD(OutFD
) {}
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
);
40 if (ErrNo
== EAGAIN
|| ErrNo
== EINTR
)
43 return llvm::errorCodeToError(
44 std::error_code(errno
, std::generic_category()));
48 return llvm::Error::success();
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
);
58 if (ErrNo
== EAGAIN
|| ErrNo
== EINTR
)
61 return llvm::errorCodeToError(
62 std::error_code(errno
, std::generic_category()));
66 return llvm::Error::success();
69 llvm::Error
send() override
{ return llvm::Error::success(); }
75 #endif // LLVM_TOOLS_LLI_REMOTEJITUTILS_H