network-run-0.4.4: Simple network runner library

Safe Haskell | None
Language | Haskell2010

Network.Run.TCP

Contents

- Server
- Client

Description

Simple functions to run TCP clients and servers.

Synopsis

- runTCPServer :: Maybe HostName -> ServiceName -> (Socket -> IO a) -> IO a
- runTCPServerWithSocket :: Socket -> (Socket -> IO a) -> IO a
- openTCPServerSocket :: AddrInfo -> IO Socket
- openTCPServerSocketWithOptions :: [(SocketOption, Int)] -> AddrInfo -> IO Socket
- openTCPServerSocketWithOpts :: [(SocketOption, SockOptValue)] -> AddrInfo -> IO Socket
- resolve :: SocketType -> Maybe HostName -> ServiceName -> [AddrInfoFlag] -> (NonEmpty AddrInfo -> AddrInfo) -> IO AddrInfo
- runTCPClient :: HostName -> ServiceName -> (Socket -> IO a) -> IO a
- data Settings
- defaultSettings :: Settings
- settingsOpenClientSocket :: Settings -> AddrInfo -> IO Socket
- settingsSelectAddrInfo :: Settings -> NonEmpty AddrInfo -> AddrInfo
- runTCPClientWithSettings :: Settings -> HostName -> ServiceName -> (Socket -> IO a) -> IO a
- openClientSocket :: AddrInfo -> IO Socket
- openClientSocketWithOptions :: [(SocketOption, Int)] -> AddrInfo -> IO Socket
- openClientSocketWithOpts :: [(SocketOption, SockOptValue)] -> AddrInfo -> IO Socket

# Server

runTCPServer :: Maybe HostName -> ServiceName -> (Socket -> IO a) -> IO a Source #

Running a TCP server with an accepted socket and its peer name.

runTCPServerWithSocket Source #

Arguments

:: Socket |
-> (Socket -> IO a) | Called for each incoming connection, in a new thread
-> IO a |

Running a TCP client with a connected socket for a given listen socket.

openTCPServerSocket :: AddrInfo -> IO Socket Source #

Open TCP socket for server use

This is the same as:

    openTCPServerSocketWithOptions []

openTCPServerSocketWithOptions :: [(SocketOption, Int)] -> AddrInfo -> IO Socket Source #

Open socket for server use, and set the provided options before binding.

This is equivalent to

    openTCPServerSocketWithOpts . map (second SockOptValue)

openTCPServerSocketWithOpts :: [(SocketOption, SockOptValue)] -> AddrInfo -> IO Socket Source #

Open socket for server use, and set the provided options before binding.

In addition to the given options, the socket is configured to

- allow reuse of local addresses (SO_REUSEADDR)
- automatically be closed during a successful `execve` (FD_CLOEXEC)
- bind to the address specified
- listen with queue length with 1024

resolve :: SocketType -> Maybe HostName -> ServiceName -> [AddrInfoFlag] -> (NonEmpty AddrInfo -> AddrInfo) -> IO AddrInfo Source #

# Client

runTCPClient :: HostName -> ServiceName -> (Socket -> IO a) -> IO a Source #

Running a TCP client with a connected socket.

This is the same as:

    runTCPClientWithSettings defaultSettings

data Settings Source #

Settings for client.

defaultSettings :: Settings Source #

Default settings.

settingsOpenClientSocket :: Settings -> AddrInfo -> IO Socket Source #

Opening a socket. Use `openClientSocketWithOptions` to specify `SocketOption`

settingsSelectAddrInfo :: Settings -> NonEmpty AddrInfo -> AddrInfo Source #

Selecting `AddrInfo`.

runTCPClientWithSettings :: Settings -> HostName -> ServiceName -> (Socket -> IO a) -> IO a Source #

Running a TCP client with a connected socket.

openClientSocket :: AddrInfo -> IO Socket Source #

This is the same as

    openClientSocketWithOptions []

openClientSocketWithOptions :: [(SocketOption, Int)] -> AddrInfo -> IO Socket Source #

Open a client socket with the given options

The options are set before `connect`. This is equivalent to

    openClientSocketWithOpts . map (second SockOptValue)

openClientSocketWithOpts :: [(SocketOption, SockOptValue)] -> AddrInfo -> IO Socket Source #

Open a client socket with the given options

This must be used rather than `openClientSocketWithOptions` for options such as `Linger` which require a composite value (`StructLinger`).

The options are set before `connect`.