From fb27a000d9383b503761d0124e7bd41115d70c9a Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 24 Mar 2011 11:53:55 +0100 Subject: send/recv was changed to send/recv/sendmsg/recvmsg send/recv now complies with POSIX by using raw buffers instead of message objects and by returning number of bytes sent/recvd instead of 0/-1. The return value is changed accordingly for sendmsg and recvmsg. Note that related man pages will be fixed in a separate patch. Signed-off-by: Martin Sustrik --- tests/test_hwm.cpp | 34 +++++----------------------------- tests/testutil.hpp | 38 +++++++++++--------------------------- 2 files changed, 16 insertions(+), 56 deletions(-) (limited to 'tests') diff --git a/tests/test_hwm.cpp b/tests/test_hwm.cpp index 58d3a82..d579f9d 100644 --- a/tests/test_hwm.cpp +++ b/tests/test_hwm.cpp @@ -49,49 +49,25 @@ int main (int argc, char *argv []) // Try to send 10 messages. Only 4 should succeed. for (int i = 0; i < 10; i++) { - zmq_msg_t msg; - rc = zmq_msg_init (&msg); - assert (rc == 0); - - int rc = zmq_send (sc, &msg, ZMQ_NOBLOCK); + int rc = zmq_send (sc, NULL, 0, ZMQ_NOBLOCK); if (i < 4) assert (rc == 0); else - assert (rc != 0 && errno == EAGAIN); - - rc = zmq_msg_close (&msg); - assert (rc == 0); + assert (rc < 0 && errno == EAGAIN); } // There should be now 4 messages pending, consume them. for (int i = 0; i != 4; i++) { - - zmq_msg_t msg; - rc = zmq_msg_init (&msg); - assert (rc == 0); - - rc = zmq_recv (sb, &msg, 0); - assert (rc == 0); - - rc = zmq_msg_close (&msg); + rc = zmq_recv (sb, NULL, 0, 0); assert (rc == 0); } // Now it should be possible to send one more. - zmq_msg_t msg; - rc = zmq_msg_init (&msg); - assert (rc == 0); - rc = zmq_send (sc, &msg, 0); - assert (rc == 0); - rc = zmq_msg_close (&msg); + rc = zmq_send (sc, NULL, 0, 0); assert (rc == 0); // Consume the remaining message. - rc = zmq_msg_init (&msg); - assert (rc == 0); - rc = zmq_recv (sb, &msg, 0); - assert (rc == 0); - rc = zmq_msg_close (&msg); + rc = zmq_recv (sb, NULL, 0, 0); assert (rc == 0); rc = zmq_close (sc); diff --git a/tests/testutil.hpp b/tests/testutil.hpp index 6879dff..1fbf1f3 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -31,39 +31,23 @@ inline void bounce (void *sb, void *sc) const char *content = "12345678ABCDEFGH12345678abcdefgh"; // Send the message. - zmq_msg_t msg1; - int rc = zmq_msg_init_size (&msg1, 32); - memcpy (zmq_msg_data (&msg1), content, 32); - rc = zmq_send (sc, &msg1, 0); - assert (rc == 0); - rc = zmq_msg_close (&msg1); - assert (rc == 0); + int rc = zmq_send (sc, content, 32, 0); + assert (rc == 32); // Bounce the message back. - zmq_msg_t msg2; - rc = zmq_msg_init (&msg2); - assert (rc == 0); - rc = zmq_recv (sb, &msg2, 0); - assert (rc == 0); - rc = zmq_send (sb, &msg2, 0); - assert (rc == 0); - rc = zmq_msg_close (&msg2); - assert (rc == 0); + char buf1 [32]; + rc = zmq_recv (sb, buf1, 32, 0); + assert (rc == 32); + rc = zmq_send (sb, buf1, 32, 0); + assert (rc == 32); // Receive the bounced message. - zmq_msg_t msg3; - rc = zmq_msg_init (&msg3); - assert (rc == 0); - rc = zmq_recv (sc, &msg3, 0); - assert (rc == 0); + char buf2 [32]; + rc = zmq_recv (sc, buf2, 32, 0); + assert (rc == 32); // Check whether the message is still the same. - assert (zmq_msg_size (&msg3) == 32); - assert (memcmp (zmq_msg_data (&msg3), content, 32) == 0); - - rc = zmq_msg_close (&msg3); - assert (rc == 0); + assert (memcmp (buf2, content, 32) == 0); } - #endif -- cgit v1.2.3