Safe Haskell | None |
---|
- sourceSocket :: MonadIO m => Socket -> GSource m ByteString
- sinkSocket :: MonadIO m => Socket -> GInfSink 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 -> GSource m ByteStringSource
Stream data from the socket.
This function does not automatically close the socket.
Since 0.0.0
sinkSocket :: MonadIO m => Socket -> GInfSink ByteString mSource
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 ()Source
A simple TCP application.
Since 0.6.0
appSource :: AppData m -> Source m ByteStringSource
appSink :: AppData m -> Sink ByteString m ()Source
appSockAddr :: AppData m -> SockAddrSource
appLocalAddr :: AppData m -> Maybe SockAddrSource
Server
data ServerSettings m Source
Settings for a TCP server. It takes a port to listen on, and an optional hostname to bind to.
Since 0.6.0
:: Monad m | |
=> Int | port to bind to |
-> HostPreference | host binding preferences |
-> ServerSettings m |
Smart constructor.
Since 0.6.0
serverPort :: ServerSettings m -> IntSource
serverAfterBind :: ServerSettings m -> Socket -> m ()Source
runTCPServer :: (MonadIO m, MonadBaseControl IO m) => ServerSettings m -> Application m -> m ()Source
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 Source
Settings for a TCP client, specifying how to connect to the server.
Since 0.6.0
:: Monad m | |
=> Int | port to connect to |
-> ByteString | host to connect to |
-> ClientSettings m |
Smart constructor.
Since 0.6.0
clientPort :: ClientSettings m -> IntSource
clientHost :: ClientSettings m -> ByteStringSource
runTCPClient :: (MonadIO m, MonadBaseControl IO m) => ClientSettings m -> Application m -> m ()Source
Run an Application
by connecting to the specified server.
Since 0.6.0
Helper utilities
data HostPreference Source
Which host to bind.
Note: The IsString
instance recognizes the following special values:
-
*
meansHostAny
-
*4
meansHostIPv4
-
*6
meansHostIPv6
bindPort :: Int -> HostPreference -> IO SocketSource
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)Source
Attempt to connect to the given host/port.
Since 0.6.0
acceptSafe :: Socket -> IO (Socket, SockAddr)Source
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