jeapostrophe / zeromq

FFI to zeromq
Other
12 stars 8 forks source link

socket-recv! not working - "make-sized-byte-string: unsupported" #16

Closed Cazra closed 2 years ago

Cazra commented 2 years ago

I'm having trouble using the socket-recv! function. Whenever I try to invoke it, I get the following error: make-sized-byte-string: unsupported

Here's a minimal code example for how I'm trying to use it:

(define (run-zmq-server port)
  (call-with-context (λ (ctx)
    (call-with-socket ctx 'PULL (λ (socket)
      (socket-bind! socket (format "tcp://127.0.0.1:~a" port))
      (display (format "Started mock CE Service on port ~a.\n" port))

      (let loop ()
        (let* ([dto-bytes (socket-recv! socket)] ; <--- The error is getting thrown here.
               [req (_bytes->dto dto-bytes)]
               [msg-type (hash-ref req 'messageType #f)])
          (cond
            [(equal? msg-type 'CLOSE)
              (display "Closing mock CE Service.\n")]
            [else
              (display (format "Received message:\n~a\n\n" msg-type))
              (loop)]))))))))
jeapostrophe commented 2 years ago

That function is not supported in ChezScheme --- https://docs.racket-lang.org/foreign/foreign_pointer-funcs.html#%28def._%28%28quote._~23~25foreign%29._make-sized-byte-string%29%29

Cazra commented 2 years ago

Are there any plans to add compatibility to this project to support socket-recv! in ChezScheme?

jeapostrophe commented 2 years ago

I have no plans and I assume that @mflatt can't support make-sized-byte-string. If you find a way to make something similar works, I'd merge it!

mflatt commented 2 years ago

It looks like the use here

 (make-sized-byte-string (msg-data-pointer m) (msg-size m))

could be replaced with

(let ([s (make-bytes (msg-size m))])
  (memcpy s (msg-data-pointer m) (msg-size m))
  s)

This copies data out of the message instead of pointing inside message. But socket-recv! was copying anyway, and thebytes-copy there could be removed.