Copyright | (c) 2019 Composewell Technologies |
---|---|
License | BSD3 |
Maintainer | streamly@composewell.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Combinators to build Inet/TCP clients and servers.
Synopsis
- acceptOnAddr :: MonadIO m => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
- acceptOnAddrWith :: MonadIO m => [(SocketOption, Int)] -> Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket
- acceptOnPort :: MonadIO m => Unfold m PortNumber Socket
- acceptOnPortWith :: MonadIO m => [(SocketOption, Int)] -> Unfold m PortNumber Socket
- acceptOnPortLocal :: MonadIO m => Unfold m PortNumber Socket
- connectionsOnAddr :: MonadAsync m => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Socket
- connectionsOnAddrWith :: MonadAsync m => [(SocketOption, Int)] -> (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Socket
- connectionsOnPort :: MonadAsync m => PortNumber -> SerialT m Socket
- connectionsOnLocalHost :: MonadAsync m => PortNumber -> SerialT m Socket
- connect :: (Word8, Word8, Word8, Word8) -> PortNumber -> IO Socket
- withConnectionM :: (MonadMask m, MonadIO m) => (Word8, Word8, Word8, Word8) -> PortNumber -> (Socket -> m ()) -> m ()
- usingConnection :: (MonadCatch m, MonadIO m) => Unfold m Socket a -> Unfold m ((Word8, Word8, Word8, Word8), PortNumber) a
- read :: (MonadCatch m, MonadIO m) => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Word8
- withConnection :: (IsStream t, MonadCatch m, MonadIO m) => (Word8, Word8, Word8, Word8) -> PortNumber -> (Socket -> t m a) -> t m a
- toBytes :: (IsStream t, MonadCatch m, MonadIO m) => (Word8, Word8, Word8, Word8) -> PortNumber -> t m Word8
- write :: (MonadAsync m, MonadCatch m) => (Word8, Word8, Word8, Word8) -> PortNumber -> Fold m Word8 ()
- writeWithBufferOf :: (MonadAsync m, MonadCatch m) => Int -> (Word8, Word8, Word8, Word8) -> PortNumber -> Fold m Word8 ()
- fromBytes :: (MonadCatch m, MonadAsync m) => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> m ()
- fromBytesWithBufferOf :: (MonadCatch m, MonadAsync m) => Int -> (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> m ()
- writeChunks :: (MonadAsync m, MonadCatch m) => (Word8, Word8, Word8, Word8) -> PortNumber -> Fold m (Array Word8) ()
- fromChunks :: (MonadCatch m, MonadAsync m) => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m (Array Word8) -> m ()
- transformBytesWith :: (IsStream t, MonadAsync m, MonadCatch m) => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> t m Word8
TCP Servers
Unfolds
acceptOnAddr :: MonadIO m => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket Source #
Unfold a tuple (ipAddr, port)
into a stream of connected TCP sockets.
ipAddr
is the local IP address and port
is the local port on which
connections are accepted.
Since: 0.7.0
acceptOnAddrWith :: MonadIO m => [(SocketOption, Int)] -> Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Socket Source #
acceptOnPort :: MonadIO m => Unfold m PortNumber Socket Source #
Like acceptOnAddr
but binds on the IPv4 address 0.0.0.0
i.e. on all
IPv4 addresses/interfaces of the machine and listens for TCP connections on
the specified port.
acceptOnPort = UF.supplyFirst acceptOnAddr (0,0,0,0)
Since: 0.7.0
acceptOnPortWith :: MonadIO m => [(SocketOption, Int)] -> Unfold m PortNumber Socket Source #
acceptOnPortLocal :: MonadIO m => Unfold m PortNumber Socket Source #
Like acceptOnAddr
but binds on the localhost IPv4 address 127.0.0.1
.
The server can only be accessed from the local host, it cannot be accessed
from other hosts on the network.
acceptOnPortLocal = UF.supplyFirst acceptOnAddr (127,0,0,1)
Since: 0.7.0
Streams
connectionsOnAddr :: MonadAsync m => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Socket Source #
Like connections
but binds on the specified IPv4 address of the machine
and listens for TCP connections on the specified port.
Internal
connectionsOnAddrWith :: MonadAsync m => [(SocketOption, Int)] -> (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Socket Source #
connectionsOnPort :: MonadAsync m => PortNumber -> SerialT m Socket Source #
Like connections
but binds on the IPv4 address 0.0.0.0
i.e. on all
IPv4 addresses/interfaces of the machine and listens for TCP connections on
the specified port.
connectionsOnPort = connectionsOnAddr (0,0,0,0)
Internal
connectionsOnLocalHost :: MonadAsync m => PortNumber -> SerialT m Socket Source #
Like connections
but binds on the localhost IPv4 address 127.0.0.1
.
The server can only be accessed from the local host, it cannot be accessed
from other hosts on the network.
connectionsOnLocalHost = connectionsOnAddr (127,0,0,1)
Internal
TCP clients
IP Address based operations.
connect :: (Word8, Word8, Word8, Word8) -> PortNumber -> IO Socket Source #
Connect to the specified IP address and port number.
Since: 0.7.0
withConnectionM :: (MonadMask m, MonadIO m) => (Word8, Word8, Word8, Word8) -> PortNumber -> (Socket -> m ()) -> m () Source #
Connect to a remote host using IP address and port and run the supplied
action on the resulting socket. withConnectionM
makes sure that the
socket is closed on normal termination or in case of an exception. If
closing the socket raises an exception, then this exception will be raised
by withConnectionM
.
Internal
Unfolds
usingConnection :: (MonadCatch m, MonadIO m) => Unfold m Socket a -> Unfold m ((Word8, Word8, Word8, Word8), PortNumber) a Source #
Transform an Unfold
from a Socket
to an unfold from a remote IP
address and port. The resulting unfold opens a socket, uses it using the
supplied unfold and then makes sure that the socket is closed on normal
termination or in case of an exception. If closing the socket raises an
exception, then this exception will be raised by usingConnection
.
Internal
read :: (MonadCatch m, MonadIO m) => Unfold m ((Word8, Word8, Word8, Word8), PortNumber) Word8 Source #
Read a stream from the supplied IPv4 host address and port number.
Since: 0.7.0
Streams
withConnection :: (IsStream t, MonadCatch m, MonadIO m) => (Word8, Word8, Word8, Word8) -> PortNumber -> (Socket -> t m a) -> t m a Source #
opens a connection to the specified IPv4
host address and port and passes the resulting socket handle to the
computation withConnection
addr port actact
. The handle will be closed on exit from withConnection
,
whether by normal termination or by raising an exception. If closing the
handle raises an exception, then this exception will be raised by
withConnection
rather than any exception raised by act
.
Internal
Source
toBytes :: (IsStream t, MonadCatch m, MonadIO m) => (Word8, Word8, Word8, Word8) -> PortNumber -> t m Word8 Source #
Read a stream from the supplied IPv4 host address and port number.
Since: 0.7.0
Sink
write :: (MonadAsync m, MonadCatch m) => (Word8, Word8, Word8, Word8) -> PortNumber -> Fold m Word8 () Source #
Write a stream to the supplied IPv4 host address and port number.
Since: 0.7.0
writeWithBufferOf :: (MonadAsync m, MonadCatch m) => Int -> (Word8, Word8, Word8, Word8) -> PortNumber -> Fold m Word8 () Source #
Like write
but provides control over the write buffer. Output will
be written to the IO device as soon as we collect the specified number of
input elements.
Since: 0.7.0
fromBytes :: (MonadCatch m, MonadAsync m) => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> m () Source #
Write a stream to the supplied IPv4 host address and port number.
Since: 0.7.0
fromBytesWithBufferOf :: (MonadCatch m, MonadAsync m) => Int -> (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> m () Source #
Like write
but provides control over the write buffer. Output will
be written to the IO device as soon as we collect the specified number of
input elements.
Since: 0.7.0
writeChunks :: (MonadAsync m, MonadCatch m) => (Word8, Word8, Word8, Word8) -> PortNumber -> Fold m (Array Word8) () Source #
Write a stream of arrays to the supplied IPv4 host address and port number.
Since: 0.7.0
fromChunks :: (MonadCatch m, MonadAsync m) => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m (Array Word8) -> m () Source #
Write a stream of arrays to the supplied IPv4 host address and port number.
Since: 0.7.0
Transformation
transformBytesWith :: (IsStream t, MonadAsync m, MonadCatch m) => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> t m Word8 Source #
Send an input stream to a remote host and produce the output stream from the host. The server host just acts as a transformation function on the input stream. Both sending and receiving happen asynchronously.
Internal