equal
deleted
inserted
replaced
3 module Main where |
3 module Main where |
4 |
4 |
5 import Network.Socket |
5 import Network.Socket |
6 import Network.BSD |
6 import Network.BSD |
7 import Control.Concurrent.Chan |
7 import Control.Concurrent.Chan |
8 import qualified Control.Exception as Exception |
8 import qualified Control.Exception as E |
9 import System.Log.Logger |
9 import System.Log.Logger |
10 ----------------------------------- |
10 ----------------------------------- |
11 import Opts |
11 import Opts |
12 import CoreTypes |
12 import CoreTypes |
13 import ServerCore |
13 import ServerCore |
24 setupLoggers :: IO () |
24 setupLoggers :: IO () |
25 setupLoggers = |
25 setupLoggers = |
26 updateGlobalLogger "Clients" |
26 updateGlobalLogger "Clients" |
27 (setLevel INFO) |
27 (setLevel INFO) |
28 |
28 |
|
29 |
|
30 server :: ServerInfo -> IO () |
|
31 server si = do |
|
32 proto <- getProtocolNumber "tcp" |
|
33 E.bracket |
|
34 (socket AF_INET Stream proto) |
|
35 sClose |
|
36 (\sock -> do |
|
37 setSocketOption sock ReuseAddr 1 |
|
38 bindSocket sock (SockAddrInet (listenPort si) iNADDR_ANY) |
|
39 listen sock maxListenQueue |
|
40 startServer si sock |
|
41 ) |
|
42 |
|
43 handleRestart :: ShutdownException -> IO () |
|
44 handleRestart ShutdownException = return () |
|
45 handleRestart RestartException = do |
|
46 |
|
47 return () |
|
48 |
29 main :: IO () |
49 main :: IO () |
30 main = withSocketsDo $ do |
50 main = withSocketsDo $ do |
31 #if !defined(mingw32_HOST_OS) |
51 #if !defined(mingw32_HOST_OS) |
32 _ <- installHandler sigPIPE Ignore Nothing |
52 _ <- installHandler sigPIPE Ignore Nothing |
33 _ <- installHandler sigCHLD Ignore Nothing |
53 _ <- installHandler sigCHLD Ignore Nothing |
41 |
61 |
42 #if defined(OFFICIAL_SERVER) |
62 #if defined(OFFICIAL_SERVER) |
43 dbHost' <- askFromConsole "DB host: " |
63 dbHost' <- askFromConsole "DB host: " |
44 dbLogin' <- askFromConsole "login: " |
64 dbLogin' <- askFromConsole "login: " |
45 dbPassword' <- askFromConsole "password: " |
65 dbPassword' <- askFromConsole "password: " |
46 let serverInfo = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
66 let si = serverInfo'{dbHost = dbHost', dbLogin = dbLogin', dbPassword = dbPassword'} |
47 #else |
67 #else |
48 let serverInfo = serverInfo' |
68 let si = serverInfo' |
49 #endif |
69 #endif |
50 |
70 |
51 |
71 (server si) `E.catch` handleRestart |
52 proto <- getProtocolNumber "tcp" |
|
53 Exception.bracket |
|
54 (socket AF_INET Stream proto) |
|
55 sClose |
|
56 (\sock -> do |
|
57 setSocketOption sock ReuseAddr 1 |
|
58 bindSocket sock (SockAddrInet (listenPort serverInfo) iNADDR_ANY) |
|
59 listen sock maxListenQueue |
|
60 startServer serverInfo sock |
|
61 ) |
|