-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Simple network sockets usage patterns.
--
-- Simple network sockets usage patterns.
--
-- See the NEWS file in the source distribution to learn about
-- any important changes between version.
@package network-simple
@version 0.2.0.0
-- | This module exports functions that abstract simple TCP Socket
-- usage patterns.
module Network.Simple.TCP
-- | Connect to a TCP server and use the connection.
--
-- The connection socket is closed when done or in case of exceptions.
--
-- If you prefer to acquire and close the socket yourself, then use
-- connectSock and the sClose function from
-- Network.Socket instead.
connect :: HostName -> ServiceName -> ((Socket, SockAddr) -> IO r) -> IO r
-- | Start a TCP server that accepts incoming connections and handles them
-- concurrently in different threads.
--
-- Any acquired network resources are properly closed and discarded when
-- done or in case of exceptions.
--
-- Note: This function performs listen and acceptFork, so
-- you don't need to perform those manually.
serve :: HostPreference -> ServiceName -> ((Socket, SockAddr) -> IO ()) -> IO ()
-- | Bind a TCP listening socket and use it.
--
-- The listening socket is closed when done or in case of exceptions.
--
-- If you prefer to acquire and close the socket yourself, then use
-- bindSock and the listen and sClose functions from
-- Network.Socket instead.
--
-- Note: maxListenQueue is tipically 128, which is too small for
-- high performance servers. So, we use the maximum between
-- maxListenQueue and 2048 as the default size of the listening
-- queue. The NoDelay and ReuseAddr options are set on the
-- socket.
listen :: HostPreference -> ServiceName -> ((Socket, SockAddr) -> IO r) -> IO r
-- | Accept a single incoming connection and use it.
--
-- The connection socket is closed when done or in case of exceptions.
accept :: Socket -> ((Socket, SockAddr) -> IO b) -> IO b
-- | Accept a single incoming connection and use it in a different thread.
--
-- The connection socket is closed when done or in case of exceptions.
acceptFork :: Socket -> ((Socket, SockAddr) -> IO ()) -> IO ThreadId
-- | Obtain a Socket bound to the given host name and TCP service
-- port.
--
-- The obtained Socket should be closed manually using
-- sClose when it's not needed anymore.
--
-- Prefer to use listen if you will be listening on this socket
-- and using it within a limited scope, and would like it to be closed
-- immediately after its usage or in case of exceptions.
bindSock :: HostPreference -> ServiceName -> IO (Socket, SockAddr)
-- | Obtain a Socket connected to the given host and TCP service
-- port.
--
-- The obtained Socket should be closed manually using
-- sClose when it's not needed anymore, otherwise you risk having
-- the socket open for much longer than needed.
--
-- Prefer to use connect if you will be using the socket within a
-- limited scope and would like it to be closed immediately after its
-- usage or in case of exceptions.
connectSock :: HostName -> ServiceName -> IO (Socket, SockAddr)
-- | Preferred host to bind.
data HostPreference
-- | Any available host.
HostAny :: HostPreference
-- | Any available IPv4 host.
HostIPv4 :: HostPreference
-- | Any available IPv6 host.
HostIPv6 :: HostPreference
-- | An explicit host name.
Host :: HostName -> HostPreference