Permalink
Browse files

fix: portCount is now 65536; portVectors now globally initialized only

once
  • Loading branch information...
cetinsert committed Aug 14, 2012
1 parent 793c65c commit 23ef37013a189dc6d1b8d7b5b29f224f7d69f9e0
Showing with 6 additions and 14 deletions.
  1. +2 −2 PortFusion.cabal
  2. +4 −12 src/Main.hs
View
@@ -84,7 +84,7 @@ executable PortFusion
if os(windows)
build-depends: network >= 2.3.0.13
if arch(i386)
ghc-options: res\win\PortFusion.res
ghc-options: res\win\PortFusion-64.res
if arch(x86_64)
ghc-options: res\win\PortFusion-64.res
else
@@ -134,7 +134,7 @@ executable PortFusion
if arch(i386)
cpp-options: -D__ARCH__="x86"
cpp-options: -D__ARCH__="x86-64"
else
if arch(x86_64)
cpp-options: -D__ARCH__="x86-64"
View
@@ -194,7 +194,6 @@ build = __OS__ <> " - " <> __ARCH__ <> " [" <> __TIMESTAMP__ <> "]"
main :: IO ()
main = withSocketsDo $ tryWith (const . print $ LS "INVALID SYNTAX") $ do
initPortVectors
mapM_ B.putStrLn [ "\n", name, copyright, "", build, "\n" ]
tasks <- parse <$> getArgs
when (null tasks) $! mapM_ B.putStrLn [ " Documentation: http://fusion.corsis.eu", "",""]
@@ -217,16 +216,10 @@ parse m = concatMap parse $ map (map B.unpack . filter (not . B.null) . B.split
type PortVector a = Ptr a
portVectors :: MVar (PortVector Word16, PortVector (StablePtr Socket))
portVectors = unsafePerformIO newEmptyMVar
initPortVectors :: IO ()
initPortVectors = do
e <- isEmptyMVar portVectors
when e $! do
c <- mallocArray0 portCount
s <- mallocArray portCount
putMVar portVectors (c,s)
where portCount = 65535
portVectors = unsafePerformIO $! newMVar =<<
(,) <$> mallocArray0 portCount
<*> mallocArray portCount
where portCount = 65536
(-@<) :: AddrPort -> IO Socket
(-@<) ap@(_ :@: p) = do
@@ -295,7 +288,6 @@ run ((:><:) fp) = do
(-<-) :: Peer -> AddrPort -> IO ()
o@(Peer !l _) -<- rp = do
initPortVectors
r <- (rp -@<)
o -✖- rp |<>| \t -> do
let f = killThread =<< takeMVar t

0 comments on commit 23ef370

Please sign in to comment.