Exemplo n.º 1
0
bool zmq::zmq_init_t::write (::zmq_msg_t *msg_)
{
    //  If identity was already received, we are not interested
    //  in subsequent messages.
    if (received)
        return false;

    //  Retreieve the remote identity. If it's empty, generate a unique name.
    if (!zmq_msg_size (msg_)) {
        unsigned char identity [uuid_t::uuid_blob_len + 1];
        identity [0] = 0;
        memcpy (identity + 1, uuid_t ().to_blob (), uuid_t::uuid_blob_len);
        peer_identity.assign (identity, uuid_t::uuid_blob_len + 1);
    }
    else {
        peer_identity.assign ((const unsigned char*) zmq_msg_data (msg_),
            zmq_msg_size (msg_));
    }

    received = true;

    //  Try finalize initialization.
    finalise_initialisation ();

    return true;
}
Exemplo n.º 2
0
bool zmq::zmq_init_t::read (::zmq_msg_t *msg_)
{
    //  If the identity was already sent, do nothing.
    if (to_send.empty ())
        return false;

    //  Pass next property to the engine.
    *msg_ = to_send.front ();
    to_send.erase (to_send.begin ());

    //  Try finalize initialization.
    finalise_initialisation ();

    return true;
}
Exemplo n.º 3
0
bool zmq::zmq_init_t::read (::zmq_msg_t *msg_)
{
    //  If the identity was already sent, do nothing.
    if (sent)
        return false;

    //  Send the identity.
    int rc = zmq_msg_init_size (msg_, options.identity.size ());
    zmq_assert (rc == 0);
    memcpy (zmq_msg_data (msg_), options.identity.c_str (),
        options.identity.size ());
    sent = true;

    //  Try finalize initialization.
    finalise_initialisation ();

    return true;
}
Exemplo n.º 4
0
bool zmq::zmq_init_t::write (msg_t *msg_)
{
    //  If identity was already received, we are not interested
    //  in subsequent messages.
    if (received)
        return false;

    //  Retrieve the peer's identity, if any.
    zmq_assert (!(msg_->flags () & msg_t::more));
    size_t size = msg_->size ();
    if (size) {
        unsigned char *data = (unsigned char*) msg_->data ();
        peer_identity.assign (data, size);
    }

    received = true;
    finalise_initialisation ();

    return true;
}
Exemplo n.º 5
0
bool zmq::zmq_init_t::write (::zmq_msg_t *msg_)
{
    //  If identity was already received, we are not interested
    //  in subsequent messages.
    if (received)
        return false;

    size_t size = zmq_msg_size (msg_);
    unsigned char *data = (unsigned char*) zmq_msg_data (msg_);

    //  There should be at least property type in the message.
    zmq_assert (size >= 2);
    uint16_t prop = get_uint16 (data);

    switch (prop) {
    case prop_type:
        {
            zmq_assert (size == 4);
            //  TODO: Check whether the type is OK.
            //  uint16_t type = get_uint16 (data + 2);
            //  ...
            break;
        };
    case prop_identity:
        {
             peer_identity.assign (data + 2, size - 2);
             break;
        }
    default:
        zmq_assert (false);
    }

    if (!(msg_->flags & ZMQ_MSG_MORE)) {
        received = true;
        finalise_initialisation ();
    }

    return true;
}