gameServer/hedgewars-server.hs
changeset 4960 3b54b1c9b768
parent 4957 3684faf5b3d1
child 4962 705c6186ad9d
--- a/gameServer/hedgewars-server.hs	Thu Feb 24 22:01:36 2011 +0300
+++ b/gameServer/hedgewars-server.hs	Sun Feb 27 19:32:14 2011 +0300
@@ -5,7 +5,7 @@
 import Network.Socket
 import Network.BSD
 import Control.Concurrent.Chan
-import qualified Control.Exception as Exception
+import qualified Control.Exception as E
 import System.Log.Logger
 -----------------------------------
 import Opts
@@ -26,6 +26,26 @@
     updateGlobalLogger "Clients"
         (setLevel INFO)
 
+
+server :: ServerInfo -> IO ()
+server si = do
+    proto <- getProtocolNumber "tcp"
+    E.bracket
+        (socket AF_INET Stream proto)
+        sClose
+        (\sock -> do
+            setSocketOption sock ReuseAddr 1
+            bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY)
+            listen sock maxListenQueue
+            startServer si sock
+        )
+
+handleRestart :: ShutdownException -> IO ()
+handleRestart ShutdownException = return ()
+handleRestart RestartException = do
+    
+    return ()
+
 main :: IO ()
 main = withSocketsDo $ do
 #if !defined(mingw32_HOST_OS)
@@ -43,19 +63,9 @@
     dbHost' <- askFromConsole "DB host: "
     dbLogin' <- askFromConsole "login: "
     dbPassword' <- askFromConsole "password: "
-    let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'}
+    let si = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'}
 #else
-    let serverInfo = serverInfo'
+    let si = serverInfo'
 #endif
 
-
-    proto <- getProtocolNumber "tcp"
-    Exception.bracket
-        (socket AF_INET Stream proto)
-        sClose
-        (\sock -> do
-            setSocketOption sock ReuseAddr 1
-            bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY)
-            listen sock maxListenQueue
-            startServer serverInfo sock
-        )
+    (server si) `E.catch` handleRestart