nettle-openflow-0.1: High level configuration and control of computer networks.



Provides a generic TCP server, parameterized over the server's listening port and the types of messages received from and sent to clients.



tcpServer :: Show a => ServerPortNumber -> TCPMessageDriver a b -> IO [Peer a b]Source

tcpServer starts a TCP server at the given port number, waiting for new connections. Whenever a new connection is established, new threads are created for reading and writing to the thread, using the given tcp message driver. The socket address of the other side of the connection, along with a pair of channels for the incoming messages and outgoing messages is placed on the result channel. This method returns immediately.

data TCPMessageDriver a b Source

A TCPMessageDriver a b is used by the tcpServer to read messages of type a from the underlying TCP sockets with peers as well as write messages of type b to the TCP sockets.




getMessage :: Handle -> IO (Maybe a)

Method to read a value from the handle. Returns Nothing if the read failed.

putMessage :: b -> Handle -> IO ()

Method to write a value to a handle.

type Peer a b = (SockAddr, Process a b IOException)Source

A Peer is a TCP peer. It consists of a SockAddr value giving the the socket address of the peer, as well as a Process value which provides methods to access messages received from the peer and send messages to a peer.

data Process a b c Source

A Process a b c represents a process with an API that allows another IO computation to observe its outputs (of type a), to supply it with inputs (of type b), and to observe when it terminates.




readP :: IO a

interact with the process by receiving one of its outputs; should block until the process emits a value.

tellP :: b -> IO ()

interact with the process by sending it an input; should be non-blocking.

whenDeadP :: IO c

should block until the process terminates, carrying an output value of type c.

readAll :: Process a b c -> IO [a]Source

Read all of the output from the process as a lazy stream.

writeAll :: Process a b c -> [b] -> IO ()Source

Write a list to the process; does not return until every element of the list has been sent to the process.