Make PipeIOStream.write_to_fd handle EAGAIN/EWOULDBLOCK and EBADF properly

The current implementation of PipeIOStream.write_to_fd makes no attempt to handle errors. If the other end of the pipe is closed, it propagates an IOError with EBADF all the way out. If the pipe buffer is full, it propagates an IOError with EAGAIN. This easily manifests if you try to write a large amount of data to a Subprocess's stdin, for example.

The read_from_fd function is properly implemented as far as I know. I re-used its error handling logic to handle EAGAIN/EBADF during writes and it resolved the issues I was seeing in my application.