Implement socket_base_t::get_credential member function

The get_credential () member function returns
credential for the last peer we received message for.
The idea is that this function is used to implement user-level API.
This commit is contained in:
Martin Hurton
2014-01-12 21:58:36 +01:00
parent 5c4f3cc603
commit e46ec31209
25 changed files with 158 additions and 4 deletions

View File

@@ -692,7 +692,7 @@ void zmq::stream_engine_t::mechanism_ready ()
}
read_msg = &stream_engine_t::pull_and_encode;
write_msg = &stream_engine_t::decode_and_push;
write_msg = &stream_engine_t::write_credential;
}
int zmq::stream_engine_t::pull_msg_from_session (msg_t *msg_)
@@ -705,6 +705,29 @@ int zmq::stream_engine_t::push_msg_to_session (msg_t *msg_)
return session->push_msg (msg_);
}
int zmq::stream_engine_t::write_credential (msg_t *msg_)
{
zmq_assert (mechanism != NULL);
zmq_assert (session != NULL);
const blob_t credential = mechanism->get_user_id ();
if (credential.size () > 0) {
msg_t msg;
int rc = msg.init_size (credential.size ());
zmq_assert (rc == 0);
memcpy (msg.data (), credential.data (), credential.size ());
msg.set_flags (msg_t::credential);
rc = session->push_msg (&msg);
if (rc == -1) {
rc = msg.close ();
errno_assert (rc == 0);
return -1;
}
}
write_msg = &stream_engine_t::decode_and_push;
return decode_and_push (msg_);
}
int zmq::stream_engine_t::pull_and_encode (msg_t *msg_)
{
zmq_assert (mechanism != NULL);