#pragma once #include #include "envoy/filesystem/filesystem.h" #include "common/common/assert.h" namespace Envoy { namespace Filesystem { class IoFileError : public Api::IoError { public: explicit IoFileError(int sys_errno) : errno_(sys_errno) {} ~IoFileError() override = default; Api::IoError::IoErrorCode getErrorCode() const override; std::string getErrorDetails() const override; private: const int errno_; }; using IoFileErrorPtr = std::unique_ptr; template Api::IoCallResult resultFailure(T result, int sys_errno) { return {result, IoFileErrorPtr(new IoFileError(sys_errno), [](Api::IoError* err) { ASSERT(err != nullptr); delete err; })}; } template Api::IoCallResult resultSuccess(T result) { return {result, IoFileErrorPtr(nullptr, [](Api::IoError*) { NOT_REACHED_GCOVR_EXCL_LINE; })}; } class FileSharedImpl : public File { public: FileSharedImpl(std::string path) : fd_(INVALID_HANDLE), path_(std::move(path)) {} ~FileSharedImpl() override = default; bool isOpen() const override; std::string path() const override; protected: filesystem_os_id_t fd_; const std::string path_; }; } // namespace Filesystem } // namespace Envoy