jaspervdj/websockets — pull request #13 by yihuang (2011-12-10 17:53:52+00:00)
Title: run an inner iteratee inside websockets monad

I need this mainly for implementing sockjs (or other websockets-like protocol), maybe this is also useful for other task.
The main function of this patch is rewrite the core procedure of websockets into a streamlined fashion using `Enumeratee` , and finally pass the data message to a inner `Iteratee`. We hide all the details of websockets protocol from the inner `Iteratee`, we can consider the inner `Iteratee` runs in a simpler websockets-like protocol. Then, we can easily use other transport to drive this same `Iteratee`.
I've made this simplified websockets-like protocol into a seperate package: websockets-lite[1], also wai-sockjs[2] package to drive it using sockjs transport protocol.

The implementation is quite simple, except one gotcha relating to problematic exception handling of enumerator library. for example, when implementing `Enumeratee` using combinators like `concatMapM`, when exception happened in the `Enumeratee`, the inner `Iteratee` has on way to know that. So i have to hack the combinator, fortunately, i only need to hack one function, the result is `concatMapIO`, which catch all the exceptions and send `EOF` to inner `Iteratee` which indicate the connection is closed, so the inner `Iteratee` can do some cleanup work.

[1]. https://github.com/yihuang/websockets-lite
[2]. https://github.com/yihuang/wai-sockjs