pakr-managedrawfd 1.0.0

A Trait and two Impls dealing with auto-closing RawFd file handles with a sensible Clone trait implementations.
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented2 out of 6 items with examples
  • Size
  • Source code size: 10.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 422.51 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • p-kraszewski/pakr-managedrawfd
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • p-kraszewski

A Trait and two Impls dealing with auto-closing RawFd file handles with a sensible Clone trait implementations.

  • DuplicatingFD holds a raw handle directly and duplicates itself by calls to dup(2) - that is each instance has its own handle that is individually closed on end-of-life of that instance. May panic on clone() call due to underlying OS error.

  • SharedFD holds a raw handle in std::sync::Arc and duplicates itself by duplicating said Arc - that is each instance shares a single handle, which is closed after the last instance reaches end-of-life.

Common functionality

Both implementations...

  • implement AsRawFd and Clone traits.
  • have a wrap(fd) constructor that simply packs fd in managed shell and takes ownership (you shouldn't use fd afterwards and definitely not close() it).
  • have a dup_wrap(fd) constructor that packs dup(2) copy of fd in managed shell. It doesn't take the ownership of the original fd, which you should dispose-of properly.
  • have a dup() method that clones handle accordingly, returning eventual errors.

Multi-access

Both are not multi-access safe, with SharedFD being even less safe.

  • Each of the related DuplicatingFD instances has its own read/write pointer (still stepping on each other's toes during writes)
  • All the related SharedFD instances have a single, shared read/write pointer.