Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "czmq.h"
- int main(int argc, char* argv[])
- {
- const char* endpoint = "inproc://test";
- const char* msg = "Hello Hello Hello Hello Hello!"; // length 30
- // create context
- zctx_t* ctx = zctx_new();
- assert(ctx);
- // create and bind pull socket
- void* pull = zsocket_new(ctx, ZMQ_PULL);
- int port = zsocket_bind(pull, endpoint);
- // create and connect push socket
- void* push = zsocket_new(ctx, ZMQ_PUSH);
- int rc = zsocket_connect(push, endpoint);
- assert(rc == 0);
- // destroy puller, then send
- zsocket_destroy(ctx, pull);
- sleep(1);
- rc = zsocket_sendmem(push, msg, strlen(msg), ZFRAME_DONTWAIT);
- assert(rc == -1);
- // clean up
- zsocket_destroy(ctx, push);
- zctx_destroy(&ctx);
- }
- /*
- Output:
- # valgrind --leak-check=full --show-reachable=yes ./testcase
- ==4354== Memcheck, a memory error detector
- ==4354== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
- ==4354== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
- ==4354== Command: ./testcase
- ==4354==
- ==4354==
- ==4354== HEAP SUMMARY:
- ==4354== in use at exit: 70 bytes in 1 blocks
- ==4354== total heap usage: 66 allocs, 65 frees, 40,842 bytes allocated
- ==4354==
- ==4354== 70 bytes in 1 blocks are definitely lost in loss record 1 of 1
- ==4354== at 0x4C277AB: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
- ==4354== by 0x5098850: zmq::msg_t::init_size(unsigned long) (msg.cpp:60)
- ==4354== by 0x4E5212B: zsocket_sendmem (zsocket.c:211)
- ==4354== by 0x400B19: main (in /root/zeromq/testcase)
- ==4354==
- ==4354== LEAK SUMMARY:
- ==4354== definitely lost: 70 bytes in 1 blocks
- ==4354== indirectly lost: 0 bytes in 0 blocks
- ==4354== possibly lost: 0 bytes in 0 blocks
- ==4354== still reachable: 0 bytes in 0 blocks
- ==4354== suppressed: 0 bytes in 0 blocks
- ==4354==
- ==4354== For counts of detected and suppressed errors, rerun with: -v
- ==4354== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
- */
Advertisement
Add Comment
Please, Sign In to add comment