Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Cazra opened this issue Jun 6, 2022 · 4 comments · Fixed by #17
Closed

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

Cazra opened this issue Jun 6, 2022 · 4 comments · Fixed by #17

Comments

@Cazra
Copy link

Cazra commented Jun 6, 2022

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
Copy link
Owner

@Cazra
Copy link
Author

Cazra commented Jun 6, 2022

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

@jeapostrophe
Copy link
Owner

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
Copy link
Contributor

mflatt commented Jun 6, 2022

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 the bytes-copy there could be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants