network-conduit-1.0.0: Stream socket data using conduits.

Safe HaskellNone

Data.Conduit.Network

Contents

Synopsis

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

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

serverSettings

Arguments

:: Monad m 
=> Int

port to bind to

-> HostPreference

host binding preferences

-> ServerSettings m 

Smart constructor.

Since 0.6.0

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

clientSettings

Arguments

:: Monad m 
=> Int

port to connect to

-> ByteString

host to connect to

-> ClientSettings m 

Smart constructor.

Since 0.6.0

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:

  • * means HostAny
  • *4 means HostIPv4
  • *6 means HostIPv6

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