mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-27 15:41:05 +08:00
ZMQ_IDENTITY option re-introduced
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
8e21d64c97
commit
d20ea25b8c
@ -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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -9,6 +9,7 @@ libzmq_la_SOURCES = \
|
||||
array.hpp \
|
||||
atomic_counter.hpp \
|
||||
atomic_ptr.hpp \
|
||||
blob.hpp \
|
||||
clock.hpp \
|
||||
command.hpp \
|
||||
config.hpp \
|
||||
|
35
src/blob.hpp
Normal file
35
src/blob.hpp
Normal file
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user