hreinhardt/amqp — pull request #30 by gseitz (2013-10-08 20:53:21+00:00)
Title: Add heartbeat support.

Hi,
This PR adds heartbeat support, as already discussed in #25.

* If no heartbeat delay (`coHeartbeatDelay`) is specified, the server provided value is used. Disabling heartbeating can be achieved by setting `coHeartbeatDelay` to `Just 0`.
* In case heartbeating is enabled, both incoming and outgoing heartbeats are checked every `timeout / 4` seconds.
* If the last outgoing frame was sent longer than `now - timeout / 2` ago, send a heartbeat frame to avoid running into a timeout on the server.
* If the last incoming frame was received longer than `timeout * 2` ago, kill the connection abruptly without sending the `close` frame.
* A dedicated thread (`forkIO`) is used to schedule the hearbeat checks.
* Each check is then executed in its own dedicated thread (`forkIO`) to not skew the rate at which the checks need to be executed. (*)

(*) Does this make sense at all? Should any exception during the heartbeat check be caught and "logged" (as opposed to just letting the thread die)?

@fegu: Could you give this a spin? I did some local tests, but as you have experienced problems in the past with some network hardware, I'd be interested in your experience report.

Please let me know if something is missing or you need anything changed.

Cheers