Start refactoring module types

- move module types to lib/s.ml (avoiding silly .ml .mli duplication)
- make PIPE-related types fully abstract: we will specialise with
  concrete types elsewhere

Signed-off-by: David Scott <dave.scott@citrix.com>
Update the Xenstore and Console ring to the new API

Signed-off-by: David Scott <dave.scott@citrix.com>
Functorise PIPE over EVENTS

We now have
- available: immediately returns data available now
- wait: blocks until n units of data are available

Signed-off-by: David Scott <dave.scott@citrix.com>
Implement the PIPE.wait function

This blocks on the EVENT (channel, or other source of events) until
n units of data are available for reading or writing.

Signed-off-by: David Scott <dave.scott@citrix.com>
Import In_memory_events from ocaml-vchan

The implementation of a buffered ring will be functorised over
the EVENTS signature and will need an in-process implementation.
We should move this code into xen-evtchn and remove it from both
ocaml-vchan and here.

Signed-off-by: David Scott <dave.scott@citrix.com>
Remove the 'type channel' from the 'WINDOW' signature

Instead the adopt the convention that the 'create' function passes
in the correct event channel to use, so we don't have to keep
resupplying it on every call to 'wait'

Signed-off-by: David Scott <dave.scott@citrix.com>
Pipe: signal on the event channel when data is formally consumed

Although we can read from and write to available space, it's only
when we bump the pointers that we need to signal the associated
channel.

Signed-off-by: David Scott <dave.scott@citrix.com>
BufferedPipe: proxy data in both directions

This isn't quite right as we have only one event channel connected
and clearly we need two channels connected to each other.

Signed-off-by: David Scott <dave.scott@citrix.com>
Expose both frontend and backend versions of the rings

Signed-off-by: David Scott <dave.scott@citrix.com>
BufferedPipe: split into backend and frontend

The user will read and write from the frontend, while a hidden
backend proxies data in both directions to and from the real
device.

Signed-off-by: David Scott <dave.scott@citrix.com>
test: add a simple unit test for the xenstore ring

Signed-off-by: David Scott <dave.scott@citrix.com>
Pipe: add a write function

We
- change 'type data = Cstruct.t list' so all available space
  in a ring can be represented even when it wraps round
- add a 'write' function which writes data without calling
  'advance'.
- change the BufferedPipe Proxy function to use write, rather
  than single byte writes.

Signed-off-by: David Scott <dave.scott@citrix.com>
test: check that no data is available for reading before the write

Signed-off-by: David Scott <dave.scott@citrix.com>
test: check that writing over a ring boundary works ok

This test currently fails.

Signed-off-by: David Scott <dave.scott@citrix.com>
pipe: correct reading across the ring boundary

This fixes the unit test.

Signed-off-by: David Scott <dave.scott@citrix.com>
test: register the 'pipe_test' as a test

Signed-off-by: David Scott <dave.scott@citrix.com>
test: hook up the C ring tests again

These tests currently fail.

Signed-off-by: David Scott <dave.scott@citrix.com>
test: the ring tests now pass again

Signed-off-by: David Scott <dave.scott@citrix.com>
Split into Ring (unbuffered) and Channel (buffered)

We will always use the Channel interface and decide at runtime whether
to ask for a layer of buffering or not.

Signed-off-by: David Scott <dave.scott@citrix.com>
Rename 'PIPE' to 'BYTE_RING'

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