Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Accept (m :: Type -> Type) fd addr = Accept {}
- data Accepted fd addr where
- AcceptFailure :: forall fd addr. !SomeException -> Accepted fd addr
- Accepted :: forall fd addr. !fd -> !addr -> Accepted fd addr
- data AddressFamily addr where
- SocketFamily :: !Family -> AddressFamily SockAddr
- LocalFamily :: !LocalAddress -> AddressFamily LocalAddress
- TestFamily :: forall addr1. AddressFamily (TestAddress addr1)
- data Snocket (m :: Type -> Type) 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 -> m (Accept m fd addr)
- close :: fd -> m ()
- makeSocketBearer :: MakeBearer IO Socket
- type SocketSnocket = Snocket IO Socket SockAddr
- socketSnocket :: IOManager -> SocketSnocket
- type LocalSnocket = Snocket IO LocalSocket LocalAddress
- localSnocket :: IOManager -> LocalSnocket
- makeLocalBearer :: MakeBearer IO LocalSocket
- newtype LocalSocket = LocalSocket {
- getLocalHandle :: LocalHandle
- newtype LocalAddress = LocalAddress {}
- localAddressFromPath :: FilePath -> LocalAddress
- newtype TestAddress addr = TestAddress {
- getTestAddress :: addr
- data FileDescriptor
- socketFileDescriptor :: Socket -> IO FileDescriptor
- localSocketFileDescriptor :: LocalSocket -> IO FileDescriptor
- invalidFileDescriptor :: FileDescriptor
- newtype MakeBearer (m :: Type -> Type) fd = MakeBearer {}
Snocket Interface
newtype Accept (m :: Type -> Type) 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 Accepted fd addr where Source #
AcceptFailure :: forall fd addr. !SomeException -> Accepted fd addr | |
Accepted :: forall fd addr. !fd -> !addr -> Accepted fd addr |
data AddressFamily addr where Source #
We support either sockets or named pipes.
There are three families of addresses: SocketFamily
used for Berkeley
sockets, LocalFamily
used for LocalAddress
es (either Unix sockets or
Windows named pipe addresses), and TestFamily
for testing purposes.
LocalFamily
requires LocalAddress
, this is needed to provide path of the
opened Win32 HANDLE
.
SocketFamily :: !Family -> AddressFamily SockAddr | |
LocalFamily :: !LocalAddress -> AddressFamily LocalAddress | |
TestFamily :: forall addr1. AddressFamily (TestAddress addr1) | Using a newtype wrapper |
Instances
Show addr => Show (AddressFamily addr) Source # | |
Defined in Ouroboros.Network.Snocket showsPrec :: Int -> AddressFamily addr -> ShowS # show :: AddressFamily addr -> String # showList :: [AddressFamily addr] -> ShowS # | |
Eq addr => Eq (AddressFamily addr) Source # | |
Defined in Ouroboros.Network.Snocket (==) :: AddressFamily addr -> AddressFamily addr -> Bool # (/=) :: AddressFamily addr -> AddressFamily addr -> Bool # |
data Snocket (m :: Type -> Type) 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.
Snocket | |
|
Socket based Snockets
:: IOManager |
Though it could be used in |
-> SocketSnocket |
Local Snockets
type LocalSnocket = Snocket IO LocalSocket LocalAddress Source #
System dependent LocalSnocket
localSnocket :: IOManager -> LocalSnocket Source #
Create a LocalSnocket
.
On Windows, there is no way to get path associated to a named pipe. To go
around this, the address passed to open
via LocalFamily
will be
referenced by LocalSocket
.
newtype LocalSocket Source #
System dependent LocalSnocket type
LocalSocket | |
|
Instances
Generic LocalSocket Source # | |||||
Defined in Ouroboros.Network.Snocket
from :: LocalSocket -> Rep LocalSocket x # to :: Rep LocalSocket x -> LocalSocket # | |||||
Show LocalSocket Source # | |||||
Defined in Ouroboros.Network.Snocket showsPrec :: Int -> LocalSocket -> ShowS # show :: LocalSocket -> String # showList :: [LocalSocket] -> ShowS # | |||||
Eq LocalSocket Source # | |||||
Defined in Ouroboros.Network.Snocket (==) :: LocalSocket -> LocalSocket -> Bool # (/=) :: LocalSocket -> LocalSocket -> Bool # | |||||
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`.
Instances
newtype TestAddress addr Source #
TestAddress | |
|
Instances
NFData addr => NFData (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket rnf :: TestAddress addr -> () # | |||||
Generic (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket
from :: TestAddress addr -> Rep (TestAddress addr) x # to :: Rep (TestAddress addr) x -> TestAddress addr # | |||||
Show addr => Show (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket showsPrec :: Int -> TestAddress addr -> ShowS # show :: TestAddress addr -> String # showList :: [TestAddress addr] -> ShowS # | |||||
Eq addr => Eq (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket (==) :: TestAddress addr -> TestAddress addr -> Bool # (/=) :: TestAddress addr -> TestAddress addr -> Bool # | |||||
Ord addr => Ord (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket compare :: TestAddress addr -> TestAddress addr -> Ordering # (<) :: TestAddress addr -> TestAddress addr -> Bool # (<=) :: TestAddress addr -> TestAddress addr -> Bool # (>) :: TestAddress addr -> TestAddress addr -> Bool # (>=) :: TestAddress addr -> TestAddress addr -> Bool # max :: TestAddress addr -> TestAddress addr -> TestAddress addr # min :: TestAddress addr -> TestAddress addr -> TestAddress addr # | |||||
Hashable addr => Hashable (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket hashWithSalt :: Int -> TestAddress addr -> Int # hash :: TestAddress addr -> Int # | |||||
Typeable addr => NoThunks (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket noThunks :: Context -> TestAddress addr -> IO (Maybe ThunkInfo) # wNoThunks :: Context -> TestAddress addr -> IO (Maybe ThunkInfo) # showTypeOf :: Proxy (TestAddress addr) -> String # | |||||
type Rep (TestAddress addr) Source # | |||||
Defined in Ouroboros.Network.Snocket type Rep (TestAddress addr) = D1 ('MetaData "TestAddress" "Ouroboros.Network.Snocket" "ouroboros-network-framework-0.14.0.0-inplace" 'True) (C1 ('MetaCons "TestAddress" 'PrefixI 'True) (S1 ('MetaSel ('Just "getTestAddress") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 addr))) |
data FileDescriptor Source #
Socket file descriptor.
Instances
Generic FileDescriptor Source # | |||||
Defined in Ouroboros.Network.Snocket
from :: FileDescriptor -> Rep FileDescriptor x # to :: Rep FileDescriptor x -> FileDescriptor # | |||||
Show FileDescriptor Source # | |||||
Defined in Ouroboros.Network.Snocket showsPrec :: Int -> FileDescriptor -> ShowS # show :: FileDescriptor -> String # showList :: [FileDescriptor] -> ShowS # | |||||
type Rep FileDescriptor Source # | |||||
Defined in Ouroboros.Network.Snocket type Rep FileDescriptor = D1 ('MetaData "FileDescriptor" "Ouroboros.Network.Snocket" "ouroboros-network-framework-0.14.0.0-inplace" '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.
for testing
invalidFileDescriptor :: FileDescriptor Source #
invalidFileDescriptor - when we need something for testing/simulation
Re-exports
newtype MakeBearer (m :: Type -> Type) fd #