Bug fix #37: Infinite loop in daemon mode caused by POLLHUP

Fix infinite loop issue caused by POLLHUP returned after a writer to
daemon pipe disconnects, and convert standard library reading to Unix
file descriptor based reading, like what fazjaxton did in #33.