jeapostrophe / zeromq

FFI to zeromq
Other
12 stars 8 forks source link

Received messages are released too soon #2

Closed ppolv closed 12 years ago

ppolv commented 12 years ago

Hi, 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 ;)

jeapostrophe commented 12 years ago

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!