Skip to content

Commit

Permalink
better socket handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zachary822 committed Nov 16, 2023
1 parent b387e84 commit 6975219
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ mdToHtml s =
readMarkdown def{readerExtensions = extensionsFromList [Ext_backtick_code_blocks]} s
>>= writeHtml5 def

data SocketConfig = TCPSocketConfig | UnixSocketConfig String

scottySocket' :: SocketConfig -> Options -> ScottyM () -> IO ()
scottySocket' sconf opts app = case sconf of
TCPSocketConfig -> do
scottySocket' :: Maybe String -> Options -> ScottyM () -> IO ()
scottySocket' mpath opts app = case mpath of
Nothing -> do
scottyOpts opts app
UnixSocketConfig p -> do
Just p -> do
let cleanup sock = do
S.close sock
removeFile p

bracketOnError (socket AF_UNIX Stream 0) cleanup $ \sock -> do
bind sock $ SockAddrUnix p
listen sock maxListenQueue
Expand All @@ -101,14 +100,12 @@ main = do

let opts =
defaultOptions
{ verbose = 1
, settings =
{ settings =
setHost (fromString webHost) . setPort (read webPort) $
settings defaultOptions
}
sconf = maybe TCPSocketConfig UnixSocketConfig socketPath

scottySocket' sconf opts $ do
scottySocket' socketPath opts $ do
middleware $
if debug
then logStdoutDev
Expand Down

0 comments on commit 6975219

Please sign in to comment.