1 {-# LANGUAGE CPP, PatternSignatures #-} |
1 {-# LANGUAGE ScopedTypeVariables #-} |
2 module NetRoutines where |
2 module NetRoutines where |
3 |
3 |
4 import Network |
4 import Network |
5 import Network.Socket |
5 import Network.Socket |
6 import System.IO |
6 import System.IO |
7 import Control.Concurrent |
7 import Control.Concurrent |
8 import Control.Concurrent.Chan |
8 import Control.Concurrent.Chan |
9 import Control.Concurrent.STM |
9 import Control.Concurrent.STM |
10 #if defined(NEW_EXCEPTIONS) |
|
11 import qualified Control.OldException as Exception |
|
12 #else |
|
13 import qualified Control.Exception as Exception |
10 import qualified Control.Exception as Exception |
14 #endif |
|
15 import Data.Time |
11 import Data.Time |
16 ----------------------------- |
12 ----------------------------- |
17 import CoreTypes |
13 import CoreTypes |
18 import ClientIO |
14 import ClientIO |
19 import Utils |
15 import Utils |
20 |
16 |
21 acceptLoop :: Socket -> Chan CoreMessage -> Int -> IO () |
17 acceptLoop :: Socket -> Chan CoreMessage -> Int -> IO () |
22 acceptLoop servSock coreChan clientCounter = do |
18 acceptLoop servSock coreChan clientCounter = do |
23 Exception.handle |
19 Exception.handle |
24 (\(_ :: Exception.Exception) -> putStrLn "exception on connect") $ |
20 (\(_ :: Exception.IOException) -> putStrLn "exception on connect") $ |
25 do |
21 do |
26 (socket, sockAddr) <- Network.Socket.accept servSock |
22 (socket, sockAddr) <- Network.Socket.accept servSock |
27 |
23 |
28 cHandle <- socketToHandle socket ReadWriteMode |
24 cHandle <- socketToHandle socket ReadWriteMode |
29 hSetBuffering cHandle LineBuffering |
25 hSetBuffering cHandle LineBuffering |