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

Safe HaskellNone

Data.Conduit.Network

Contents

Synopsis

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

data AppData m Source

The data passed to an Application.

Since 0.6.0

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

serverSettingsSource

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 ()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

clientSettingsSource

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 ()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:

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

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.

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