-
Notifications
You must be signed in to change notification settings - Fork 607
[AOSP] add file descriptor support to file_data_loader #6611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,27 @@ namespace extension { | |
*/ | ||
class FileDataLoader final : public executorch::runtime::DataLoader { | ||
public: | ||
/** | ||
* Creates a new FileDataLoader that wraps the named file descriptor, and the | ||
* ownership of the file descriptor is passed. This helper is used when ET is | ||
* running in a process that does not have access to the filesystem, and the | ||
* caller is able to open the file and pass the file descriptor. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be mention that the fd ownership will be passed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
edit: read the destructor for FileDataLoader, makes sense now! |
||
* @param[in] file_descriptor_uri File descriptor with the prefix "fd:///", | ||
* followed by the file descriptor number. | ||
* @param[in] alignment Alignment in bytes of pointers returned by this | ||
* instance. Must be a power of two. | ||
* | ||
* @returns A new FileDataLoader on success. | ||
* @retval Error::InvalidArgument `alignment` is not a power of two. | ||
* @retval Error::AccessFailed `file_name` could not be opened, or its size | ||
* could not be found. | ||
* @retval Error::MemoryAllocationFailed Internal memory allocation failure. | ||
*/ | ||
static executorch::runtime::Result<FileDataLoader> fromFileDescriptorUri( | ||
const char* file_descriptor_uri, | ||
size_t alignment = alignof(std::max_align_t)); | ||
|
||
/** | ||
* Creates a new FileDataLoader that wraps the named file. | ||
* | ||
|
@@ -79,6 +100,11 @@ class FileDataLoader final : public executorch::runtime::DataLoader { | |
void* buffer) const override; | ||
|
||
private: | ||
static executorch::runtime::Result<FileDataLoader> fromFileDescriptor( | ||
const char* file_name, | ||
const int fd, | ||
size_t alignment = alignof(std::max_align_t)); | ||
|
||
FileDataLoader( | ||
int fd, | ||
size_t file_size, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's possible to factor the common code between here and
FileDataLoader::from
?