[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:45:41 UTC 2010


The following commit has been merged in the master branch:
commit 0aa340240debbe509d1be71e118bc000c41277b4
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sun Oct 24 07:37:22 2004 +0100

    Added some IO and network utilities
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-112)

diff --git a/ChangeLog b/ChangeLog
index d68bd20..37fae24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,18 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
 #
 
+2004-10-24 01:37:22 GMT	John Goerzen <jgoerzen at complete.org>	patch-112
+
+    Summary:
+      Added some IO and network utilities
+    Revision:
+      missingh--head--1.0--patch-112
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/IO.hs libsrc/MissingH/Network.hs
+
+
 2004-10-23 22:54:00 GMT	John Goerzen <jgoerzen at complete.org>	patch-111
 
     Summary:
diff --git a/libsrc/MissingH/IO.hs b/libsrc/MissingH/IO.hs
index 9173ba0..cf29c1c 100644
--- a/libsrc/MissingH/IO.hs
+++ b/libsrc/MissingH/IO.hs
@@ -45,6 +45,8 @@ module MissingH.IO(-- * Entire File\/Handle Utilities
                        hInteract,
                        -- ** Line-based
                        hLineInteract, lineInteract,
+                   -- * Optimizations
+                   optimizeForBatch, optimizeForInteraction
                         ) where
 
 import System.IO.Unsafe
@@ -206,3 +208,18 @@ copyFileLinesToFile infn outfn = do
                                  hClose hout
                                  return ()
 
+{- | Sets stdin and stdout to be block-buffered.  This can save a huge amount
+of system resources since far fewer syscalls are made, and can make programs
+run much faster. -}
+optimizeForBatch :: IO ()
+optimizeForBatch = do
+                   hSetBuffering stdin (BlockBuffering (Just 4096))
+                   hSetBuffering stdout (BlockBuffering (Just 4096))
+
+{- | Sets stdin and stdout to be line-buffered.  This saves resources
+on stdout, but not many on stdin, since it it still looking for newlines.
+-}
+optimizeForInteraction :: IO ()
+optimizeForInteraction = do
+                         hSetBuffering stdin LineBuffering
+                         hSetBuffering stdout LineBuffering
diff --git a/libsrc/MissingH/Network.hs b/libsrc/MissingH/Network.hs
index 2b7ccac..16412ac 100644
--- a/libsrc/MissingH/Network.hs
+++ b/libsrc/MissingH/Network.hs
@@ -31,12 +31,31 @@ This module provides various helpful utilities for dealing with networking
 Written by John Goerzen, jgoerzen\@complete.org
 -}
 
-module MissingH.Network(connectTCP, connectTCPAddr
+module MissingH.Network(niceSocketsDo, connectTCP, connectTCPAddr
                        )
 where
+import Network
 import Network.Socket
 import Network.BSD
 import System.IO
+import qualified System.Posix.Signals
+
+{- | Sets up the system for networking.  Similar to the built-in
+withSocketsDo (and actually, calls it), but also sets the SIGPIPE
+handler so that signal is ignored. 
+
+Example:
+
+> main = niceSocketsDo $ do { ... } 
+-}
+
+niceSocketsDo :: IO a -> IO a
+niceSocketsDo func = do
+                System.Posix.Signals.installHandler 
+                      System.Posix.Signals.sigPIPE
+                      System.Posix.Signals.Ignore
+                      Nothing
+                withSocketsDo func
 
 connectTCP :: HostName -> PortNumber -> IO Socket
 connectTCP host port = do

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list