Safe Haskell | None |
---|
Data.Conduit.Network
- sourceSocket :: MonadIO m => Socket -> Producer m ByteString
- sinkSocket :: MonadIO m => Socket -> Consumer ByteString m ()
- type Application m = AppData m -> m ()
- data AppData m
- appSource :: AppData m -> Source m ByteString
- appSink :: AppData m -> Sink ByteString m ()
- appSockAddr :: AppData m -> SockAddr
- appLocalAddr :: AppData m -> Maybe SockAddr
- data ServerSettings m
- serverSettings :: Monad m => Int -> HostPreference -> ServerSettings m
- serverPort :: ServerSettings m -> Int
- serverHost :: ServerSettings m -> HostPreference
- serverAfterBind :: ServerSettings m -> Socket -> m ()
- serverNeedLocalAddr :: ServerSettings m -> Bool
- runTCPServer :: (MonadIO m, MonadBaseControl IO m) => ServerSettings m -> Application m -> m ()
- data ClientSettings m
- clientSettings :: Monad m => Int -> ByteString -> ClientSettings m
- clientPort :: ClientSettings m -> Int
- clientHost :: ClientSettings m -> ByteString
- runTCPClient :: (MonadIO m, MonadBaseControl IO m) => ClientSettings m -> Application m -> m ()
- data HostPreference
- bindPort :: Int -> HostPreference -> IO Socket
- getSocket :: ByteString -> Int -> IO (Socket, SockAddr)
- acceptSafe :: Socket -> IO (Socket, SockAddr)
Basic utilities
sourceSocket :: MonadIO m => Socket -> Producer m ByteString
Stream data from the socket.
This function does not automatically close the socket.
Since 0.0.0
sinkSocket :: MonadIO m => Socket -> Consumer ByteString m ()
Stream data to the socket.
This function does not automatically close the socket.
Since 0.0.0
Simple TCP server/client interface.
type Application m = AppData m -> m ()
A simple TCP application.
Since 0.6.0
data AppData m
The data passed to an Application
.
Since 0.6.0
appSource :: AppData m -> Source m ByteString
appSink :: AppData m -> Sink ByteString m ()
appSockAddr :: AppData m -> SockAddr
appLocalAddr :: AppData m -> Maybe SockAddr
Server
data ServerSettings m
Settings for a TCP server. It takes a port to listen on, and an optional hostname to bind to.
Since 0.6.0
Arguments
:: Monad m | |
=> Int | port to bind to |
-> HostPreference | host binding preferences |
-> ServerSettings m |
Smart constructor.
Since 0.6.0
serverPort :: ServerSettings m -> Int
serverHost :: ServerSettings m -> HostPreference
serverAfterBind :: ServerSettings m -> Socket -> m ()
serverNeedLocalAddr :: ServerSettings m -> Bool
runTCPServer :: (MonadIO m, MonadBaseControl IO m) => ServerSettings m -> Application m -> m ()
Run an Application
with the given settings. This function will create a
new listening socket, accept connections on it, and spawn a new thread for
each connection.
Since 0.6.0
Client
data ClientSettings m
Settings for a TCP client, specifying how to connect to the server.
Since 0.6.0
Arguments
:: Monad m | |
=> Int | port to connect to |
-> ByteString | host to connect to |
-> ClientSettings m |
Smart constructor.
Since 0.6.0
clientPort :: ClientSettings m -> Int
clientHost :: ClientSettings m -> ByteString
runTCPClient :: (MonadIO m, MonadBaseControl IO m) => ClientSettings m -> Application m -> m ()
Run an Application
by connecting to the specified server.
Since 0.6.0
Helper utilities
data HostPreference
Which host to bind.
Note: The IsString
instance recognizes the following special values:
-
*
meansHostAny
-
*4
meansHostIPv4
-
*6
meansHostIPv6
bindPort :: Int -> HostPreference -> IO Socket
Attempt to bind a listening Socket
on the given host/port. If no host is
given, will use the first address available.
maxListenQueue
is topically 128 which is too short for
high performance servers. So, we specify 'max 2048 maxListenQueue' to
the listen queue.
Since 0.3.0
getSocket :: ByteString -> Int -> IO (Socket, SockAddr)
Attempt to connect to the given host/port.
Since 0.6.0
acceptSafe :: Socket -> IO (Socket, SockAddr)
Try to accept a connection, recovering automatically from exceptions.
As reported by Kazu against Warp, resource exhausted (Too many open files) may be thrown by accept(). This function will catch that exception, wait a second, and then try again.
Since 0.6.0