iohk-monitoring-0.1.10.1: logging, benchmarking and monitoring framework
Safe HaskellNone
LanguageHaskell2010

Cardano.BM.Snocket

Synopsis

Snocket Interface

newtype Accept addr fd Source #

Named pipes and Berkeley sockets have different API when accepting a connection. For named pipes the file descriptor created by createNamedPipe is supposed to be used for the first connected client. Named pipe accept loop looks this way:

acceptLoop k = do
  h <- createNamedPipe name
  connectNamedPipe h
  -- h is now in connected state
  forkIO (k h)
  acceptLoop k

For Berkeley sockets equivalent loop starts by creating a socket which accepts connections and accept returns a new socket in connected state

acceptLoop k = do
    s <- socket ...
    bind s address
    listen s
    loop s
  where
    loop s = do
      (s' , _addr') <- accept s
      -- s' is in connected state
      forkIO (k s')
      loop s

To make common API for both we use a recursive type Accept, see berkeleyAccept below. Creation of a socket / named pipe is part of Snocket, but this means we need to have different recursion step for named pipe & sockets. For sockets its recursion step will always return accept syscall; for named pipes the first callback will reuse the file descriptor created by open and only subsequent calls will create a new file descriptor by createNamedPipe, see namedPipeSnocket.

Constructors

Accept 

Fields

fmapAccept :: (addr -> addr') -> Accept addr fd -> Accept addr' fd Source #

Arguments of Accept are in the wrong order.

TODO: this can be fixed later.

mkListeningSocket :: Snocket IO fd addr -> Maybe addr -> AddressFamily addr -> IO fd Source #

data AddressFamily addr where Source #

We support either sockets or named pipes.

Instances

Instances details
Eq (AddressFamily addr) Source # 
Instance details

Defined in Cardano.BM.Snocket

Methods

(==) :: AddressFamily addr -> AddressFamily addr -> Bool #

(/=) :: AddressFamily addr -> AddressFamily addr -> Bool #

Show (AddressFamily addr) Source # 
Instance details

Defined in Cardano.BM.Snocket

Methods

showsPrec :: Int -> AddressFamily addr -> ShowS #

show :: AddressFamily addr -> String #

showList :: [AddressFamily addr] -> ShowS #

data Snocket m fd addr Source #

Abstract communication interface that can be used by more than Socket. Snockets are polymorphic over monad which is used, this feature is useful for testing and/or simulations.

Constructors

Snocket 

Fields

Socket based Snocktes

socketSnocket Source #

Arguments

:: IOManager

IOManager interface. We use it when we create a new socket and when we accept a connection.

Though it could be used in open, but that is going to be used in a bracket so it's better to keep it simple.

-> SocketSnocket 

Create a Snocket for the given Family. In the bind method set ReuseAddr and ReusePort.

Local Snockets

type LocalSnocket = Snocket IO Socket LocalAddress Source #

System dependent LocalSnocket type

newtype LocalAddress Source #

Local address, on Unix is associated with AF_UNIX family, on

Windows with `named-pipes`.

Constructors

LocalAddress