- line <- recv_line h
-
- if (xml_prologue `isPrefixOf` line && not (null buffer))
- then do
- -- This is the beginning of a new document, and we have an "old"
- -- one to save. The buffer is in reverse (newest first) order,
- -- though, so we have to reverse it first. We then concatenate all
- -- of its lines into one big string.
- let document = concat $ reverse buffer
- save_document cfg document
- loop cfg h [line] -- Empty the buffer before looping again.
- else
- -- Append line to the head of the buffer and loop.
- loop cfg h (line : buffer)
+ line' <- timeout fifteen_minutes $ recv_line h
+ case line' of
+ -- If we haven't received anything in fifteen minutes, return back
+ -- to the calling function. This should only happen in the case of
+ -- an error, and our caller should be prepared to handle it.
+ Nothing -> report_warning "No data received for 15 minutes."
+
+ Just line -> do
+ -- If the recv didn't timeout, proceed normally.
+ let new_buffer = line : buffer
+
+ -- Use isPrefixOf to avoid line-ending issues. Hopefully they won't
+ -- send invalid junk (on the same line) after closing the root
+ -- element.
+ if "</message>" `isPrefixOf` line
+ then do
+ -- The buffer is in reverse (newest first) order, though, so we
+ -- have to reverse it first. We then concatenate all of its lines
+ -- into one big string.
+ let document = concat $ reverse new_buffer
+ save_document cfg document
+ loop cfg h [] -- Empty the buffer before looping again.
+ else
+ -- Append line to the head of the buffer and loop.
+ loop cfg h new_buffer
+ where
+ fifteen_minutes :: Int
+ fifteen_minutes = 15 * 60 * 1000000