Commit 8980a985 authored by Martin Sustrik's avatar Martin Sustrik

zmq_error used from ruby binding

parent 551fa104
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
*/ */
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <ruby.h> #include <ruby.h>
...@@ -44,7 +43,7 @@ static VALUE context_initialize (VALUE self_, VALUE app_threads_, ...@@ -44,7 +43,7 @@ static VALUE context_initialize (VALUE self_, VALUE app_threads_,
void *ctx = zmq_init (NUM2INT (app_threads_), NUM2INT (io_threads_), void *ctx = zmq_init (NUM2INT (app_threads_), NUM2INT (io_threads_),
NUM2INT (flags_)); NUM2INT (flags_));
if (!ctx) { if (!ctx) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
...@@ -76,7 +75,7 @@ static VALUE socket_initialize (VALUE self_, VALUE context_, VALUE type_) ...@@ -76,7 +75,7 @@ static VALUE socket_initialize (VALUE self_, VALUE context_, VALUE type_)
void *s = zmq_socket (DATA_PTR (context_), NUM2INT (type_)); void *s = zmq_socket (DATA_PTR (context_), NUM2INT (type_));
if (!s) { if (!s) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
...@@ -118,12 +117,12 @@ static VALUE socket_setsockopt (VALUE self_, VALUE option_, ...@@ -118,12 +117,12 @@ static VALUE socket_setsockopt (VALUE self_, VALUE option_,
break; break;
default: default:
rc = -1; rb_raise (rb_eRuntimeError, zmq_strerror (EINVAL));
errno = EINVAL; return Qnil;
} }
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
...@@ -137,7 +136,7 @@ static VALUE socket_bind (VALUE self_, VALUE addr_) ...@@ -137,7 +136,7 @@ static VALUE socket_bind (VALUE self_, VALUE addr_)
int rc = zmq_bind (DATA_PTR (self_), rb_string_value_cstr (&addr_)); int rc = zmq_bind (DATA_PTR (self_), rb_string_value_cstr (&addr_));
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
...@@ -150,7 +149,7 @@ static VALUE socket_connect (VALUE self_, VALUE addr_) ...@@ -150,7 +149,7 @@ static VALUE socket_connect (VALUE self_, VALUE addr_)
int rc = zmq_connect (DATA_PTR (self_), rb_string_value_cstr (&addr_)); int rc = zmq_connect (DATA_PTR (self_), rb_string_value_cstr (&addr_));
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
...@@ -166,20 +165,20 @@ static VALUE socket_send (VALUE self_, VALUE msg_, VALUE flags_) ...@@ -166,20 +165,20 @@ static VALUE socket_send (VALUE self_, VALUE msg_, VALUE flags_)
zmq_msg_t msg; zmq_msg_t msg;
int rc = zmq_msg_init_size (&msg, RSTRING_LEN (msg_)); int rc = zmq_msg_init_size (&msg, RSTRING_LEN (msg_));
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
memcpy (zmq_msg_data (&msg), RSTRING_PTR (msg_), RSTRING_LEN (msg_)); memcpy (zmq_msg_data (&msg), RSTRING_PTR (msg_), RSTRING_LEN (msg_));
rc = zmq_send (DATA_PTR (self_), &msg, NUM2INT (flags_)); rc = zmq_send (DATA_PTR (self_), &msg, NUM2INT (flags_));
if (rc != 0 && errno == EAGAIN) { if (rc != 0 && zmq_errno () == EAGAIN) {
rc = zmq_msg_close (&msg); rc = zmq_msg_close (&msg);
assert (rc == 0); assert (rc == 0);
return Qfalse; return Qfalse;
} }
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
rc = zmq_msg_close (&msg); rc = zmq_msg_close (&msg);
assert (rc == 0); assert (rc == 0);
return Qnil; return Qnil;
...@@ -196,7 +195,7 @@ static VALUE socket_flush (VALUE self_) ...@@ -196,7 +195,7 @@ static VALUE socket_flush (VALUE self_)
int rc = zmq_flush (DATA_PTR (self_)); int rc = zmq_flush (DATA_PTR (self_));
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil; return Qnil;
} }
...@@ -212,14 +211,14 @@ static VALUE socket_recv (VALUE self_, VALUE flags_) ...@@ -212,14 +211,14 @@ static VALUE socket_recv (VALUE self_, VALUE flags_)
assert (rc == 0); assert (rc == 0);
rc = zmq_recv (DATA_PTR (self_), &msg, NUM2INT (flags_)); rc = zmq_recv (DATA_PTR (self_), &msg, NUM2INT (flags_));
if (rc != 0 && errno == EAGAIN) { if (rc != 0 && zmq_errno () == EAGAIN) {
rc = zmq_msg_close (&msg); rc = zmq_msg_close (&msg);
assert (rc == 0); assert (rc == 0);
return Qnil; return Qnil;
} }
if (rc != 0) { if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno)); rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
rc = zmq_msg_close (&msg); rc = zmq_msg_close (&msg);
assert (rc == 0); assert (rc == 0);
return Qnil; return Qnil;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment