[zeromq-dev] Fix for libzmq.vcproj failing to compile. And a question about size of message changing after being sent by socket
sustrik at 250bpm.com
Tue Jun 29 07:51:55 CEST 2010
Salvor Hardin wrote:
> I'm using latest zeromq from git (zeromq2-ba91644...) compiled with
> Visual C++ 2008 SP1, tested on Vista 32-bit.
> Please consider adding NOMINMAX to preprocessor definitions in
> libzmq.vcproj. Without NOMINMAX, msvc fails to compile msg_store.cpp
> because Windef.h defines "min".
Ok. Fixed in the trunk.
> Also, here's a C++ code snippet showing odd behavior (message size
> goes from 22 before sending, to 0 after sending.)
> Please let me know if this is a bug or a feature. Thanks.
> zmq::context_t ctx (1);
> zmq::socket_t s (ctx, ZMQ_REQ);
> s.connect ("tcp://localhost:5555");
> const char *query_string = "SELECT * FROM mytable";
> zmq::message_t query (strlen (query_string) + 1);
> memcpy (query.data (), query_string, strlen (query_string) + 1);
> printf("query.size() before send: %ld\n", query.size()); // 22
> s.send (query);
> printf("query.size() after send: %ld\n", query.size()); // 0
Yes. This behaviour is by design. It has to do with zero-copy. When
message is _moved_ to the I/O thread there's no need to copy it or
If you want to clone the message so that it can be used after send, use
zmq_msg_copy function. Note that it doesn't necessarily copy the data,
in most cases it will just add refcount to the message.
Hope things are OK back there at the Foundation!
More information about the zeromq-dev