Start to functorise the buffered I/O

The buffered I/O is currently tangled with the ring handling. Separating
these two concerns would make the code easier to read and test.

Signed-off-by: David Scott <dave.scott@citrix.com>