diff --git a/Network/Connection.hs b/Network/Connection.hs
--- a/Network/Connection.hs
+++ b/Network/Connection.hs
@@ -41,6 +41,7 @@
     , connectionGetChunk
     , connectionGetChunk'
     , connectionGetLine
+    , connectionWaitForInput
     , connectionPut
 
     -- * TLS related operation
@@ -74,6 +75,7 @@
 import qualified Data.ByteString.Lazy as L
 
 import System.Environment
+import System.Timeout
 import System.IO
 import qualified Data.Map as M
 
@@ -170,8 +172,9 @@
           -> IO Connection     -- ^ The new established connection on success.
 connectTo cg cParams = do
     conFct <- getConFct (connectionUseSocks cParams)
-    h      <- conFct (connectionHostname cParams) (N.PortNumber $ connectionPort cParams)
-    connectFromSocket cg h cParams
+    let doConnect = conFct (connectionHostname cParams) (N.PortNumber $ connectionPort cParams)
+    E.bracketOnError doConnect N.close $ \h->
+        connectFromSocket cg h cParams
   where
         getConFct Nothing                            = return resolve'
         getConFct (Just (OtherProxy h p))            = return $ \_ _ -> resolve' h (N.PortNumber p)
@@ -273,6 +276,19 @@
 connectionGetChunk' :: Connection -> (ByteString -> (a, ByteString)) -> IO a
 connectionGetChunk' = connectionGetChunkBase "connectionGetChunk'"
 
+-- | Wait for input to become available on a connection.
+--
+-- As with 'hWaitForInput', the timeout value is given in milliseconds.  If the
+-- timeout value is less than zero, then 'connectionWaitForInput' waits
+-- indefinitely.
+--
+-- Unlike 'hWaitForInput', this function does not do any decoding, so it
+-- returns true when there is /any/ available input, not just full characters.
+connectionWaitForInput :: Connection -> Int -> IO Bool
+connectionWaitForInput conn timeout_ms = maybe False (const True) <$> timeout timeout_ns tryGetChunk
+  where tryGetChunk = connectionGetChunkBase "connectionWaitForInput" conn $ \buf -> ((), buf)
+        timeout_ns  = timeout_ms * 1000
+
 connectionGetChunkBase :: String -> Connection -> (ByteString -> (a, ByteString)) -> IO a
 connectionGetChunkBase loc conn f =
     modifyMVar (connectionBuffer conn) $ \m ->
@@ -336,7 +352,7 @@
       join $ connectionGetChunkBase loc conn $ \s ->
         if B.null s
           then (eofK, B.empty)
-          else case B.breakByte 10 s of
+          else case B.break (== 10) s of
                  (a, b)
                    | B.null b  -> (moreK a, B.empty)
                    | otherwise -> (doneK a, B.tail b)
diff --git a/connection.cabal b/connection.cabal
--- a/connection.cabal
+++ b/connection.cabal
@@ -1,5 +1,5 @@
 Name:                connection
-Version:             0.2.6
+Version:             0.2.7
 Description:
     Simple network library for all your connection need.
     .
