-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Stream socket data using conduits.
--   
--   Stream socket data using conduits.
@package network-conduit
@version 0.6.1.1

module Data.Conduit.Network.UDP

-- | Representation of a single message
data Message
Message :: {-# UNPACK #-} !ByteString -> !SockAddr -> Message
msgData :: Message -> {-# UNPACK #-} !ByteString
msgSender :: Message -> !SockAddr

-- | Stream messages from the socket.
--   
--   The given <tt>len</tt> defines the maximum packet size. Every produced
--   item contains the message payload and the origin address.
--   
--   This function does <i>not</i> automatically close the socket.
sourceSocket :: MonadIO m => Socket -> Int -> GSource m Message

-- | Stream messages to the connected socket.
--   
--   The payload is sent using <tt>send</tt>, so some of it might be lost.
--   
--   This function does <i>not</i> automatically close the socket.
sinkSocket :: MonadIO m => Socket -> GInfSink ByteString m

-- | Stream messages to the connected socket.
--   
--   The payload is sent using <tt>sendAll</tt>, so it might end up in
--   multiple packets.
--   
--   This function does <i>not</i> automatically close the socket.
sinkAllSocket :: MonadIO m => Socket -> GInfSink ByteString m

-- | Stream messages to the socket.
--   
--   Every handled item contains the message payload and the destination
--   address. The payload is sent using <tt>sendTo</tt>, so some of it
--   might be lost.
--   
--   This function does <i>not</i> automatically close the socket.
sinkToSocket :: MonadIO m => Socket -> GInfSink Message m

-- | Stream messages to the socket.
--   
--   Every handled item contains the message payload and the destination
--   address. The payload is sent using <tt>sendAllTo</tt>, so it might end
--   up in multiple packets.
--   
--   This function does <i>not</i> automatically close the socket.
sinkAllToSocket :: MonadIO m => Socket -> GInfSink Message m

-- | Which host to bind.
--   
--   Note: The <tt>IsString</tt> instance recognizes the following special
--   values:
--   
--   <ul>
--   <li><tt>*</tt> means <tt>HostAny</tt></li>
--   <li><tt>*4</tt> means <tt>HostIPv4</tt></li>
--   <li><tt>*6</tt> means <tt>HostIPv6</tt></li>
--   </ul>
data HostPreference
HostAny :: HostPreference
HostIPv4 :: HostPreference
HostIPv6 :: HostPreference
Host :: String -> HostPreference

-- | Attempt to bind a listening <tt>Socket</tt> on the given host/port. If
--   no host is given, will use the first address available.
bindPort :: Int -> HostPreference -> IO Socket

-- | Attempt to connect to the given host/port.
getSocket :: String -> Int -> IO (Socket, AddrInfo)

module Data.Conduit.Network.Internal

-- | The data passed to an <tt>Application</tt>.
--   
--   Since 0.6.0
data AppData m
AppData :: Source m ByteString -> Sink ByteString m () -> SockAddr -> Maybe SockAddr -> AppData m
appSource :: AppData m -> Source m ByteString
appSink :: AppData m -> Sink ByteString m ()
appSockAddr :: AppData m -> SockAddr
appLocalAddr :: AppData m -> Maybe SockAddr

-- | Settings for a TCP server. It takes a port to listen on, and an
--   optional hostname to bind to.
--   
--   Since 0.6.0
data ServerSettings m
ServerSettings :: Int -> HostPreference -> (Socket -> m ()) -> Bool -> ServerSettings m
serverPort :: ServerSettings m -> Int
serverHost :: ServerSettings m -> HostPreference
serverAfterBind :: ServerSettings m -> Socket -> m ()
serverNeedLocalAddr :: ServerSettings m -> Bool

-- | Settings for a TCP client, specifying how to connect to the server.
--   
--   Since 0.6.0
data ClientSettings (m :: * -> *)
ClientSettings :: Int -> ByteString -> ClientSettings
clientPort :: ClientSettings -> Int
clientHost :: ClientSettings -> ByteString

module Data.Conduit.Network

-- | Stream data from the socket.
--   
--   This function does <i>not</i> automatically close the socket.
--   
--   Since 0.0.0
sourceSocket :: MonadIO m => Socket -> GSource m ByteString

-- | Stream data to the socket.
--   
--   This function does <i>not</i> automatically close the socket.
--   
--   Since 0.0.0
sinkSocket :: MonadIO m => Socket -> GInfSink ByteString m

-- | A simple TCP application.
--   
--   Since 0.6.0
type Application m = AppData m -> m ()

-- | The data passed to an <tt>Application</tt>.
--   
--   Since 0.6.0
data AppData m
appSource :: AppData m -> Source m ByteString
appSink :: AppData m -> Sink ByteString m ()
appSockAddr :: AppData m -> SockAddr
appLocalAddr :: AppData m -> Maybe SockAddr

-- | Settings for a TCP server. It takes a port to listen on, and an
--   optional hostname to bind to.
--   
--   Since 0.6.0
data ServerSettings m

-- | Smart constructor.
--   
--   Since 0.6.0
serverSettings :: Monad m => Int -> HostPreference -> ServerSettings m
serverPort :: ServerSettings m -> Int
serverHost :: ServerSettings m -> HostPreference
serverAfterBind :: ServerSettings m -> Socket -> m ()
serverNeedLocalAddr :: ServerSettings m -> Bool

-- | Run an <tt>Application</tt> 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
runTCPServer :: (MonadIO m, MonadBaseControl IO m) => ServerSettings m -> Application m -> m ()

-- | Settings for a TCP client, specifying how to connect to the server.
--   
--   Since 0.6.0
data ClientSettings (m :: * -> *)

-- | Smart constructor.
--   
--   Since 0.6.0
clientSettings :: Monad m => Int -> ByteString -> ClientSettings m
clientPort :: ClientSettings m -> Int
clientHost :: ClientSettings m -> ByteString

-- | Run an <tt>Application</tt> by connecting to the specified server.
--   
--   Since 0.6.0
runTCPClient :: (MonadIO m, MonadBaseControl IO m) => ClientSettings m -> Application m -> m ()

-- | Which host to bind.
--   
--   Note: The <tt>IsString</tt> instance recognizes the following special
--   values:
--   
--   <ul>
--   <li><tt>*</tt> means <tt>HostAny</tt></li>
--   <li><tt>*4</tt> means <tt>HostIPv4</tt></li>
--   <li><tt>*6</tt> means <tt>HostIPv6</tt></li>
--   </ul>
data HostPreference
HostAny :: HostPreference
HostIPv4 :: HostPreference
HostIPv6 :: HostPreference
Host :: String -> HostPreference

-- | Attempt to bind a listening <tt>Socket</tt> on the given host/port. If
--   no host is given, will use the first address available.
--   <tt>maxListenQueue</tt> is topically 128 which is too short for high
--   performance servers. So, we specify 'max 2048 maxListenQueue' to the
--   listen queue.
--   
--   Since 0.3.0
bindPort :: Int -> HostPreference -> IO Socket

-- | Attempt to connect to the given host/port.
--   
--   Since 0.6.0
getSocket :: ByteString -> Int -> IO (Socket, SockAddr)

-- | Try to accept a connection, recovering automatically from exceptions.
--   
--   As reported by Kazu against Warp, <a>resource exhausted (Too many open
--   files)</a> may be thrown by accept(). This function will catch that
--   exception, wait a second, and then try again.
--   
--   Since 0.6.0
acceptSafe :: Socket -> IO (Socket, SockAddr)
