while using the 0mq bindings to have some fun while learning racket, I think I found a small problem.
(socket-recv! sock) is releasing the received message too soon.
Its byte contents might be used by the caller after they were already released or reused by 0mq, this is particular true on high-rate scenarios with messages larger than just a few bytes.
The patch do the simplest fix: just copy the bytes.
A better API that lets the caller access the data without copying it, and then release the underling msg when done will be useful to avoid double-copying in many situations, being the caller's responsibility to copy the data somewhere if he need to access it latter. But that's beyond my current racket abilities ;)
Do not release msg until not really used anymore
Just bytes-copy it.
Thanks so much. I think the better API you're thinking of is 0mq itself. socket-recv is just a convenience in Racket, so if it doesn't do the most efficient thing, the 0mq user should go directly to the API. In this case, your patch definitely fixes an error. Thank you!