ZMQ_MSG_GET(3)

πŸ’– ZMQ_MSG_GET(3) πŸ’–

okay so bestie, welcome to zmq_msg_get β€” it's a page from the 0MQ Manual and honestly? it's giving "tiny function, big secrets". let's get into it 🫢


✨ NAME ✨

zmq_msg_get β€” get message property πŸ‘‘


✨ SYNOPSIS ✨

int zmq_msg_get (zmq_msg_t *message, int property);

✨ DESCRIPTION ✨

so like. the zmq_msg_get() function shall return the value for the property you ask for β€” you name that property in the property argument β€” for the message that the message argument is pointing at. that's it. that's the whole vibe. 🌸

here are the properties you can pull out with zmq_msg_get(), no cap:

ZMQ_MORE πŸ’…

indicates that there are more message frames to follow after the message. like, this is not the last one, keep going, there's more where that came from.

ZMQ_SRCFD πŸ”₯

returns the file descriptor of the socket the message was read from. this lets your application retrieve the remote endpoint via getpeername(2) β€” iconic. but bestie, be aware: the respective socket might already be closed, or even reused 😭 (reused! the audacity). currently only implemented for TCP sockets.

ZMQ_SHARED πŸ¦‹

indicates that a message MAY share underlying storage with another copy of this message. "may" is doing a lot of heavy lifting here β€” it's not a promise, it's a possibility. periodt.


✨ RETURN VALUE ✨

if everything slays, zmq_msg_get() shall return the value for the property. otherwise? it shall return -1 and set errno to one of the values defined below. πŸ’€


✨ ERRORS ✨

  • EINVAL β€” the requested property is unknown. like, you asked for a property that doesn't exist. it's not them, it's you.

✨ EXAMPLE ✨

receiving a multi-frame message πŸŽ€ (this is the main character scenario fr fr):

zmq_msg_t frame;
while (true) {
    //  Create an empty 0MQ message to hold the message frame
    int rc = zmq_msg_init (&frame);
    assert (rc == 0);
    //  Block until a message is available to be received from socket
    rc = zmq_msg_recv (socket, &frame, 0);
    assert (rc != -1);
    if (zmq_msg_get (&frame, ZMQ_MORE))
        fprintf (stderr, "more\n");
    else {
        fprintf (stderr, "end\n");
        break;
    }
    zmq_msg_close (&frame);
}

✨ SEE ALSO ✨

zmq_msg_set(3) zmq_msg_init(3) zmq_msg_close(3) zmq(7) 🌈


✨ AUTHORS ✨

this page was written by the 0MQ community 🫢 if you wanna make a change, please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing β€” they'd love to have you, fr.


okay and that's the whole page bestie, tysm for reading πŸ’– this was the 0MQ 4.3.5 version, dated 10/09/2023, and honestly it ate. go forth and get those message properties. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from