Add Fd() method to file descriptor wrapper am: 32a1604c13
Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/2240835
Change-Id: I17afcecddd9c2208b85a43585d1ad72e0a5b88f2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/payload_consumer/file_descriptor.h b/payload_consumer/file_descriptor.h
index faebcc1..f672871 100644
--- a/payload_consumer/file_descriptor.h
+++ b/payload_consumer/file_descriptor.h
@@ -103,12 +103,19 @@
// Indicates whether the descriptor is currently open.
virtual bool IsOpen() = 0;
+ // Return the wrapped underlying file descriptor. Some classes might not
+ // support this.
+ // Using read/write syscall to read from the returned file descriptor should
+ // have same effect as calling Read()/Write() method of this FileDescriptor
+ // instance.
+ virtual int Fd() { return -1; }
+
private:
DISALLOW_COPY_AND_ASSIGN(FileDescriptor);
};
// A simple EINTR-immune wrapper implementation around standard system calls.
-class EintrSafeFileDescriptor : public FileDescriptor {
+class EintrSafeFileDescriptor final : public FileDescriptor {
public:
EintrSafeFileDescriptor() : fd_(-1) {}
~EintrSafeFileDescriptor();
@@ -128,6 +135,7 @@
bool Close() override;
bool IsSettingErrno() override { return true; }
bool IsOpen() override { return (fd_ >= 0); }
+ int Fd() override { return fd_; }
protected:
int fd_;