[zeromq-dev] Request for a slight change of zmq_msg_t typedef

Chernyshev Vyacheslav astellar at ro.ru
Fri Sep 21 17:25:23 CEST 2012


21.09.12, 8:09, Pieter Hintjens wrote:
> Not quite sure what your use case is, could you paste some sample code?
>
> I'd probably _not_ provide zmq_msg_t to higher level APIs at all. It's
> very low level and semantically vague. Is it a frame, a message? You
> can't even process multi-part data if you handle only zmq_msg_t's.

What if I want to hide all 3rd-party dependencies from main application? 
I can easily do it for zmq_context and zmq_socket as they are just void 
pointers, but it is just impossible for zmq message. Sample code may be 
something like:

     class Message final {
         struct Deleter final {
             void operator()(zmq_msg_t *msg) noexcept;
         };
         typedef std::unique_ptr<zmq_msg_t, Deleter> MessagePtr;

     public:
         <skipped>

     private:
         operator zmq_msg_t * () const noexcept;

         MessagePtr msg_;
     };

This example is somewhat contrived of course, but currently anything 
that requires just a pointer/reference to zmq_msg_t has to include zmq.h 
as there is no way to forward-declare zmq_msg_t. And including it 
exposes everything zmq-related to global namespace. It is not good 
sometimes.

> Applications will (I guarantee it) start to use that _ property
> directly and break future changes to the implementation.

Anonymous struct does not prevent usage of struct members at all when 
typedef is present. Applications can do something like

     #include <zmq.h>

     int main(int argc, char *argv[])
     {
         zmq_msg_t msg;
         msg._[0] = '\0'; // oops...

         return 0;
     }

right now, so if someone wants to shoot in the foot, he can do it. It is 
not a protection from illegal code, but may be a headache for legal 
use-cases.




More information about the zeromq-dev mailing list