gameServer/stresstest2.hs
changeset 1804 4e78ad846fb6
child 2352 7eaf82cf0890
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer/stresstest2.hs	Wed Feb 18 15:04:40 2009 +0000
@@ -0,0 +1,35 @@
+{-# LANGUAGE CPP #-}
+
+module Main where
+
+import IO
+import System.IO
+import Control.Concurrent
+import Network
+import Control.Exception
+import Control.Monad
+import System.Random
+
+#if !defined(mingw32_HOST_OS)
+import System.Posix
+#endif
+
+testing = Control.Exception.handle (\e -> putStrLn $ show e) $ do
+	delay <- randomRIO (100::Int, 300)
+	threadDelay delay
+	sock <- connectTo "127.0.0.1" (PortNumber 46631)
+	hClose sock
+
+forks i = do
+	delay <- randomRIO (50::Int, 190)
+	if i `mod` 10 == 0 then putStr (show i) else putStr "."
+	hFlush stdout
+	threadDelay delay
+	forkIO testing
+	forks (i + 1)
+
+main = withSocketsDo $ do
+#if !defined(mingw32_HOST_OS)
+	installHandler sigPIPE Ignore Nothing;
+#endif
+	forks 1