Struct glommio::io::BufferedFile [−][src]
pub struct BufferedFile { /* fields omitted */ }
Expand description
An asynchronously accessed file backed by the OS page cache.
All access uses buffered I/O, and all operations including open and close are asynchronous (with some exceptions noted).
See the module-level documentation for more details and examples.
Implementations
Returns true if the BufferedFile represent the same file on the underlying device.
Files are considered to be the same if they live in the same file system and have the same Linux inode. Note that based on this rule a symlink is not considered to be the same file.
Files will be considered to be the same if:
- A file is opened multiple times (different file descriptors, but same file!)
- they are hard links.
Examples
use glommio::{io::BufferedFile, LocalExecutor};
use std::os::unix::io::AsRawFd;
let ex = LocalExecutor::default();
ex.run(async {
let mut wfile = BufferedFile::create("myfile.txt").await.unwrap();
let mut rfile = BufferedFile::open("myfile.txt").await.unwrap();
// Different objects (OS file descriptors), so they will be different...
assert_ne!(wfile.as_raw_fd(), rfile.as_raw_fd());
// However they represent the same object.
assert!(wfile.is_same(&rfile));
wfile.close().await;
rfile.close().await;
});
Similar to create
in the standard library, but returns a
BufferedFile
Similar to open
in the standard library, but returns a
BufferedFile
Write the data in the buffer buf
to this BufferedFile
at the
specified position
This method acquires ownership of the buffer so the buffer can be kept alive while the kernel has it.
Note that it is legal to return fewer bytes than the buffer size. That
is the situation, for example, when the device runs out of space
(See the man page for write(2)
for details)
Examples
use glommio::{io::BufferedFile, LocalExecutor};
let ex = LocalExecutor::default();
ex.run(async {
let file = BufferedFile::create("test.txt").await.unwrap();
let mut buf = vec![0, 1, 2, 3];
file.write_at(buf, 0).await.unwrap();
file.close().await.unwrap();
});
Reads data at the specified position into a buffer allocated by this library.
Note that this differs from DmaFile
’s read APIs: that reflects the
fact that buffered reads need no specific alignment and io_uring will
not be able to use its own pre-allocated buffers for it anyway.
Reads from a specific position in the file and returns the buffer.
Issues fdatasync
for the underlying file, instructing the OS to flush
all writes to the device, providing durability even if the system
crashes or is rebooted.
pre-allocates space in the filesystem to hold a file at least as big as the size argument.
Truncates a file to the specified size.
Warning: synchronous operation, will block the reactor
rename this file.
Warning: synchronous operation, will block the reactor
remove this file.
The file does not have to be closed to be removed. Removing removes the name from the filesystem but the file will still be accessible for as long as it is open.
Warning: synchronous operation, will block the reactor
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for BufferedFile
impl !Send for BufferedFile
impl !Sync for BufferedFile
impl Unpin for BufferedFile
impl !UnwindSafe for BufferedFile
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more