X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FSocketLike.hs;h=580ee529fdd139d2726a5a5d79435e713b252a3f;hp=998e4490761bfb6324f6d5bb03a47073ec5c25c4;hb=b495d6b8b7647b719eceef2f3e50d5bf87c430cf;hpb=bb121f1189d01b5089aa5c29f0d390fad36ade48 diff --git a/Network/HTTP/Lucu/SocketLike.hs b/Network/HTTP/Lucu/SocketLike.hs index 998e449..580ee52 100644 --- a/Network/HTTP/Lucu/SocketLike.hs +++ b/Network/HTTP/Lucu/SocketLike.hs @@ -10,10 +10,14 @@ module Network.HTTP.Lucu.SocketLike ( 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 @@ -40,8 +44,26 @@ instance SocketLike (SSL.SSLContext, So.Socket) where 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