Crate palaver[][src]

Cross-platform polyfills.

Crates.ioRepo

This library attempts to provide reliable pollyfills for functionality that isn't implemented on all platforms, for example gettid, memfd_create, fexecve, as well as providing non-atomic versions of functions like accept4, socket+SOCK_CLOEXEC, pipe2, and other miscellanea like seal to make a file descriptor read-only thus suitable for fexecve.

palaver = "Platform Abstraction Layer" / pa·lav·er n. – prolonged and tedious fuss.

It's currently used on unix-family systems; most Windows functionality is TODO.

Structs

SockFlag

Akin to nix::sys::socket::SockFlag but avail cross-platform

Functions

accept

Like accept4, falls back to non-atomic accept

copy

Loops io::copy till len elapsed or error

copy_sendfile

Loops sendfile till len elapsed or error

copy_splice

Loops splice till len elapsed or error

dup

Like dup except O_CLOEXEC can be passed atomically

dup_to

Like dup2/3; automatically retries on EBUSY on Linux

fexecve

Falls back to execve("/proc/self/fd/{fd}",...), falls back to execve("/tmp/{randomfilename}")

gettid

Get an identifier for the thread; uses gettid on linux; pthread_threadid_np on mac; GetCurrentThreadId on windows.

is_connected

Intended to check for completion after connect(2) has returned EINPROGRESS.

is_valgrind

Check if we're running under valgrind

memfd_create

Falls back to shm_open, falls back to creating+unlinking /tmp/{random_filename}

move_fds

Maps file descriptors [(from,to)]

pipe

Like pipe2; not atomic on platforms that lack it

seal

Makes a file descriptor read-only, which seems neccessary on some platforms to pass to fexecve and is good practise anyway

socket

Falls back to non-atomic if SOCK_NONBLOCK/SOCK_CLOEXEC unavailable

spawn

A wrapper around std::thread::spawn() that blocks until the new thread has left library code. Library code can do things like temporarily opening fds (leading to dup2 on other threads returning EBUSY on Linux), so blocking this thread until it's done just makes things more predictable.

unreceived

Count of bytes that have yet to be read from a socket

unsent

Count of bytes that have been written to a socket, but have yet to be acked by the remote end

valgrind_start_fd

Valgrind sets up various file descriptors for its purposes; they're all > any user fds, and this function gets the lowest of them