Continuation on the miniature project I had started for building my own minimal mio. This mini private project can be found in the rust-async/mini-mio private repo.
Note
libc is not always used, and ffi interfaces are defined within this crate for epoll
and kqueue directly.
epoll examples:
- delayserver
- stdinmonitoring
kqueue examples:
- filemonitoring (kqueue)
- timers (kqueue)
This makes use of the delayserver found in rust-async-utils. Hence, that must be up and running first for this basic example to work correctly.
- delayserver from private repo.
- linux OS: uses epoll only
cargo run --example delayserverHere we are adding standard input's file descriptor (fd0) to epoll's interest list.
- linux OS: uses epoll only
cargo run --example stdinmonitoringWe trigger events via writing to the proccesses stdin. This can be achieved via following commands:
- Get the process id
Using either the below command,
ps aux | grep "stdinmonitoring"or via reading out the process_id that is logged to stdout when example is first started up.
- Write directly into the file descriptor
echo "<some text input here>" >> /proc/<PID>/fd/0`Where file description zero is typically the standard input.
This opens a file with the O_EVTONLY flag and adds and event with a system filter that watches for various types of events to occur to a file descriptor. A separate file descriptor, with it's own open file description entry, is used in a spawned thread to write out to the file. The kernel queue is then polled again to retrieve the event notification on the first file descriptor.
- BSD / OSX
- kqueue
cargo run --example filemonitoringWhen using the open syscall, to create a file if it doesn't exist (O_CREAT), some
additional mode bits must also be passed in as a bitmask to set the permissions on the
temporary file. If these are not set, you could end up with permission errors when
attempting to write to the file after initially creating it.
chmodman pages on OSX: the permission bits are defined here and not inopen's man page.
Uses kqueue with timer based system filters.
- BSD / OSX
- kqueue
cargo run --example timers