[Haskell-cafe] `Expect'-like lazy reading/Parsec matching on TCP sockets

Scott Bell sebell at gmail.com
Wed Apr 4 10:39:22 EDT 2007


Bulat,

> one possible solution: use Streams library and establish a stream
> transformer that adds an error call on timeout. something like this:
>
> data StreamWithTimeout s = StreamWithTimeout s Timeout
>
> instance Stream s => Stream (StreamWithTimeout s) where
>   vGetChar (StreamWithTimeout s t) = do
>      timeout t (vGetChar s)
>                (error "Timed out!")

If possible, I would like to try and use lazy [Char]s -- this would greatly
simplify my usage of the Parsec parser.

> or, even simple, you can make your own variant of hGetContents which
> adds a timeout checks before each next call to hGetChar or hGetBuf

Can this be as simple as applying the parser against a string returned
by the (modified) hGetContents, which will read all that is possible given
a certain time constraint?

Thanks,

- Scott


More information about the Haskell-Cafe mailing list