summaryrefslogtreecommitdiff
path: root/ruby/rbzmq.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@fastmq.com>2009-09-16 15:27:39 +0200
committerMartin Sustrik <sustrik@fastmq.com>2009-09-16 15:27:39 +0200
commitfc7715b4636be7a0d49f27234359ddfddce23f5b (patch)
treebd63ddd7b86e591935b871de40ba1e341300a6a0 /ruby/rbzmq.cpp
parentf1c72d693e3bd252866a1f78e575493573eb57fe (diff)
parentc6665f46be7eb701866441087c35cdb1a08fc641 (diff)
Merge branch 'master' of git@github.com:sustrik/zeromq2
Diffstat (limited to 'ruby/rbzmq.cpp')
-rw-r--r--ruby/rbzmq.cpp106
1 files changed, 42 insertions, 64 deletions
diff --git a/ruby/rbzmq.cpp b/ruby/rbzmq.cpp
index 1751c14..bf0d9bc 100644
--- a/ruby/rbzmq.cpp
+++ b/ruby/rbzmq.cpp
@@ -83,74 +83,52 @@ static VALUE socket_initialize (VALUE self_, VALUE context_, VALUE type_)
return self_;
}
-/*
-static VALUE rb_setsockopt (VALUE self_, VALUE socket_, VALUE option_,
+
+static VALUE socket_setsockopt (VALUE self_, VALUE option_,
VALUE optval_)
{
- // Get the socket.
- void* socket;
- Data_Get_Struct (socket_, void*, socket);
-
+
int rc = 0;
- if (TYPE (optval_) == T_STRING) {
-
- // Forward the code to native 0MQ library.
- rc = zmq_setsockopt (socket, NUM2INT (option_),
- (void *) StringValueCStr (optval_), RSTRING_LEN (optval_));
-
- }
- else if (TYPE (optval_) == T_FLOAT) {
-
- double optval = NUM2DBL (optval_);
-
- // Forward the code to native 0MQ library.
- rc = zmq_setsockopt (socket, NUM2INT (option_),
- (void*) &optval, 8);
- }
-
- else if (TYPE (optval_) == T_FIXNUM) {
-
- long optval = FIX2LONG (optval_);
-
- // Forward the code to native 0MQ library.
- rc = zmq_setsockopt (socket, NUM2INT (option_),
- (void *) &optval, 4);
-
- }
-
- else if (TYPE (optval_) == T_BIGNUM) {
-
- long optval = NUM2LONG (optval_);
-
- // Forward the code to native 0MQ library.
- rc = zmq_setsockopt (socket, NUM2INT (option_),
- (void *) &optval, 4);
-
- }
- else if (TYPE (optval_) == T_ARRAY) {
-
- // Forward the code to native 0MQ library.
- rc = zmq_setsockopt (socket, NUM2INT (option_),
- (void *) RARRAY_PTR (optval_), RARRAY_LEN (optval_));
-
- }
-
- else if (TYPE (optval_) == T_STRUCT) {
-
- // Forward the code to native 0MQ library.
- rc = zmq_setsockopt (socket, NUM2INT (option_),
- (void *) RSTRUCT_PTR (optval_), RSTRUCT_LEN (optval_));
-
- }
- else
- rb_raise(rb_eRuntimeError, "Unknown type");
-
- assert (rc == 0);
-
+ switch (NUM2INT (option_)) {
+ case ZMQ_HWM:
+ case ZMQ_LWM:
+ case ZMQ_SWAP:
+ case ZMQ_AFFINITY:
+ case ZMQ_RATE:
+ case ZMQ_RECOVERY_IVL:
+ case ZMQ_MCAST_LOOP:
+ {
+ long optval = FIX2LONG (optval_);
+
+ // Forward the code to native 0MQ library.
+ rc = zmq_setsockopt (DATA_PTR (self_), NUM2INT (option_),
+ (void *) &optval, 4);
+ }
+
+ break;
+ case ZMQ_IDENTITY:
+ case ZMQ_SUBSCRIBE:
+ case ZMQ_UNSUBSCRIBE:
+
+ // Forward the code to native 0MQ library.
+ rc = zmq_setsockopt (DATA_PTR (self_), NUM2INT (option_),
+ (void *) StringValueCStr (optval_), RSTRING_LEN (optval_));
+ break;
+
+ default:
+ rc = -1;
+ errno = EINVAL;
+ }
+
+ if (rc != 0) {
+ rb_raise (rb_eRuntimeError, strerror (errno));
+ return Qnil;
+ }
+
return self_;
}
-*/
+
static VALUE socket_bind (VALUE self_, VALUE addr_)
{
@@ -264,8 +242,8 @@ extern "C" void Init_librbzmq ()
rb_define_alloc_func (socket_type, socket_alloc);
rb_define_method (socket_type, "initialize",
(VALUE(*)(...)) socket_initialize, 2);
-// rb_define_method (socket_type, "setsockopt",
-// (VALUE(*)(...)) socket_setsockopt, 2);
+ rb_define_method (socket_type, "setsockopt",
+ (VALUE(*)(...)) socket_setsockopt, 2);
rb_define_method (socket_type, "bind",
(VALUE(*)(...)) socket_bind, 1);
rb_define_method (socket_type, "connect",