From 4338fe15d68e11e3c7fd0f9862f818864adc1d45 Mon Sep 17 00:00:00 2001 From: Dima Kurilo Date: Tue, 1 Oct 2019 14:23:11 -0400 Subject: [PATCH 1/2] fix deprecations from Network.Socket. Now it's impossible to build snap-server with network-3.0.0 and 3.1.1 and with --force-reinstalls --- src/Snap/Internal/Http/Server/Socket.hs | 18 +++++++++++------- src/Snap/Internal/Http/Server/TLS.hs | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Snap/Internal/Http/Server/Socket.hs b/src/Snap/Internal/Http/Server/Socket.hs index 42b962ae..c3c115ac 100644 --- a/src/Snap/Internal/Http/Server/Socket.hs +++ b/src/Snap/Internal/Http/Server/Socket.hs @@ -21,7 +21,11 @@ import Data.ByteString.Char8 (ByteString) import Network.Socket (Socket, SocketOption (NoDelay, ReuseAddr), accept, close, getSocketName, setSocketOption, socket) import qualified Network.Socket as N #ifdef HAS_SENDFILE +#if MIN_VERSION_network(3,1,1) +import Network.Socket.Types (unsafeFdSocket) +#else import Network.Socket (fdSocket) +#endif import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, openFd) import System.Posix.Types (Fd (..)) import System.SendFile (sendFile, sendHeaders) @@ -174,16 +178,16 @@ sendFileFunc :: Socket -> SendFileHandler sendFileFunc sock !_ builder fPath offset nbytes = bracket acquire closeFd go where acquire = openFd fPath ReadOnly Nothing defaultFileFlags -#if MIN_VERSION_network(3,0,0) - go fileFd = do sockFd <- Fd `fmap` fdSocket sock - sendHeaders builder sockFd - sendFile sockFd fileFd offset nbytes + go fileFd = do +#if MIN_VERSION_network(3,1,1) + sockFd <- Fd `fmap` unsafeFdSocket sock +#elif MIN_VERSION_network(3,0,0) + sockFd <- Fd `fmap` fdSocket sock #else - go fileFd = do let sockFd = Fd $ fdSocket sock + let sockFd = Fd $ fdSocket sock +#endif sendHeaders builder sockFd sendFile sockFd fileFd offset nbytes -#endif - #else sendFileFunc sock buffer builder fPath offset nbytes = Streams.unsafeWithFileAsInputStartingAt (fromIntegral offset) fPath $ diff --git a/src/Snap/Internal/Http/Server/TLS.hs b/src/Snap/Internal/Http/Server/TLS.hs index 551966f5..bedae57a 100644 --- a/src/Snap/Internal/Http/Server/TLS.hs +++ b/src/Snap/Internal/Http/Server/TLS.hs @@ -105,7 +105,11 @@ bindHttps bindAddress bindPort cert chainCert key = (Socket.close . fst) $ \(sock, addr) -> do Socket.setSocketOption sock Socket.ReuseAddr 1 +#if MIN_VERSION_network(2,7,0) + Socket.bind sock addr +#else Socket.bindSocket sock addr +#endif Socket.listen sock 150 ctx <- SSL.context From 410de2df123b1d56b3093720e9c6a1ad79fe9de6 Mon Sep 17 00:00:00 2001 From: Dima Kurilo Date: Tue, 1 Oct 2019 16:17:09 -0400 Subject: [PATCH 2/2] remove unsafeFdSocket, fdSocket should work and maybe it's better to replace fdSocket with withFdSocket --- src/Snap/Internal/Http/Server/Socket.hs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Snap/Internal/Http/Server/Socket.hs b/src/Snap/Internal/Http/Server/Socket.hs index c3c115ac..b1964fe7 100644 --- a/src/Snap/Internal/Http/Server/Socket.hs +++ b/src/Snap/Internal/Http/Server/Socket.hs @@ -21,11 +21,7 @@ import Data.ByteString.Char8 (ByteString) import Network.Socket (Socket, SocketOption (NoDelay, ReuseAddr), accept, close, getSocketName, setSocketOption, socket) import qualified Network.Socket as N #ifdef HAS_SENDFILE -#if MIN_VERSION_network(3,1,1) -import Network.Socket.Types (unsafeFdSocket) -#else import Network.Socket (fdSocket) -#endif import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, openFd) import System.Posix.Types (Fd (..)) import System.SendFile (sendFile, sendHeaders) @@ -179,9 +175,7 @@ sendFileFunc sock !_ builder fPath offset nbytes = bracket acquire closeFd go where acquire = openFd fPath ReadOnly Nothing defaultFileFlags go fileFd = do -#if MIN_VERSION_network(3,1,1) - sockFd <- Fd `fmap` unsafeFdSocket sock -#elif MIN_VERSION_network(3,0,0) +#if MIN_VERSION_network(3,0,0) sockFd <- Fd `fmap` fdSocket sock #else let sockFd = Fd $ fdSocket sock