(bind-func nonblocking_read_loop
(let ((buflen:i64 1024)
(buf:i8* (zalloc buflen))
(continue #t))
(lambda ()
(if (< REQUEST_SOCKET 0)
(nn_println_strerror)
(let ((nbytes (nn_recv REQUEST_SOCKET buf buflen NN_DONTWAIT)))
;; if we get some bytes, trigger the callback
(if (> nbytes 0)
(begin (printf "received response: %.*s\n" nbytes buf) void))))
(if continue
(callback (+ (now) 1000) nonblocking_read_loop)
(begin
(println "stopping nonblocking_read_loop")
0)))))