mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-31 14:39:55 +01:00
Merge branch 'master' of git@github.com:sustrik/zeromq2
This commit is contained in:
commit
fc7715b463
@ -29,7 +29,7 @@ message_count = ARGV[2].to_i
|
|||||||
|
|
||||||
ctx = Context.new(1, 1)
|
ctx = Context.new(1, 1)
|
||||||
s = Socket.new(ctx, SUB);
|
s = Socket.new(ctx, SUB);
|
||||||
s.setsockopt (SUBSCRIBE, "*");
|
s.setsockopt(SUBSCRIBE, "*");
|
||||||
|
|
||||||
# Add your socket options here.
|
# Add your socket options here.
|
||||||
# For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
|
# For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
|
||||||
|
@ -139,15 +139,30 @@ PyObject *socket_setsockopt (socket_t *self, PyObject *args, PyObject *kwdict)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc;
|
int rc = 0;
|
||||||
if (PyInt_Check (optval)) {
|
|
||||||
int val = PyInt_AsLong (optval);
|
switch (option) {
|
||||||
rc = zmq_setsockopt (self->handle, option, &val, sizeof (int));
|
case ZMQ_HWM:
|
||||||
}
|
case ZMQ_LWM:
|
||||||
if (PyString_Check (optval))
|
case ZMQ_SWAP:
|
||||||
rc = zmq_setsockopt (self->handle, option, PyString_AsString (optval),
|
case ZMQ_AFFINITY:
|
||||||
PyString_Size (optval));
|
case ZMQ_RATE:
|
||||||
else {
|
case ZMQ_RECOVERY_IVL:
|
||||||
|
case ZMQ_MCAST_LOOP:
|
||||||
|
{
|
||||||
|
int val = PyInt_AsLong (optval);
|
||||||
|
rc = zmq_setsockopt (self->handle, option, &val, sizeof (int));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ZMQ_IDENTITY:
|
||||||
|
case ZMQ_SUBSCRIBE:
|
||||||
|
case ZMQ_UNSUBSCRIBE:
|
||||||
|
|
||||||
|
rc = zmq_setsockopt (self->handle, option, PyString_AsString (optval),
|
||||||
|
PyString_Size (optval));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
rc = -1;
|
rc = -1;
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -83,74 +83,52 @@ static VALUE socket_initialize (VALUE self_, VALUE context_, VALUE type_)
|
|||||||
return self_;
|
return self_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static VALUE rb_setsockopt (VALUE self_, VALUE socket_, VALUE option_,
|
static VALUE socket_setsockopt (VALUE self_, VALUE option_,
|
||||||
VALUE optval_)
|
VALUE optval_)
|
||||||
{
|
{
|
||||||
// Get the socket.
|
|
||||||
void* socket;
|
|
||||||
Data_Get_Struct (socket_, void*, socket);
|
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (TYPE (optval_) == T_STRING) {
|
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.
|
// Forward the code to native 0MQ library.
|
||||||
rc = zmq_setsockopt (socket, NUM2INT (option_),
|
rc = zmq_setsockopt (DATA_PTR (self_), NUM2INT (option_),
|
||||||
(void *) StringValueCStr (optval_), RSTRING_LEN (optval_));
|
(void *) &optval, 4);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
break;
|
||||||
else if (TYPE (optval_) == T_FLOAT) {
|
case ZMQ_IDENTITY:
|
||||||
|
case ZMQ_SUBSCRIBE:
|
||||||
|
case ZMQ_UNSUBSCRIBE:
|
||||||
|
|
||||||
double optval = NUM2DBL (optval_);
|
// Forward the code to native 0MQ library.
|
||||||
|
rc = zmq_setsockopt (DATA_PTR (self_), NUM2INT (option_),
|
||||||
|
(void *) StringValueCStr (optval_), RSTRING_LEN (optval_));
|
||||||
|
break;
|
||||||
|
|
||||||
// Forward the code to native 0MQ library.
|
default:
|
||||||
rc = zmq_setsockopt (socket, NUM2INT (option_),
|
rc = -1;
|
||||||
(void*) &optval, 8);
|
errno = EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (TYPE (optval_) == T_FIXNUM) {
|
if (rc != 0) {
|
||||||
|
rb_raise (rb_eRuntimeError, strerror (errno));
|
||||||
long optval = FIX2LONG (optval_);
|
return Qnil;
|
||||||
|
}
|
||||||
// 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);
|
|
||||||
|
|
||||||
return self_;
|
return self_;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE socket_bind (VALUE self_, VALUE addr_)
|
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_alloc_func (socket_type, socket_alloc);
|
||||||
rb_define_method (socket_type, "initialize",
|
rb_define_method (socket_type, "initialize",
|
||||||
(VALUE(*)(...)) socket_initialize, 2);
|
(VALUE(*)(...)) socket_initialize, 2);
|
||||||
// rb_define_method (socket_type, "setsockopt",
|
rb_define_method (socket_type, "setsockopt",
|
||||||
// (VALUE(*)(...)) socket_setsockopt, 2);
|
(VALUE(*)(...)) socket_setsockopt, 2);
|
||||||
rb_define_method (socket_type, "bind",
|
rb_define_method (socket_type, "bind",
|
||||||
(VALUE(*)(...)) socket_bind, 1);
|
(VALUE(*)(...)) socket_bind, 1);
|
||||||
rb_define_method (socket_type, "connect",
|
rb_define_method (socket_type, "connect",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user