Introduce functions for proper I/O handling. These functions are able to deal with interrupts and partial I/O.