12 |
12 |
13 #if !defined(mingw32_HOST_OS) |
13 #if !defined(mingw32_HOST_OS) |
14 import System.Posix |
14 import System.Posix |
15 #endif |
15 #endif |
16 |
16 |
17 session1 nick room = ["NICK", nick, "", "PROTO", "32", "", "PING", "", "CHAT", "lobby 1", "", "CREATE_ROOM", room, "", "CHAT", "room 1", "", "QUIT", "creator", ""] |
17 session 0 nick room = ["NICK", nick, "", "PROTO", "38", "", "PING", "", "CHAT", "lobby 1", "", "PONG", "", "CREATE_ROOM", room, "", "CHAT", "room 1", "", "QUIT", "creator", ""] |
18 session2 nick room = ["NICK", nick, "", "PROTO", "32", "", "LIST", "", "JOIN_ROOM", room, "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "part-quit", ""] |
18 session 1 nick room = ["NICK", nick, "", "PROTO", "38", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "part-quit", ""] |
19 session3 nick room = ["NICK", nick, "", "PROTO", "32", "", "LIST", "", "JOIN_ROON", room, "", "CHAT", "room 2", "", "QUIT", "quit", ""] |
19 session 2 nick room = ["NICK", nick, "", "PROTO", "38", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "QUIT", "quit", ""] |
|
20 session 3 nick room = ["NICK", nick, "", "PROTO", "38", "", "CHAT", "lobby 1", "", "CREATE_ROOM", room, "", "", "PONG", "CHAT", "room 1", "", "PART", "creator", "", "QUIT", "part-quit", ""] |
20 |
21 |
21 emulateSession sock s = do |
22 emulateSession sock s = do |
22 mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (1000000::Int, 3000000) >>= threadDelay) s |
23 mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (100000::Int, 600000) >>= threadDelay) s |
23 hFlush sock |
24 hFlush sock |
24 threadDelay 225000 |
25 threadDelay 225000 |
25 |
26 |
26 testing = Control.OldException.handle print $ do |
27 testing = Control.OldException.handle print $ do |
27 putStrLn "Start" |
28 putStrLn "Start" |
28 sock <- connectTo "127.0.0.1" (PortNumber 46631) |
29 sock <- connectTo "127.0.0.1" (PortNumber 46631) |
29 |
30 |
30 num1 <- randomRIO (70000::Int, 70100) |
31 num1 <- randomRIO (100000::Int, 101000) |
31 num2 <- randomRIO (0::Int, 2) |
32 num2 <- randomRIO (0::Int, 3) |
32 num3 <- randomRIO (0::Int, 5) |
33 num3 <- randomRIO (0::Int, 1000) |
33 let nick1 = 'n' : show num1 |
34 let nick1 = 'n' : show num1 |
34 let room1 = 'r' : show num2 |
35 let room1 = 'r' : show num3 |
35 case num2 of |
36 emulateSession sock $ session num2 nick1 room1 |
36 0 -> emulateSession sock $ session1 nick1 room1 |
|
37 1 -> emulateSession sock $ session2 nick1 room1 |
|
38 2 -> emulateSession sock $ session3 nick1 room1 |
|
39 hClose sock |
37 hClose sock |
40 putStrLn "Finish" |
38 putStrLn "Finish" |
41 |
39 |
42 forks = forever $ do |
40 forks = forever $ do |
43 delay <- randomRIO (0::Int, 90000) |
41 delays <- randomRIO (0::Int, 2) |
44 threadDelay delay |
42 replicateM 200 $ |
45 forkIO testing |
43 do |
|
44 delay <- randomRIO (delays * 20000::Int, delays * 20000 + 50000) |
|
45 threadDelay delay |
|
46 forkIO testing |
46 |
47 |
47 main = withSocketsDo $ do |
48 main = withSocketsDo $ do |
48 #if !defined(mingw32_HOST_OS) |
49 #if !defined(mingw32_HOST_OS) |
49 installHandler sigPIPE Ignore Nothing; |
50 installHandler sigPIPE Ignore Nothing; |
50 #endif |
51 #endif |