![]() |
libzmq master
The Intelligent Transport Layer
|
00001 /* 00002 Copyright (c) 2009-2011 250bpm s.r.o. 00003 Copyright (c) 2007-2011 iMatix Corporation 00004 Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file 00005 00006 This file is part of 0MQ. 00007 00008 0MQ is free software; you can redistribute it and/or modify it under 00009 the terms of the GNU Lesser General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 0MQ is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 #ifndef __ZMQ_TEST_TESTUTIL_HPP_INCLUDED__ 00023 #define __ZMQ_TEST_TESTUTIL_HPP_INCLUDED__ 00024 00025 #include <assert.h> 00026 #include <string.h> 00027 00028 #include "../include/zmq.h" 00029 00030 inline void bounce (void *sb, void *sc) 00031 { 00032 const char *content = "12345678ABCDEFGH12345678abcdefgh"; 00033 00034 // Send the message. 00035 int rc = zmq_send (sc, content, 32, ZMQ_SNDMORE); 00036 assert (rc == 32); 00037 rc = zmq_send (sc, content, 32, 0); 00038 assert (rc == 32); 00039 00040 // Bounce the message back. 00041 char buf1 [32]; 00042 rc = zmq_recv (sb, buf1, 32, 0); 00043 assert (rc == 32); 00044 int rcvmore; 00045 size_t sz = sizeof (rcvmore); 00046 rc = zmq_getsockopt (sb, ZMQ_RCVMORE, &rcvmore, &sz); 00047 assert (rc == 0); 00048 assert (rcvmore); 00049 rc = zmq_recv (sb, buf1, 32, 0); 00050 assert (rc == 32); 00051 rc = zmq_getsockopt (sb, ZMQ_RCVMORE, &rcvmore, &sz); 00052 assert (rc == 0); 00053 assert (!rcvmore); 00054 rc = zmq_send (sb, buf1, 32, ZMQ_SNDMORE); 00055 assert (rc == 32); 00056 rc = zmq_send (sb, buf1, 32, 0); 00057 assert (rc == 32); 00058 00059 // Receive the bounced message. 00060 char buf2 [32]; 00061 rc = zmq_recv (sc, buf2, 32, 0); 00062 assert (rc == 32); 00063 rc = zmq_getsockopt (sc, ZMQ_RCVMORE, &rcvmore, &sz); 00064 assert (rc == 0); 00065 assert (rcvmore); 00066 rc = zmq_recv (sc, buf2, 32, 0); 00067 assert (rc == 32); 00068 rc = zmq_getsockopt (sc, ZMQ_RCVMORE, &rcvmore, &sz); 00069 assert (rc == 0); 00070 assert (!rcvmore); 00071 00072 // Check whether the message is still the same. 00073 assert (memcmp (buf2, content, 32) == 0); 00074 } 00075 00076 #endif