Michael Granger avatar Michael Granger committed b9bed47

Fix return-code check to be compatible with 3.x.

Also modify the error-checking to only raise ZMQ::Errors
on zmq-specific errors. All others use rb_sys_fail() so
they're rescuable. EAGAIN errors no longer return +nil+;
they are raised as Error::EAGAIN so non-blocking code
can handle the case via poll+retry.

Comments (0)

Files changed (2)

         }
         break;
 
+#ifdef ZMQ_LAST_ENDPOINT
 	case ZMQ_LAST_ENDPOINT:
 		{
             char endpoint[4096];
 
             retval = rb_str_new (endpoint, optvalsize);
 		}
+#endif
+
     default:
         rb_raise (exception_type, "%s", zmq_strerror (EINVAL));
         return Qnil;
  * [_tcp_] unicast transport using TCP
  * [_pgm_, _epgm_] reliable multicast transport using PGM
  *
- * With the exception of ZMQ:PAIR sockets, a single socket may be connected to
+ * With the exception of ZMQ::PAIR sockets, a single socket may be connected to
  * multiple endpoints using connect(), while simultaneously accepting
  * incoming connections from multiple endpoints bound to the socket using
  * bind(). Refer to ZMQ::Socket for a description of the exact semantics
     else
 #endif
         rc = zmq_msg_send (&msg, s->socket, flags);
-    if (rc != 0 && zmq_errno () == EAGAIN) {
+
+    if (rc == -1) {
+        int err = zmq_errno();
+        const char *errmsg = zmq_strerror( err );
+
         rc = zmq_msg_close (&msg);
         assert (rc == 0);
-        return Qfalse;
-    }
 
-    if (rc != 0) {
-        rb_raise (exception_type, "%s", zmq_strerror (zmq_errno ()));
-        rc = zmq_msg_close (&msg);
-        assert (rc == 0);
+        if ( err >= ZMQ_HAUSNUMERO )
+            rb_raise (exception_type, "%s", errmsg );
+        else
+            rb_sys_fail( "#send" );
+
         return Qnil;
     }
 
     else
 #endif
         rc = zmq_msg_recv (&msg, s->socket, flags);
-    if (rc != 0 && zmq_errno () == EAGAIN) {
+
+    if (rc == -1) {
+        int err = zmq_errno();
+        const char *errmsg = zmq_strerror( err );
+
         rc = zmq_msg_close (&msg);
         assert (rc == 0);
-        return Qnil;
-    }
 
-    if (rc != 0) {
-        rb_raise (exception_type, "%s", zmq_strerror (zmq_errno ()));
-        rc = zmq_msg_close (&msg);
-        assert (rc == 0);
+        if ( err >= ZMQ_HAUSNUMERO )
+            rb_raise (exception_type, "%s", errmsg );
+        else
+            rb_sys_fail( "#recv" );
+
         return Qnil;
     }
 
 		rval = ZMQ.select( nil, [sock2], nil, 0.2 )
 		rval.should == [ [], [sock2], [] ]
 
-		sock2.send( "Hi!" )
+		sock2.send( "Hi!" ).should be_true()
 		
 		rval = ZMQ.select( [sock1,sock2], nil, nil, 0.2 )
 		rval.should == [ [sock1], [], [] ]
 
-		sock1.recv
+		sock1.recv.should == 'Hi!'
 
 		sock1.close
 		sock2.close
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.