Adding registration/waiting on fds, as well as wait-loop.

Still entirely untested, will add some simple tests soon.