import Control.Concurrent
import Control.Exception
import Control.Monad
+import Data.Maybe
import Network.BSD
import Network.Socket
import Network.HTTP.Lucu.Config
= withSocketsDo $
do _ <- installHandler sigPIPE Ignore Nothing
- -- FIXME: TERRIBLE CODE. NEED MAJOR REWRITE.
- case cnfSSLConfig cnf of
- Nothing
- -> return ()
- Just scnf
- -> do case cnfServerV4Addr cnf of
- Nothing
- -> return ()
- Just v4addr
- -> do so <- listenOn AF_INET v4addr (sslServerPort scnf)
- p <- socketPort so
- -- FIXME: Don't throw away the thread
- -- ID as we can't kill it later
- -- then. [1]
- _ <- forkIO $ httpLoop p (sslContext scnf, so)
- return ()
-
- case cnfServerV6Addr cnf of
- Nothing
- -> return ()
- Just v6addr
- -> do so <- listenOn AF_INET6 v6addr (sslServerPort scnf)
- p <- socketPort so
- -- FIXME: [1]
- _ <- forkIO $ httpLoop p (sslContext scnf, so)
- return ()
-
- case cnfServerV4Addr cnf of
- Nothing
- -> return ()
- Just v4addr
- -> do so <- listenOn AF_INET v4addr (cnfServerPort cnf)
- p <- socketPort so
- -- FIXME: [1]
- _ <- forkIO $ httpLoop p so
- return ()
-
- case cnfServerV6Addr cnf of
- Nothing
- -> return ()
- Just v6addr
- -> do so <- listenOn AF_INET6 v6addr (cnfServerPort cnf)
- p <- socketPort so
- -- FIXME: [1]
- _ <- forkIO $ httpLoop p so
- return ()
+ let launchers
+ = catMaybes
+ [ do scnf <- cnfSSLConfig cnf
+ addr <- cnfServerV4Addr cnf
+ return ( do so <- listenOn AF_INET addr (sslServerPort scnf)
+ launchListener (sslContext scnf, so)
+ )
+ , do scnf <- cnfSSLConfig cnf
+ addr <- cnfServerV6Addr cnf
+ return ( do so <- listenOn AF_INET6 addr (sslServerPort scnf)
+ launchListener (sslContext scnf, so)
+ )
+ , do addr <- cnfServerV4Addr cnf
+ return ( launchListener =<< listenOn AF_INET addr (cnfServerPort cnf)
+ )
+ , do addr <- cnfServerV6Addr cnf
+ return ( launchListener =<< listenOn AF_INET6 addr (cnfServerPort cnf)
+ )
+ ]
+ sequence_ launchers
waitForever
where
+ launchListener :: SocketLike s => s -> IO ()
+ launchListener so
+ = do p <- SL.socketPort so
+ -- FIXME: Don't throw away the thread ID as we can't
+ -- kill it later then. [1]
+ _ <- forkIO $ httpLoop p so
+ return ()
+
listenOn :: Family -> HostName -> ServiceName -> IO Socket
listenOn fam host srv
= do proto <- getProtocolNumber "tcp"
class (HandleLike (Handle s)) => SocketLike s where
type Handle s :: *
- accept :: s -> IO (Handle s, So.SockAddr)
+ accept :: s -> IO (Handle s, So.SockAddr)
+ socketPort :: s -> IO So.PortNumber
instance SocketLike So.Socket where
type Handle So.Socket = I.Handle
+
accept soSelf
= do (soPeer, addr) <- So.accept soSelf
hPeer <- So.socketToHandle soPeer I.ReadWriteMode
return (hPeer, addr)
+ socketPort = So.socketPort
+
instance SocketLike (SSL.SSLContext, So.Socket) where
type Handle (SSL.SSLContext, So.Socket) = SSL.SSL
+
accept (ctx, soSelf)
= do (soPeer, addr) <- So.accept soSelf
ssl <- SSL.connection ctx soPeer
SSL.accept ssl
return (ssl, addr)
+
+ socketPort = So.socketPort . snd
\ No newline at end of file
Thanks
type: :feature
component: Lucu
-release: 0.4.3
+release: "0.5"
reporter: PHO <pho@cielonegro.org>
-status: :unstarted
-disposition:
+status: :closed
+disposition: :fixed
creation_time: 2010-03-02 12:09:26.521388 Z
references: []
- PHO <pho@cielonegro.org>
- assigned to release 0.4.3 from unassigned
- ""
+- - 2010-03-03 16:43:24.865175 Z
+ - PHO <pho@cielonegro.org>
+ - unassigned from release 0.4.3
+ - This change should bump version to 0.5
+- - 2010-03-03 16:46:04.795565 Z
+ - PHO <pho@cielonegro.org>
+ - assigned to release 0.5 from unassigned
+ - ""
+- - 2010-03-03 16:47:55.250708 Z
+ - PHO <pho@cielonegro.org>
+ - closed with disposition fixed
+ - Seems working now.