Distinguish IO error from EOF in the read callback function.

This effectively does nothing for the moment since the error state is
not properly propagated.
Fix return values from the write callback function.

- Return the actual size #write has returned.
- Return -1 on error.

Again, this does not affect how libxml2 and nokogiri work for the
moment.