parseBuffered :: TCPConnection -> Parser a -> IO a
parseBuffered c@(TCPConnection h bufvar) parser = do
  buffer <- readIORef bufvar
  input <- getString h
  putStrLn $ "got '" ++ buffer ++ input ++ "'"
  case parse (getRest parser) "" (buffer++input) of
    Right (result, rest) ->
        do
          writeIORef bufvar rest
          return result
    Left e ->
        do
          putStrLn $ "An error?  Hopefully doesn't matter.\n"++(show e)
          parseBuffered c parser
parseBuffered :: TCPConnection -> Parser a -> IO a
parseBuffered c@(TCPConnection h bufvar) parser = do
  buffer <- readIORef bufvar
  input <- getString h
  putStrLn $ "got '" ++ buffer ++ input ++ "'"
  case parse (getRest parser) "" (buffer++input) of
    Right (result, rest) ->
        do
          writeIORef bufvar rest
          return result
    Left e ->
        do
          putStrLn $ "An error?  Hopefully doesn't matter.\n"++(show e)
          parseBuffered c parser
parseBuffered c@(TCPConnection h bufvar) parser = do
  buffer <- readIORef bufvar
  input <- getString h
  putStrLn $ "got '" ++ buffer ++ input ++ "'"
  case parse (getRest parser) "" (buffer++input) of
    Right (result, rest) ->
        do
          writeIORef bufvar rest
          return result
    Left e ->
        do
          putStrLn $ "An error?  Hopefully doesn't matter.\n"++(show e)
          parseBuffered c parser