Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit c5b6c09

Browse files
committed
Improved zeromq.zmq/send-all function
- zeromq.zmq/send-all now behaves well when empty coll is given - test added for zeromq.zmq/send-all and zeromq.zmq/receive-all with req/rep socket pair
1 parent b6d6036 commit c5b6c09

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/zeromq/zmq.clj

+7-6
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,15 @@
219219
(persistent! new-acc)))))
220220

221221
(defn send-all
222-
"Send all data parts to the socket.
223-
coll is a seq containing byte arrays."
222+
"Send all data parts to the socket. coll is a seq containing byte arrays.
223+
Does nothing if coll is empty."
224224
[^ZMQ$Socket socket coll]
225225
(loop [[x & xs] coll]
226-
(if xs
227-
(do (send socket x send-more)
228-
(recur xs))
229-
(send socket x))))
226+
(when x
227+
(if xs
228+
(do (send socket x send-more)
229+
(recur xs))
230+
(send socket x)))))
230231

231232
(defn ^ZMQ$Socket set-linger
232233
"The linger option shall set the linger period for the specified socket. The

test/zeromq/zmq_test.clj

+15
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@
4242
(zmq/send-str router "ack")
4343
(let [actual (zmq/receive-str dealer)]
4444
(is (= "ack" actual))))))
45+
46+
(deftest receive-all-send-all-test
47+
(let [addr "inproc://rxtx-all-test"]
48+
(with-open [req (doto (zmq/socket context :req)
49+
(zmq/bind addr))
50+
rep (doto (zmq/socket context :rep)
51+
(zmq/connect addr))]
52+
(zmq/send-all req [(.getBytes "hello") (.getBytes "world")])
53+
(let [msg (zmq/receive-all rep)]
54+
(is (= (vec (first msg)) (vec (.getBytes "hello"))))
55+
(is (= (vec (second msg)) (vec (.getBytes "world"))))
56+
)
57+
(zmq/send-all rep [(byte-array[])])
58+
(let [msg (zmq/receive-all req)]
59+
(is (= (vec (first msg)) []))))))

0 commit comments

Comments
 (0)