author | nemo |
Tue, 12 Mar 2013 22:20:42 -0400 | |
changeset 8728 | d2f6262452a3 |
parent 6805 | 097289be7200 |
child 10460 | 8dcea9087d75 |
permissions | -rw-r--r-- |
1804 | 1 |
{-# LANGUAGE CPP #-} |
2 |
||
3 |
module Main where |
|
4 |
||
5 |
import System.IO |
|
4932 | 6 |
import System.IO.Error |
1804 | 7 |
import Control.Concurrent |
8 |
import Network |
|
4905 | 9 |
import Control.OldException |
1804 | 10 |
import Control.Monad |
11 |
import System.Random |
|
12 |
||
13 |
#if !defined(mingw32_HOST_OS) |
|
14 |
import System.Posix |
|
15 |
#endif |
|
16 |
||
6805
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
17 |
session 0 nick room = ["NICK", nick, "", "PROTO", "42", "", "PING", "", "CHAT", "lobby 1", "", "PONG", "", "CREATE_ROOM", room, "", "CHAT", "room 1", "", "QUIT", "creator", ""] |
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
18 |
session 1 nick room = ["NICK", nick, "", "PROTO", "42", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "part-quit", ""] |
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
19 |
session 2 nick room = ["NICK", nick, "", "PROTO", "42", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "QUIT", "quit", ""] |
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
20 |
session 3 nick room = ["NICK", nick, "", "PROTO", "42", "", "CHAT", "lobby 1", "", "CREATE_ROOM", room, "", "", "PONG", "CHAT", "room 1", "", "PART", "creator", "", "QUIT", "part-quit", ""] |
1804 | 21 |
|
22 |
emulateSession sock s = do |
|
5119 | 23 |
mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (100000::Int, 600000) >>= threadDelay) s |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
24 |
hFlush sock |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
25 |
threadDelay 225000 |
1804 | 26 |
|
4905 | 27 |
testing = Control.OldException.handle print $ do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
28 |
putStrLn "Start" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
29 |
sock <- connectTo "127.0.0.1" (PortNumber 46631) |
1804 | 30 |
|
5119 | 31 |
num1 <- randomRIO (100000::Int, 101000) |
32 |
num2 <- randomRIO (0::Int, 3) |
|
33 |
num3 <- randomRIO (0::Int, 1000) |
|
4905 | 34 |
let nick1 = 'n' : show num1 |
5119 | 35 |
let room1 = 'r' : show num3 |
36 |
emulateSession sock $ session num2 nick1 room1 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
37 |
hClose sock |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
38 |
putStrLn "Finish" |
1804 | 39 |
|
40 |
forks = forever $ do |
|
5119 | 41 |
delays <- randomRIO (0::Int, 2) |
42 |
replicateM 200 $ |
|
43 |
do |
|
44 |
delay <- randomRIO (delays * 20000::Int, delays * 20000 + 50000) |
|
45 |
threadDelay delay |
|
46 |
forkIO testing |
|
1804 | 47 |
|
48 |
main = withSocketsDo $ do |
|
49 |
#if !defined(mingw32_HOST_OS) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
50 |
installHandler sigPIPE Ignore Nothing; |
1804 | 51 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
52 |
forks |