( SocketLike(..)
)
where
+#if defined(HAVE_SSL)
+import Control.Exception
+#endif
import qualified Network.Socket as So
import Network.HTTP.Lucu.HandleLike
#if defined(HAVE_SSL)
import qualified OpenSSL.Session as SSL
+import Prelude hiding (catch)
import Prelude.Unicode
#endif
import qualified System.IO as I
accept (ctx, soSelf)
= do (soPeer, addr) ← So.accept soSelf
ssl ← SSL.connection ctx soPeer
- SSL.accept ssl
- return (ssl, addr)
+ handshake ssl addr `catch` next ssl addr
+ where
+ handshake ∷ SSL.SSL → So.SockAddr → IO (SSL.SSL, So.SockAddr)
+ handshake ssl addr
+ = do SSL.accept ssl
+ return (ssl, addr)
+
+ next ∷ SSL.SSL
+ → So.SockAddr
+ → SSL.SomeSSLException
+ → IO (SSL.SSL, So.SockAddr)
+ next ssl addr e
+ = do I.hPutStrLn I.stderr
+ $ "Lucu: failed to accept an SSL connection from "
+ ⧺ show addr
+ ⧺ ":"
+ I.hPutStrLn I.stderr
+ $ show e
+ SSL.shutdown ssl SSL.Bidirectional
+ accept (ctx, soSelf)
socketPort = So.socketPort ∘ snd
#endif