Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Received messages are released too soon #2

Merged
merged 1 commit into from

2 participants

@ppolv

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 jeapostrophe merged commit 7fd5945 into from
@jeapostrophe
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 6, 2012
  1. @ppolv

    Do not release msg until not really used anymore

    ppolv authored
    Just bytes-copy it.
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 zmq.rkt
View
4 zmq.rkt
@@ -377,7 +377,7 @@
(socket-recv-msg! s m empty)
(dynamic-wind
void
- (λ () (msg-data m))
+ (λ () (bytes-copy (msg-data m)))
(λ ()
(msg-close! m)
(free m))))
@@ -398,4 +398,4 @@
[zmq-version zmq_version]
(-> (values exact-nonnegative-integer? exact-nonnegative-integer? exact-nonnegative-integer?))
(_fun [major : (_ptr o _int)] [minor : (_ptr o _int)] [patch : (_ptr o _int)]
- -> [err : _int] -> (if (zero? err) (values major minor patch) (zmq-error))))
+ -> [err : _int] -> (if (zero? err) (values major minor patch) (zmq-error))))
Something went wrong with that request. Please try again.