streaming-commons-0.1.3.1: Common lower-level functions needed by various streaming data libraries

Safe HaskellNone

Data.Streaming.Network

Contents

Synopsis

Types

data ServerSettings Source

Settings for a TCP server. It takes a port to listen on, and an optional hostname to bind to.

data ClientSettings Source

Settings for a TCP client, specifying how to connect to the server.

data HostPreference Source

Which host to bind.

Note: The IsString instance recognizes the following special values:

  • * means HostAny
  • *4 means HostIPv4
  • !4 means HostIPv4Only
  • *6 means HostIPv6
  • !6 means HostIPv6Only

data Message Source

Representation of a single UDP message

Constructors

Message 

data AppData Source

The data passed to an Application.

data ServerSettingsUnix Source

Settings for a Unix domain sockets server.

data ClientSettingsUnix Source

Settings for a Unix domain sockets client.

data AppDataUnix Source

The data passed to a Unix domain sockets Application.

Smart constructors

serverSettingsTCPSource

Arguments

:: Int

port to bind to

-> HostPreference

host binding preferences

-> ServerSettings 

Smart constructor.

serverSettingsTCPSocket :: Socket -> ServerSettingsSource

Create a server settings that uses an already available listening socket. Any port and host modifications made to this value will be ignored.

Since 0.1.1

clientSettingsTCPSource

Arguments

:: Int

port to connect to

-> ByteString

host to connect to

-> ClientSettings 

Smart constructor.

serverSettingsUDPSource

Arguments

:: Int

port to bind to

-> HostPreference

host binding preferences

-> ServerSettings 

Smart constructor.

clientSettingsUDPSource

Arguments

:: Int

port to connect to

-> ByteString

host to connect to

-> ClientSettings 

Smart constructor.

serverSettingsUnixSource

Arguments

:: FilePath

path to bind to

-> ServerSettingsUnix 

Smart constructor.

clientSettingsUnixSource

Arguments

:: FilePath

path to connect to

-> ClientSettingsUnix 

Smart constructor.

Classes

class HasPort a whereSource

Methods

portLens :: Functor f => (Int -> f Int) -> a -> f aSource

class HasAfterBind a whereSource

Methods

afterBindLens :: Functor f => ((Socket -> IO ()) -> f (Socket -> IO ())) -> a -> f aSource

class HasReadWrite a whereSource

Methods

readLens :: Functor f => (IO ByteString -> f (IO ByteString)) -> a -> f aSource

writeLens :: Functor f => ((ByteString -> IO ()) -> f (ByteString -> IO ())) -> a -> f aSource

Setters

setPort :: HasPort a => Int -> a -> aSource

setAddrFamily :: Family -> ClientSettings -> ClientSettingsSource

Set the address family for the given settings.

Since 0.1.3

setAfterBind :: HasAfterBind a => (Socket -> IO ()) -> a -> aSource

setPath :: HasPath a => FilePath -> a -> aSource

Getters

getAddrFamily :: ClientSettings -> FamilySource

Get the address family for the given settings.

Since 0.1.3

Functions

General

bindPortGen :: SocketType -> Int -> HostPreference -> IO SocketSource

Attempt to bind a listening Socket on the given host/port using given SocketType. If no host is given, will use the first address available.

bindRandomPortGen :: SocketType -> HostPreference -> IO (Int, Socket)Source

Bind to a random port number. Especially useful for writing network tests.

This will attempt 30 different port numbers before giving up and throwing an exception.

Since 0.1.1

getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)Source

Attempt to connect to the given host/port using given SocketType.

getSocketFamilyGen :: SocketType -> String -> Int -> Family -> IO (Socket, AddrInfo)Source

Attempt to connect to the given hostportaddress family using given SocketType.

Since 0.1.3

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.

getUnassignedPort :: IO IntSource

Get a port from the IANA list of unassigned ports.

Internally, this function uses an IORef to cycle through the list of ports

TCP

bindPortTCP :: 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.

bindRandomPortTCP :: HostPreference -> IO (Int, Socket)Source

Bind a random TCP port.

See bindRandomPortGen.

Since 0.1.1

getSocketTCP :: ByteString -> Int -> IO (Socket, SockAddr)Source

Attempt to connect to the given host/port.

getSocketFamilyTCP :: ByteString -> Int -> Family -> IO (Socket, SockAddr)Source

Attempt to connect to the given hostportaddress family.

Since 0.1.3

runTCPServer :: ServerSettings -> (AppData -> IO ()) -> IO ()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.

runTCPClient :: ClientSettings -> (AppData -> IO a) -> IO aSource

Run an Application by connecting to the specified server.

UDP

bindPortUDP :: 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.

bindRandomPortUDP :: HostPreference -> IO (Int, Socket)Source

Bind a random UDP port.

See bindRandomPortGen

Since 0.1.1

getSocketUDP :: String -> Int -> IO (Socket, AddrInfo)Source

Attempt to connect to the given host/port.

Unix

bindPath :: FilePath -> IO SocketSource

Attempt to bind a listening Unix domain socket at the given path.

getSocketUnix :: FilePath -> IO SocketSource

Attempt to connect to the given Unix domain socket path.

runUnixServer :: ServerSettingsUnix -> (AppDataUnix -> IO ()) -> IO ()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.

runUnixClient :: ClientSettingsUnix -> (AppDataUnix -> IO a) -> IO aSource

Run an Application by connecting to the specified server.