mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-28 03:20:13 +01:00
ZMQ_IDENTITY option re-introduced
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user