Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Network.Snocket
Synopsis
- newtype Accept m fd addr = Accept {}
- data AddressFamily addr where
- data Snocket m fd addr = Snocket {
- getLocalAddr :: fd -> m addr
- getRemoteAddr :: fd -> m addr
- addrFamily :: addr -> AddressFamily addr
- open :: AddressFamily addr -> m fd
- openToConnect :: addr -> m fd
- connect :: fd -> addr -> m ()
- bind :: fd -> addr -> m ()
- listen :: fd -> m ()
- accept :: fd -> Accept m fd addr
- close :: fd -> m ()
- toBearer :: DiffTime -> Tracer m MuxTrace -> fd -> MuxBearer m
- type SocketSnocket = Snocket IO Socket SockAddr
- socketSnocket :: IOManager -> SocketSnocket
- type LocalSnocket = Snocket IO LocalSocket LocalAddress
- localSnocket :: IOManager -> FilePath -> LocalSnocket
- newtype LocalSocket = LocalSocket {
- getLocalHandle :: LocalHandle
- newtype LocalAddress = LocalAddress {}
- localAddressFromPath :: FilePath -> LocalAddress
- data FileDescriptor
- socketFileDescriptor :: Socket -> IO FileDescriptor
- localSocketFileDescriptor :: LocalSocket -> IO FileDescriptor
Snocket Interface
newtype Accept m fd addr 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
.
data AddressFamily addr where Source #
We support either sockets or named pipes.
Constructors
SocketFamily :: !Family -> AddressFamily SockAddr | |
LocalFamily :: AddressFamily LocalAddress |
Instances
Eq (AddressFamily addr) Source # | |
Defined in Ouroboros.Network.Snocket Methods (==) :: AddressFamily addr -> AddressFamily addr -> Bool # (/=) :: AddressFamily addr -> AddressFamily addr -> Bool # | |
Show (AddressFamily addr) Source # | |
Defined in Ouroboros.Network.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
Arguments
:: IOManager |
Though it could be used in |
-> SocketSnocket |
Local Snockets
type LocalSnocket = Snocket IO LocalSocket LocalAddress Source #
System dependent LocalSnocket
localSnocket :: IOManager -> FilePath -> LocalSnocket Source #
newtype LocalSocket Source #
System dependent LocalSnocket type
Constructors
LocalSocket | |
Fields
|
Instances
Eq LocalSocket Source # | |
Defined in Ouroboros.Network.Snocket | |
Show LocalSocket Source # | |
Defined in Ouroboros.Network.Snocket Methods showsPrec :: Int -> LocalSocket -> ShowS # show :: LocalSocket -> String # showList :: [LocalSocket] -> ShowS # | |
Generic LocalSocket Source # | |
Defined in Ouroboros.Network.Snocket Associated Types type Rep LocalSocket :: Type -> Type # | |
type Rep LocalSocket Source # | |
Defined in Ouroboros.Network.Snocket |
newtype LocalAddress Source #
Local address, on Unix is associated with AF_UNIX
family, on
Windows with `named-pipes`.
Constructors
LocalAddress | |
Fields |
Instances
data FileDescriptor Source #
Socket file descriptor.
Instances
Show FileDescriptor Source # | |
Defined in Ouroboros.Network.Snocket Methods showsPrec :: Int -> FileDescriptor -> ShowS # show :: FileDescriptor -> String # showList :: [FileDescriptor] -> ShowS # | |
Generic FileDescriptor Source # | |
Defined in Ouroboros.Network.Snocket Associated Types type Rep FileDescriptor :: Type -> Type # Methods from :: FileDescriptor -> Rep FileDescriptor x # to :: Rep FileDescriptor x -> FileDescriptor # | |
type Rep FileDescriptor Source # | |
Defined in Ouroboros.Network.Snocket type Rep FileDescriptor = D1 ('MetaData "FileDescriptor" "Ouroboros.Network.Snocket" "ouroboros-network-framework-0.1.0.0-KkueAIRtlld4DOJE9pzECA" 'True) (C1 ('MetaCons "FileDescriptor" 'PrefixI 'True) (S1 ('MetaSel ('Just "getFileDescriptor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))) |
socketFileDescriptor :: Socket -> IO FileDescriptor Source #
We use unsafeFdSocket
but FileDescriptor
constructor is not exposed.
This forbids any usage of FileDescriptor
(at least in a straightforward
way) using any low level functions which operate on file descriptors.