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


-- | A very quick-and-dirty WebSocket server.
--   
--   A very quick-and-dirty WebSocket server. Intended for use with unit
--   tests.
@package skews
@version 0.1.0.2

module Network.WebSockets.Skews

-- | The Server object. You can easily configure the behavior (how the
--   server responds with some requests) after creating by <a>start</a>
--   function.
data Server
data Args
Args :: String -> Int -> Args
[host] :: Args -> String
[portNumber] :: Args -> Int

-- | Used to configure the server's behavior when receiving
--   <a>DataMessage</a> as a <a>ByteString</a>. If returns
--   <tt>Nothing</tt>, the server does nothing.
type RequestHandler = ByteString -> IO (Maybe ByteString)

-- | Start the server by the given hostname and port number as <a>Args</a>
--   object.
start :: Args -> IO Server

-- | Close all connections, forget recently received requests, and delete
--   any configured <a>RequestHandler</a>s.
reinit :: Server -> IO ()

-- | Call <a>killThread</a> to stop the server.
threadId :: Server -> ThreadId

-- | Configure the request handler called when the server receives next.
--   <a>RequestHandler</a>s configured with this function and other
--   non-<tt>Default</tt> functions are "dequeued". So the server responds
--   with the request handler only once.
--   
--   If you need the server to respond always with the same response, use
--   <a>setDefaultResponse</a> and <a>setDefaultRequestHandler</a>.
enqueRequestHandler :: Server -> RequestHandler -> IO ()

-- | Configure the response called when the server receives next.
enqueResponse :: Server -> ByteString -> IO ()

-- | Reset the request handler queue.
replaceRequestHandlers :: Server -> [RequestHandler] -> IO ()

-- | Configure the request handler called when no request handlers are
--   queued.
setDefaultRequestHandler :: Server -> RequestHandler -> IO ()

-- | Configure the response called when no request handlers are queued.
setDefaultResponse :: Server -> ByteString -> IO ()

-- | Maybe often used <a>RequestHandler</a>. Always respond with the given
--   <a>Message</a>.
respondWith :: ByteString -> RequestHandler

-- | Maybe often used <a>RequestHandler</a>. Do nothing.
doNothing :: RequestHandler

-- | Send the given <tt>Message</tt> immediately to the all connected
--   clients.
sendToClients :: Server -> ByteString -> IO ()

-- | Delete the default request handler. After calling this function, the
--   <a>Server</a> object doesn't respond to any message if the request
--   handler queue is empty.
forgetDefaultRequestHandler :: Server -> IO ()

-- | Alias for <a>forgetDefaultRequestHandler</a>
forgetDefaultResponse :: Server -> IO ()

-- | Forget recently received requests.
forgetReceivedRequests :: Server -> IO ()
listeningPort :: Server -> Int
listeningHost :: Server -> String

-- | Retrieve any messages sent by the clients.
recentlyReceived :: Server -> IO (Deque ByteString)

-- | For debugging
countConnectedClients :: Server -> IO Int
