updateMeasure calls modifyIORef, which does not force the value. Since the Measurement is almost never examined by the program, this results in a memory leak.
In a test program I wrote, a server sending thousands of packets to a client leaks memory pretty quickly (~150 bytes per send, on my 64-bit system). After applying the space leak fix in this pull request, the program successfully sent 1000000 messages to itself using just under 10MB.
This pull request also includes a couple other improvements:
Fix space leak caused by updateMeasure
modifyIORef does not force the value, so if the Measurement object is updated a
bunch of times but never examined, the program will leak memory.
Use modifyMVar in usingState for exception safety
Also, force the state value, to avoid potential space leaks.
Add links to the 'BufferMode' type in 'client' and 'server'
Fix spelling of negotiate/negotiation in documentation
thanks, nice catch for the leak and nice improvements