summaryrefslogtreecommitdiff
path: root/src/options.cpp
diff options
context:
space:
mode:
authorsustrik <sustrik@250bpm.com>2011-11-04 02:15:37 -0700
committersustrik <sustrik@250bpm.com>2011-11-04 02:15:37 -0700
commit6cdd720400ea456ccbfdf09cdc5054ab07dbdc6f (patch)
tree6a25ede64ac1252e022feb91b1342cdc38e3dcf5 /src/options.cpp
parent541b83bc02784c721efa3d9dde8f8a191c3c3b7b (diff)
parente9c3a227a7175b4eda5193b1c8ce6985f5ed89f3 (diff)
Merge pull request #220 from 250bpm/HEAD
Refactoring
Diffstat (limited to 'src/options.cpp')
-rw-r--r--src/options.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/options.cpp b/src/options.cpp
index 8a3e527..4db1a6c 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -1,5 +1,7 @@
/*
- Copyright (c) 2007-2011 iMatix Corporation
+ 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.
@@ -27,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),
@@ -43,7 +46,9 @@ zmq::options_t::options_t () :
ipv4only (1),
delay_on_close (true),
delay_on_disconnect (true),
- filter (false)
+ filter (false),
+ send_identity (false),
+ recv_identity (false)
{
}
@@ -76,6 +81,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;
@@ -232,6 +251,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;