summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-11-02 14:33:58 +0100
committerMartin Sustrik <sustrik@250bpm.com>2011-11-02 14:33:58 +0100
commitd20ea25b8c63e148fe48cc2b85bac9c896f1073b (patch)
tree652d550341029adab6926192e580955f3d6593a5
parent8e21d64c974344b5b2b83cac85d12c51392fe74b (diff)
ZMQ_IDENTITY option re-introduced
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--doc/zmq_getsockopt.txt16
-rw-r--r--doc/zmq_setsockopt.txt17
-rw-r--r--include/zmq.h1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/blob.hpp35
-rw-r--r--src/options.cpp25
-rw-r--r--src/options.hpp5
7 files changed, 100 insertions, 0 deletions
diff --git a/doc/zmq_getsockopt.txt b/doc/zmq_getsockopt.txt
index 36abbdb..252834e 100644
--- a/doc/zmq_getsockopt.txt
+++ b/doc/zmq_getsockopt.txt
@@ -117,6 +117,22 @@ Option value unit:: N/A (bitmap)
Default value:: 0
Applicable socket types:: N/A
+ZMQ_IDENTITY: Set socket identity
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The 'ZMQ_IDENTITY' option shall retrieve the identity of the specified 'socket'.
+Socket identity is used only by request/reply pattern. Namely, it can be used
+in tandem with ROUTER socket to route messages to the peer with specific
+identity.
+
+Identity should be at least one byte and at most 255 bytes long. Identities
+starting with binary zero are reserved for use by 0MQ infrastructure.
+
+[horizontal]
+Option value type:: binary data
+Option value unit:: N/A
+Default value:: NULL
+Applicable socket types:: all
+
ZMQ_RATE: Retrieve multicast data rate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt
index fd004f4..72d1faa 100644
--- a/doc/zmq_setsockopt.txt
+++ b/doc/zmq_setsockopt.txt
@@ -122,6 +122,23 @@ Default value:: N/A
Applicable socket types:: ZMQ_SUB
+ZMQ_IDENTITY: Set socket identity
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The 'ZMQ_IDENTITY' option shall set the identity of the specified 'socket'.
+Socket identity is used only by request/reply pattern. Namely, it can be used
+in tandem with ROUTER socket to route messages to the peer with specific
+identity.
+
+Identity should be at least one byte and at most 255 bytes long. Identities
+starting with binary zero are reserved for use by 0MQ infrastructure.
+
+[horizontal]
+Option value type:: binary data
+Option value unit:: N/A
+Default value:: NULL
+Applicable socket types:: all
+
+
ZMQ_RATE: Set multicast data rate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The 'ZMQ_RATE' option shall set the maximum send or receive data rate for
diff --git a/include/zmq.h b/include/zmq.h
index e6fc45c..09ed89c 100644
--- a/include/zmq.h
+++ b/include/zmq.h
@@ -170,6 +170,7 @@ ZMQ_EXPORT int zmq_term (void *context);
/* Socket options. */
#define ZMQ_AFFINITY 4
+#define ZMQ_IDENTITY 5
#define ZMQ_SUBSCRIBE 6
#define ZMQ_UNSUBSCRIBE 7
#define ZMQ_RATE 8
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b6c8f0..4d3cba3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ libzmq_la_SOURCES = \
array.hpp \
atomic_counter.hpp \
atomic_ptr.hpp \
+ blob.hpp \
clock.hpp \
command.hpp \
config.hpp \
diff --git a/src/blob.hpp b/src/blob.hpp
new file mode 100644
index 0000000..b8039c4
--- /dev/null
+++ b/src/blob.hpp
@@ -0,0 +1,35 @@
+/*
+ Copyright (c) 2010 250bpm s.r.o.
+ Copyright (c) 2010-2011 Other contributors as noted in the AUTHORS file
+
+ This file is part of 0MQ.
+
+ 0MQ is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ 0MQ is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __ZMQ_BLOB_HPP_INCLUDED__
+#define __ZMQ_BLOB_HPP_INCLUDED__
+
+#include <string>
+
+namespace zmq
+{
+
+ // Object to hold dynamically allocated opaque binary data.
+ typedef std::basic_string <unsigned char> blob_t;
+
+}
+
+#endif
+
diff --git a/src/options.cpp b/src/options.cpp
index ddf2965..aa94a21 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -1,6 +1,7 @@
/*
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
+ Copyright (c) 2011 VMware, Inc.
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
@@ -28,6 +29,7 @@ zmq::options_t::options_t () :
sndhwm (1000),
rcvhwm (1000),
affinity (0),
+ identity_size (0),
rate (100),
recovery_ivl (10000),
multicast_hops (1),
@@ -77,6 +79,20 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
affinity = *((uint64_t*) optval_);
return 0;
+ case ZMQ_IDENTITY:
+
+ // Empty identity is invalid as well as identity longer than
+ // 255 bytes. Identity starting with binary zero is invalid
+ // as these are used for auto-generated identities.
+ if (optvallen_ < 1 || optvallen_ > 255 ||
+ *((const unsigned char*) optval_) == 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ identity_size = optvallen_;
+ memcpy (identity, optval_, identity_size);
+ return 0;
+
case ZMQ_RATE:
if (optvallen_ != sizeof (int) || *((int*) optval_) <= 0) {
errno = EINVAL;
@@ -233,6 +249,15 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
*optvallen_ = sizeof (uint64_t);
return 0;
+ case ZMQ_IDENTITY:
+ if (*optvallen_ < identity_size) {
+ errno = EINVAL;
+ return -1;
+ }
+ memcpy (optval_, identity, identity_size);
+ *optvallen_ = identity_size;
+ return 0;
+
case ZMQ_RATE:
if (*optvallen_ < sizeof (int)) {
errno = EINVAL;
diff --git a/src/options.hpp b/src/options.hpp
index 8344356..d017c00 100644
--- a/src/options.hpp
+++ b/src/options.hpp
@@ -1,6 +1,7 @@
/*
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
+ Copyright (c) 2011 VMware, Inc.
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
@@ -42,6 +43,10 @@ namespace zmq
// I/O thread affinity.
uint64_t affinity;
+ // Socket identity
+ unsigned char identity_size;
+ unsigned char identity [256];
+
// Maximum tranfer rate [kb/s]. Default 100kb/s.
int rate;