diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2016-06-07 03:57:26 +0800 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2016-06-07 03:57:26 +0800 |
commit | 50fbf638a92b0dfc85b9000bc026911f798dede8 (patch) | |
tree | cd43ee31ba9e2558e305ae3b2ed692653d4580c5 | |
parent | cd428a60b178aa621ac26e47a7d404af596eecd1 (diff) | |
download | juandelacosa-50fbf638a92b0dfc85b9000bc026911f798dede8.tar.gz |
Reuse TCP port
-rw-r--r-- | src/Server.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Server.hs b/src/Server.hs index 3ecb642..ee9aad2 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -7,15 +7,15 @@ import Control.Exception.Base (throwIO, catch, bracket) import Data.Bits ((.|.)) import Data.Pool (createPool, destroyAllResources) import Database.MySQL.Base (ConnectInfo) -import Network.Socket (socket, bind, listen, close, maxListenQueue, - getSocketName, inet_addr, - Family(AF_UNIX, AF_INET), SocketType(Stream), - Socket, SockAddr(SockAddrUnix, SockAddrInet)) +import Network.Socket (socket, setSocketOption, bind, listen, close, + maxListenQueue, getSocketName, inet_addr, Family(AF_UNIX, AF_INET), + SocketType(Stream), SocketOption(ReuseAddr), Socket, SockAddr(SockAddrUnix, + SockAddrInet)) import Network.Wai.Handler.Warp (Port, defaultSettings, runSettingsSocket) import System.IO (hPutStrLn, stderr) import System.IO.Error (isDoesNotExistError) -import System.Posix.Files (removeLink, setFileMode, socketMode, - ownerReadMode, ownerWriteMode, groupReadMode, groupWriteMode) +import System.Posix.Files (removeLink, setFileMode, socketMode, ownerReadMode, + ownerWriteMode, groupReadMode, groupWriteMode) import qualified Database.MySQL.Simple as MySQL import Application (app) @@ -55,6 +55,7 @@ createSocket (Right path) = do return sock createSocket (Left port) = do sock <- socket AF_INET Stream 0 + setSocketOption sock ReuseAddr 1 addr <- inet_addr "127.0.0.1" bind sock $ SockAddrInet (fromIntegral port) addr hPutStrLn stderr $ "Listening on localhost:" ++ show port |