resolve #1347 Support limited metadata for STREAM sockets

This commit is contained in:
Thomas Rodgers
2015-02-18 12:28:58 -06:00
parent 39338e2fe4
commit 638ddeb404
4 changed files with 42 additions and 13 deletions

View File

@@ -192,14 +192,23 @@ void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
handshaking = false;
next_msg = &stream_engine_t::pull_msg_from_session;
process_msg = &stream_engine_t::push_msg_to_session;
process_msg = &stream_engine_t::push_raw_msg_to_session;
if (!peer_address.empty()) {
// Compile metadata.
typedef metadata_t::dict_t properties_t;
properties_t properties;
properties.insert(std::make_pair("Peer-Address", peer_address));
zmq_assert (metadata == NULL);
metadata = new (std::nothrow) metadata_t (properties);
}
if (options.raw_notify) {
// For raw sockets, send an initial 0-length message to the
// application so that it knows a peer has connected.
msg_t connector;
connector.init();
push_msg_to_session (&connector);
push_raw_msg_to_session (&connector);
connector.close();
session->flush ();
}
@@ -835,6 +844,12 @@ int zmq::stream_engine_t::push_msg_to_session (msg_t *msg_)
return session->push_msg (msg_);
}
int zmq::stream_engine_t::push_raw_msg_to_session (msg_t *msg_) {
if (metadata)
msg_->set_metadata(metadata);
return push_msg_to_session(msg_);
}
int zmq::stream_engine_t::write_credential (msg_t *msg_)
{
zmq_assert (mechanism != NULL);