hans-2.4.0.0: IPv4 Network Stack

Safe HaskellNone
LanguageHaskell98

Hans.Layer.Tcp.Monad

Synopsis

Documentation

data TcpState Source

Constructors

TcpState 

self :: Tcp TcpHandle Source

The handle to this layer.

ip4Handle :: Tcp IP4Handle Source

Get the handle to the IP4 layer.

modifyHost :: (Host -> Host) -> Tcp () Source

resetTimeWait2MSL :: SocketId -> Tcp () Source

Reset the 2MSL timer on the socket in TimeWait.

lookupConnection :: SocketId -> Tcp (Maybe TcpSocket) Source

Lookup a connection, returning Nothing if the connection doesn't exist.

getConnection :: SocketId -> Tcp TcpSocket Source

Retrieve a connection from the host. The computation fails if the connection doesn't exist.

setConnection :: SocketId -> TcpSocket -> Tcp () Source

Assign a connection to a socket id. If the TcpSocket is in TimeWait, this will do two things:

  1. Remove the corresponding key from the connections map
  2. Add the socket to the TimeWait map, using the current value of its 2MSL timer (which should be set when the TimeWait state is entered)

The purpose of this is to clean up the memory associated with the connection as soon as possible, and once it's in TimeWait, no data will flow on the socket.

addConnection :: SocketId -> TcpSocket -> Tcp () Source

Add a new connection to the host.

modifyConnection :: SocketId -> (TcpSocket -> TcpSocket) -> Tcp () Source

Modify an existing connection in the host.

remConnection :: SocketId -> Tcp () Source

Remove a connection from the host.

sendSegment :: IP4 -> TcpHeader -> ByteString -> Tcp () Source

Send out a tcp segment via the IP layer.

initialSeqNum :: Tcp TcpSeqNum Source

Get the initial sequence number.

addInitialSeqNum :: TcpSeqNum -> Tcp () Source

Increment the initial sequence number by a value.

allocatePort :: Tcp TcpPort Source

Allocate a new port for use.

closePort :: TcpPort -> Tcp () Source

Release a used port.

newtype Sock a Source

Tcp operations in the context of a socket.

This implementation is a bit ridiculous, and when the eventual rewrite comes this should be one of the first things to be reconsidered. The basic problem is that if you rely on the finished implementation for the Layer monad, you exit from the socket context as well, losing any changes that have been made locally. This gives the ability to simulate finished, with the benefit of only yielding from the Sock context, not the whole Tcp context.

Constructors

Sock 

Fields

unSock :: forall r. TcpSocket -> Escape r -> Next a r -> Tcp (TcpSocket, Maybe r)
 

type Next a r = TcpSocket -> a -> Tcp (TcpSocket, Maybe r) Source

inTcp :: Tcp a -> Sock a Source

escape :: Sock a Source

Finish early, with no result.

runSock :: TcpSocket -> Sock a -> Tcp (TcpSocket, Maybe a) Source

Run the socket action, and increment its internal timestamp value.

eachConnection :: Sock () -> Tcp () Source

Iterate for each connection, rolling back to its previous state if the computation fails.

withConnection' :: IP4 -> TcpHeader -> Sock a -> Tcp () -> Tcp () Source

establishedConnection :: SocketId -> Sock a -> Tcp () Source

Run a socket operation in the context of the socket identified by the socket id.

XXX this should really be renamed, as it's not guarding on the state of the socket

getParent :: Sock (Maybe SocketId) Source

Get the parent id of the current socket, and fail if it doesn't exist.

inParent :: Sock a -> Sock (Maybe a) Source

Run an action in the context of the socket's parent. Returns Nothing if the connection has no parent.

setState :: ConnState -> Sock () Source

Set the state of the current connection.

getState :: Sock ConnState Source

Get the state of the current connection.

popAcceptor :: Sock (Maybe Acceptor) Source

Pop off an acceptor.

notify :: Bool -> Sock () Source

Send a notification back to a waiting process that the socket has been established, or that it has failed. It's assumed that this will only be called from the context of a user socket, so when the parameter is False, the user close field will be set to true.

outputS :: IO () -> Sock () Source

Output some IO to the Tcp layer.

tcpOutput :: TcpHeader -> ByteString -> Sock () Source

Send a TCP segment in the context of a socket.

shutdown :: Sock () Source

Unblock any waiting processes, in preparation to close.

closeSocket :: Sock () Source

Set the socket state to closed, and unblock any waiting processes.