-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple network sockets usage patterns. -- -- Simple network sockets usage patterns. @package network-simple @version 0.1.0.1 -- | This module exports functions that abstract simple TCP Socket -- usage patterns. module Network.Simple.TCP -- | Start a TCP server that sequentially accepts and uses each incoming -- connection. -- -- Both the listening and connection sockets are closed when done or in -- case of exceptions. -- -- Note: You don't need to use listen nor accept manually -- if you use this function. serve :: HostPreference -> ServiceName -> ((Socket, SockAddr) -> IO r) -> IO r -- | Start a TCP server that accepts incoming connections and uses them -- concurrently in different threads. -- -- The listening and connection sockets are closed when done or in case -- of exceptions. -- -- Note: You don't need to use listen nor acceptFork -- manually if you use this function. serveFork :: 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 -- | 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 -- | 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