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

zmq_error used from ruby binding

parent 551fa104
......@@ -18,7 +18,6 @@
*/
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <ruby.h>
......@@ -44,7 +43,7 @@ static VALUE context_initialize (VALUE self_, VALUE app_threads_,
void *ctx = zmq_init (NUM2INT (app_threads_), NUM2INT (io_threads_),
NUM2INT (flags_));
if (!ctx) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
......@@ -76,7 +75,7 @@ static VALUE socket_initialize (VALUE self_, VALUE context_, VALUE type_)
void *s = zmq_socket (DATA_PTR (context_), NUM2INT (type_));
if (!s) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
......@@ -118,12 +117,12 @@ static VALUE socket_setsockopt (VALUE self_, VALUE option_,
break;
default:
rc = -1;
errno = EINVAL;
rb_raise (rb_eRuntimeError, zmq_strerror (EINVAL));
return Qnil;
}
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
......@@ -137,7 +136,7 @@ static VALUE socket_bind (VALUE self_, VALUE addr_)
int rc = zmq_bind (DATA_PTR (self_), rb_string_value_cstr (&addr_));
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
......@@ -150,7 +149,7 @@ static VALUE socket_connect (VALUE self_, VALUE addr_)
int rc = zmq_connect (DATA_PTR (self_), rb_string_value_cstr (&addr_));
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
......@@ -166,20 +165,20 @@ static VALUE socket_send (VALUE self_, VALUE msg_, VALUE flags_)
zmq_msg_t msg;
int rc = zmq_msg_init_size (&msg, RSTRING_LEN (msg_));
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
memcpy (zmq_msg_data (&msg), RSTRING_PTR (msg_), RSTRING_LEN (msg_));
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);
assert (rc == 0);
return Qfalse;
}
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
rc = zmq_msg_close (&msg);
assert (rc == 0);
return Qnil;
......@@ -196,7 +195,7 @@ static VALUE socket_flush (VALUE self_)
int rc = zmq_flush (DATA_PTR (self_));
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
return Qnil;
}
......@@ -212,14 +211,14 @@ static VALUE socket_recv (VALUE self_, VALUE flags_)
assert (rc == 0);
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);
assert (rc == 0);
return Qnil;
}
if (rc != 0) {
rb_raise (rb_eRuntimeError, zmq_strerror (errno));
rb_raise (rb_eRuntimeError, zmq_strerror (zmq_errno ()));
rc = zmq_msg_close (&msg);
assert (rc == 0);
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