request   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/nanomsg.xtm

Implementation

(bind-func request
  (let ((buflen:i64 1024)
        (buf:i8* (zalloc buflen)))
    (lambda (msg:i8*)
      (let ((sz_msg (+ (strlen msg) 1))
            (bytes (nn_send REQUEST_SOCKET msg sz_msg 0)))
        (if (= bytes (convert sz_msg)) ;; should also check (< bytes (convert sz_msg))
            (let ((rbytes (nn_recv REQUEST_SOCKET buf buflen 0)))
              (if (> rbytes 0)
                  (begin (printf "reply received: %s\n" buf)
                         void)))
            (nn_println_strerror "error in request"))))))


Back to Index

Similar Entries