[zeromq-dev] Message corruption
Martin Hurton
hurtonm at gmail.com
Wed Aug 26 04:01:52 CEST 2009
Hi Conrad,
On Wed, Aug 26, 2009 at 3:18 AM, Conrad
Steenberg<conrad.steenberg at gmail.com> wrote:
> Hi Martin et al,
>
> In my application I'm sending a message using
> void somefunction(){
> string data=....;
> zmq::message_t out_message ((void *)data.c_str(), data.length(),
> NULL);
> while (!api->send (used_exid, out_message, true));
> }
When you construct messages this way, the ZeroMQ takes over the
ownership of the memory buffer. The problem is you cannot do this with
memory as returned by c_str () method, as it can be reused later.
Try to allocate you own buffer and copy the string into it.
I hope this helps.
- Martin
>
> Sometimes the data in the message (over TCP) that ends up on the wire is
> different than what is put in the message. Up to and including
> zmq::pipe_t::write (raw_message_t *msg_) in pipe.cpp, everything seems
> OK.
>
> Is there anything obvious in the above snippet that might lead to memory
> being trampled upon? Like the "data" string being deallocated when the
> function returns? My assumption here is that the message gets "sent"
> before the function returns.
>
> What is a reasonable place to check the raw_messages that comes out of
> the y_pipe once written?
>
>
> Thanks!
> Conrad
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
More information about the zeromq-dev
mailing list