From d20ea25b8c63e148fe48cc2b85bac9c896f1073b Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 2 Nov 2011 14:33:58 +0100 Subject: ZMQ_IDENTITY option re-introduced Signed-off-by: Martin Sustrik --- doc/zmq_getsockopt.txt | 16 ++++++++++++++++ doc/zmq_setsockopt.txt | 17 +++++++++++++++++ include/zmq.h | 1 + src/Makefile.am | 1 + src/blob.hpp | 35 +++++++++++++++++++++++++++++++++++ src/options.cpp | 25 +++++++++++++++++++++++++ src/options.hpp | 5 +++++ 7 files changed, 100 insertions(+) create mode 100644 src/blob.hpp 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 . +*/ + +#ifndef __ZMQ_BLOB_HPP_INCLUDED__ +#define __ZMQ_BLOB_HPP_INCLUDED__ + +#include + +namespace zmq +{ + + // Object to hold dynamically allocated opaque binary data. + typedef std::basic_string 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; -- cgit v1.2.3