~ubuntu-branches/ubuntu/maverick/zeromq/maverick

« back to all changes in this revision

Viewing changes to src/zmq_init.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adrian von Bidder
  • Date: 2010-03-17 10:43:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100317104340-un1ne0oqe16w8eaq
Tags: 2.0.6beta.dfsg-1
* New upstream version.
  - Source doesn't include non-C/C++ language bindings anymore.
  - New versioning: 2.0.6 is official upstream version which is a beta.
* Repacked orig tar: removed non-free RFC documents (closes: #567513)
* Improved/corrected description and copyright file, added bzip2 build
  dependency.  Thanks to feedback from zeromq mailing list.
* Disable OpenPGM on non-x86 architectures (closes: #567848)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
*/
19
19
 
 
20
#include <string.h>
 
21
 
20
22
#include "zmq_init.hpp"
21
23
#include "zmq_engine.hpp"
22
24
#include "io_thread.hpp"
23
25
#include "session.hpp"
 
26
#include "uuid.hpp"
24
27
#include "err.hpp"
25
28
 
26
29
zmq::zmq_init_t::zmq_init_t (io_thread_t *parent_, socket_base_t *owner_,
71
74
    if (received)
72
75
        return false;
73
76
 
74
 
    //  Retreieve the remote identity.
75
 
    peer_identity.assign ((const char*) zmq_msg_data (msg_),
76
 
        zmq_msg_size (msg_));
 
77
    //  Retreieve the remote identity. If it's empty, generate a unique name.
 
78
    if (!zmq_msg_size (msg_)) {
 
79
        unsigned char identity [uuid_t::uuid_blob_len + 1];
 
80
        identity [0] = 0;
 
81
        memcpy (identity + 1, uuid_t ().to_blob (), uuid_t::uuid_blob_len);
 
82
        peer_identity.assign (identity, uuid_t::uuid_blob_len + 1);
 
83
    }
 
84
    else {
 
85
        peer_identity.assign ((const unsigned char*) zmq_msg_data (msg_),
 
86
            zmq_msg_size (msg_));
 
87
    }
 
88
    if (options.traceroute)
 
89
        engine->add_prefix (peer_identity);
77
90
    received = true;
78
91
 
79
92
    return true;
118
131
 
119
132
uint64_t zmq::zmq_init_t::get_ordinal ()
120
133
{
121
 
    zmq_assert (false);
122
 
    return 0;
 
134
    return session_ordinal;
123
135
}
124
136
 
125
137
void zmq::zmq_init_t::process_plug ()
155
167
                return;
156
168
            }
157
169
        }
 
170
        else {
158
171
 
159
 
        //  If the peer has a unique name, find the associated session. If it
160
 
        //  doesn't exist, create it.
161
 
        else if (!peer_identity.empty ()) {
162
 
            session = owner->find_session (peer_identity.c_str ());
 
172
            //  If the peer has a unique name, find the associated session.
 
173
            //  If it does not exist, create it.
 
174
            zmq_assert (!peer_identity.empty ());
 
175
            session = owner->find_session (peer_identity);
163
176
            if (!session) {
164
177
                session = new (std::nothrow) session_t (
165
178
                    choose_io_thread (options.affinity), owner, options,
166
 
                    peer_identity.c_str ());
 
179
                    peer_identity);
167
180
                zmq_assert (session);
168
181
                send_plug (session);
169
182
                send_own (owner, session);
173
186
            }
174
187
        }
175
188
 
176
 
        //  If the other party has no specific identity, let's create a
177
 
        //  transient session.
178
 
        else {
179
 
            session = new (std::nothrow) session_t (
180
 
                choose_io_thread (options.affinity), owner, options, NULL);
181
 
            zmq_assert (session);
182
 
            send_plug (session);
183
 
            send_own (owner, session);
184
 
 
185
 
            //  Reserve a sequence number for following 'attach' command.
186
 
            session->inc_seqnum ();
187
 
        }
188
 
 
189
 
        //  No need to increment seqnum as it was laready incremented above.
190
 
        send_attach (session, engine, false);
 
189
        //  No need to increment seqnum as it was already incremented above.
 
190
        send_attach (session, engine, peer_identity, false);
191
191
 
192
192
        //  Destroy the init object.
193
193
        engine = NULL;