author | smxx |
Fri, 04 Jun 2010 20:50:24 +0000 | |
changeset 3494 | 208c5671b202 |
parent 3435 | 4e4f88a7bdf2 |
child 3500 | af8390d807d6 |
permissions | -rw-r--r-- |
2348 | 1 |
{-# LANGUAGE ScopedTypeVariables #-} |
1804 | 2 |
module NetRoutines where |
3 |
||
4 |
import Network.Socket |
|
5 |
import System.IO |
|
6 |
import Control.Concurrent.Chan |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
7 |
import qualified Control.Exception as Exception |
1804 | 8 |
import Data.Time |
3435 | 9 |
import Control.Monad |
1804 | 10 |
----------------------------- |
11 |
import CoreTypes |
|
1917 | 12 |
import Utils |
1804 | 13 |
|
3435 | 14 |
acceptLoop :: Socket -> Chan CoreMessage -> IO () |
15 |
acceptLoop servSock chan = forever $ do |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
16 |
Exception.handle |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
17 |
(\(_ :: Exception.IOException) -> putStrLn "exception on connect") $ |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
18 |
do |
3435 | 19 |
(sock, sockAddr) <- Network.Socket.accept servSock |
1804 | 20 |
|
3435 | 21 |
cHandle <- socketToHandle sock ReadWriteMode |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
22 |
hSetBuffering cHandle LineBuffering |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
23 |
clientHost <- sockAddr2String sockAddr |
1804 | 24 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
25 |
currentTime <- getCurrentTime |
3425 | 26 |
|
3435 | 27 |
sendChan' <- newChan |
1804 | 28 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
29 |
let newClient = |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
30 |
(ClientInfo |
3435 | 31 |
sendChan' |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
32 |
cHandle |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
33 |
clientHost |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
34 |
currentTime |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
35 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
36 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
37 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
38 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
39 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
40 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
41 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
42 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
43 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
44 |
undefined |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
45 |
undefined |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
46 |
) |
1804 | 47 |
|
3435 | 48 |
writeChan chan $ Accept newClient |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
49 |
return () |