client: on connection, signal the server

This allows the server to notice we've connected and unblock.

Signed-off-by: David Scott <dave.scott@citrix.com>
server: wait for the connection to be established

This means that it is safe to read or write on a connection as soon
as you have the handle.

Related to #24

Signed-off-by: David Scott <dave.scott@citrix.com>
Merge pull request #25 from djs55/test

Partial fixes for #24
close: set our 'live' flag to 'Exiting' and signal the event channel

This is the needed for the other end of the communication to detect that we
have shutdown, and it should return `Eof.

This is part of #24

Signed-off-by: David Scott <dave.scott@citrix.com>
When the server closes, clean up its xenstore entries

Further connections to this client will use fresh memory, grants and event
channel ports and will manifest as a fresh FLOW.

Related to #24

Signed-off-by: David Scott <dave.scott@citrix.com>
Merge pull request #26 from djs55/test

close: set our 'live' flag to 'Exiting' and signal the event channel
Merge pull request #27 from djs55/test

When the server closes, clean up its xenstore entries
Remove the notion of a persistent connection

Once a connection has disconnected and returns `Eof, a fresh
connection must be established.

Related to #24

Signed-off-by: David Scott <dave.scott@citrix.com>
vchan: remove idea of a shared 'waiter' thread

Threads may call read and write concurrently on the same vchan, and
therefore have to use the same event channel. Rather than replicate the
'single-shot-oops-you-missed-it' semantics of the underlying Xen event
channels, everyone should use the activations mechanism instead, which
tracks the number of times the event channel has been signalled and
guarantees that you'll not miss one and then block forever.

The downside is that we'll probably check for outstanding work one more
time than strictly necessary in the common case, but this is just a
memory load so it's not worth worrying about (I assert)

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Merge pull request #28 from djs55/test

Remove the notion of a 'persistent' connection
If we aren't connected, return `Eof

This is expected behaviour after the other end has disconnected.

The case where {read,write] is called before a connection has been
accepted should be handled by blocking (not in this patch)

Signed-off-by: David Scott <dave.scott@citrix.com>
Lwt_io: on `Eof from the FLOW, return 0 bytes read or written

This matches the behaviour of the file descriptors that Lwt_io is
usually used over.

Signed-off-by: David Scott <dave.scott@citrix.com>
Implement Lwt_io.close on the input side of a vchan to close the connection.

Signed-off-by: David Scott <dave.scott@citrix.com>
Merge pull request #29 from djs55/test

Partial implementation of close
vchan: check for `Eof in the inner loops of read, write and writev

Previously we only checked the connection state on entry, but then would
block forever waiting for data to arrive. We would be signalled on close
but not re-check the state.

We now always check the state.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
xencat: while proxying, End_of_file means we should shutdown cleanly

There is one proxy thread for each direction. When one of these threads
gets End_of_file, it should unblock, shutdown the connection and cleanup.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Merge pull request #30 from djs55/test

Handle `Eof while blocked in read/write
xencat: catch SIGINT (Control+C) and trigger the disconnect and cleanup

Otherwise Control+C exits the process uncleanly and without signalling
to the other end that we've gone away.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Merge pull request #31 from djs55/test

xencat: catch SIGINT (Control+C) and trigger the disconnect and cleanup
Lwt_unix: rename functions to 'open_client' and 'open_server'

We still need to support a more traditional client/server model by
having some kind of 'listen', 'accept' and 'connect'. This will need
to be built on top of 'open_client' and 'open_server'.

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