summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/zmq.h2
-rw-r--r--src/options.cpp106
-rw-r--r--src/options.hpp1
-rw-r--r--src/socket_base.cpp7
-rw-r--r--src/socket_base.hpp4
-rw-r--r--src/zmq.cpp6
6 files changed, 122 insertions, 4 deletions
diff --git a/include/zmq.h b/include/zmq.h
index 3d641ef..e2b5436 100644
--- a/include/zmq.h
+++ b/include/zmq.h
@@ -187,6 +187,8 @@ ZMQ_EXPORT void *zmq_socket (void *context, int type);
ZMQ_EXPORT int zmq_close (void *s);
ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
size_t optvallen);
+ZMQ_EXPORT int zmq_getsockopt (void *s, int option, void *optval,
+ size_t *optvallen);
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
ZMQ_EXPORT int zmq_send (void *s, zmq_msg_t *msg, int flags);
diff --git a/src/options.cpp b/src/options.cpp
index 6d12944..c13488f 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -17,6 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <string.h>
+
#include "../include/zmq.h"
#include "options.hpp"
@@ -68,11 +70,11 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
return 0;
case ZMQ_AFFINITY:
- if (optvallen_ != sizeof (int64_t)) {
+ if (optvallen_ != sizeof (uint64_t)) {
errno = EINVAL;
return -1;
}
- affinity = (uint64_t) *((int64_t*) optval_);
+ affinity = *((uint64_t*) optval_);
return 0;
case ZMQ_IDENTITY:
@@ -139,3 +141,103 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno = EINVAL;
return -1;
}
+
+int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
+{
+ switch (option_) {
+
+ case ZMQ_HWM:
+ if (*optvallen_ < sizeof (uint64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((uint64_t*) optval_) = hwm;
+ *optvallen_ = sizeof (uint64_t);
+ return 0;
+
+ case ZMQ_LWM:
+ if (*optvallen_ < sizeof (uint64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((uint64_t*) optval_) = lwm;
+ *optvallen_ = sizeof (uint64_t);
+ return 0;
+
+ case ZMQ_SWAP:
+ if (*optvallen_ < sizeof (int64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int64_t*) optval_) = swap;
+ *optvallen_ = sizeof (int64_t);
+ return 0;
+
+ case ZMQ_AFFINITY:
+ if (*optvallen_ < sizeof (uint64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((uint64_t*) optval_) = affinity;
+ *optvallen_ = sizeof (uint64_t);
+ return 0;
+
+ case ZMQ_IDENTITY:
+ if (*optvallen_ < identity.size ()) {
+ errno = EINVAL;
+ return -1;
+ }
+ memcpy (optval_, identity.data (), identity.size ());
+ *optvallen_ = identity.size ();
+ return 0;
+
+
+ case ZMQ_RATE:
+ if (*optvallen_ < sizeof (int64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int64_t*) optval_) = rate;
+ *optvallen_ = sizeof (int64_t);
+ return 0;
+
+ case ZMQ_RECOVERY_IVL:
+ if (*optvallen_ < sizeof (int64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int64_t*) optval_) = recovery_ivl;
+ *optvallen_ = sizeof (int64_t);
+ return 0;
+
+ case ZMQ_MCAST_LOOP:
+ if (*optvallen_ < sizeof (int64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((int64_t*) optval_) = use_multicast_loop ? 1 : 0;
+ *optvallen_ = sizeof (int64_t);
+ return 0;
+
+ case ZMQ_SNDBUF:
+ if (*optvallen_ < sizeof (uint64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((uint64_t*) optval_) = sndbuf;
+ *optvallen_ = sizeof (uint64_t);
+ return 0;
+
+ case ZMQ_RCVBUF:
+ if (*optvallen_ < sizeof (uint64_t)) {
+ errno = EINVAL;
+ return -1;
+ }
+ *((uint64_t*) optval_) = rcvbuf;
+ *optvallen_ = sizeof (uint64_t);
+ return 0;
+ }
+
+ errno = EINVAL;
+ return -1;
+}
diff --git a/src/options.hpp b/src/options.hpp
index 0dd2e18..fd92e3f 100644
--- a/src/options.hpp
+++ b/src/options.hpp
@@ -32,6 +32,7 @@ namespace zmq
options_t ();
int setsockopt (int option_, const void *optval_, size_t optvallen_);
+ int getsockopt (int option_, void *optval_, size_t *optvallen_);
uint64_t hwm;
uint64_t lwm;
diff --git a/src/socket_base.cpp b/src/socket_base.cpp
index 89a135e..ddf2470 100644
--- a/src/socket_base.cpp
+++ b/src/socket_base.cpp
@@ -67,6 +67,13 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
return options.setsockopt (option_, optval_, optvallen_);
}
+int zmq::socket_base_t::getsockopt (int option_, void *optval_,
+ size_t *optvallen_)
+{
+ // At the moment there are no socket-type-specific overloads of getsockopt.
+ return options.getsockopt (option_, optval_, optvallen_);
+}
+
int zmq::socket_base_t::bind (const char *addr_)
{
// Parse addr_ string.
diff --git a/src/socket_base.hpp b/src/socket_base.hpp
index 4464256..1b70299 100644
--- a/src/socket_base.hpp
+++ b/src/socket_base.hpp
@@ -47,8 +47,8 @@ namespace zmq
socket_base_t (class app_thread_t *parent_);
// Interface for communication with the API layer.
- int setsockopt (int option_, const void *optval_,
- size_t optvallen_);
+ int setsockopt (int option_, const void *optval_, size_t optvallen_);
+ int getsockopt (int option_, void *optval_, size_t *optvallen_);
int bind (const char *addr_);
int connect (const char *addr_);
int send (zmq_msg_t *msg_, int flags_);
diff --git a/src/zmq.cpp b/src/zmq.cpp
index 1b70f1b..b8d18f7 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -305,6 +305,12 @@ int zmq_setsockopt (void *s_, int option_, const void *optval_,
optvallen_));
}
+int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_)
+{
+ return (((zmq::socket_base_t*) s_)->getsockopt (option_, optval_,
+ optvallen_));
+}
+
int zmq_bind (void *s_, const char *addr_)
{
return (((zmq::socket_base_t*) s_)->bind (addr_));