0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 15:41:05 +08:00

Problem: zmq_msg_gets did not set errno on unknown properties

Solution: set errno to EINVAL when a property does not exist.

Also fixed test_metadata.cpp to test this case.
This commit is contained in:
Pieter Hintjens 2014-06-25 17:22:02 +02:00
parent 6e91330a0c
commit dd05a64462
2 changed files with 9 additions and 2 deletions

View File

@ -648,10 +648,15 @@ int zmq_msg_set (zmq_msg_t *, int, int)
const char *zmq_msg_gets (zmq_msg_t *msg_, const char *property_)
{
zmq::metadata_t *metadata = ((zmq::msg_t*) msg_)->metadata ();
const char *value = NULL;
if (metadata)
return metadata->get (std::string (property_));
else
value = metadata->get (std::string (property_));
if (value)
return value;
else {
errno = EINVAL;
return NULL;
}
}
// Polling.

View File

@ -100,6 +100,8 @@ int main (void)
assert (streq (zmq_msg_gets (&msg, "Hello"), "World"));
assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER"));
assert (streq (zmq_msg_gets (&msg, "User-Id"), "anonymous"));
assert (zmq_msg_gets (&msg, "No Such") == NULL);
assert (zmq_errno () == EINVAL);
zmq_msg_close (&msg);
close_zero_linger (client);