Skip to content
This repository
Browse code

tweak steffen's pull request so that the context will determine what …

…gets returned
  • Loading branch information...
commit 3ebcdd5003533b0e7a8819985fc9cc8a72884705 1 parent 46a114f
lestrrat authored
24  ZMQ-LibZMQ2/t/005_poll.t
@@ -20,9 +20,23 @@ subtest 'basic poll with fd' => sub {
20 20
                 }
21 21
             ], 1);
22 22
             ok $called, "callback called";
23  
-            ok(ref($rv) && ref($rv) eq 'ARRAY' && @$rv == 1 && $rv->[0] == $called,
24  
-               "zmq_poll returns an array ref indicating whether the callback was invoked");
25  
-        }, undef, "PollItem doesn't die";
  23
+            ok($rv,
  24
+               "zmq_poll returns a scalar ndicating whether the callback was invoked");
  25
+        }, undef, "PollItem (return scalar) doesn't die";
  26
+
  27
+        is exception {
  28
+            my $called = 0;
  29
+            my @rv = zmq_poll([
  30
+                {
  31
+                    fd       => fileno(STDOUT),
  32
+                    events   => ZMQ_POLLOUT,
  33
+                    callback => sub { $called++ }
  34
+                }
  35
+            ], 1);
  36
+            ok $called, "callback called";
  37
+            ok(@rv == 1 && $rv[0] == $called,
  38
+               "zmq_poll returns an array indicating whether the callback was invoked");
  39
+        }, undef, "PollItem (return array) doesn't die";
26 40
     }
27 41
 };
28 42
 
@@ -38,7 +52,7 @@ subtest 'poll with zmq sockets' => sub {
38 52
         zmq_connect($req[$_], "inproc://polltest$_") for 0..$n-1;
39 53
         zmq_send( $req[$_], "Test$_") for 0..$nsend-1;
40 54
 
41  
-        my $rv = zmq_poll([
  55
+        my @rv = zmq_poll([
42 56
             map {
43 57
                 my $x = $_;
44 58
                 +{
@@ -50,7 +64,7 @@ subtest 'poll with zmq sockets' => sub {
50 64
             (0..$n-1)
51 65
         ], 1);
52 66
         my $exp_rv = [((1) x $nsend), ((0) x ($n-$nsend))];
53  
-        is_deeply($rv, $exp_rv,
  67
+        is_deeply(\@rv, $exp_rv,
54 68
                   "zmq_poll returns an array ref indicating whether the callback was invoked");
55 69
     }, undef, "PollItem correctly handles callback";
56 70
 
51  ZMQ-LibZMQ2/xs/perl_libzmq2.xs
@@ -763,7 +763,7 @@ PerlLibzmq2_zmq_poll( list, timeout = 0 )
763 763
         int rv;
764 764
         int eventfired;
765 765
         AV *events_fired;
766  
-    CODE:
  766
+    PPCODE:
767 767
         list_len = av_len( list ) + 1;
768 768
         if (list_len <= 0) {
769 769
             XSRETURN(0);
@@ -829,37 +829,34 @@ PerlLibzmq2_zmq_poll( list, timeout = 0 )
829 829
 
830 830
         /* now call zmq_poll */
831 831
         rv = zmq_poll( pollitems, list_len, timeout );
832  
-        if (rv < 0) {
833  
-            SET_BANG;
834  
-            RETVAL = &PL_sv_undef;
835  
-        }
836  
-        else {
837  
-            events_fired = newAV();
838  
-            RETVAL = newRV_noinc((SV *)events_fired);
839  
-            av_fill(events_fired, list_len-1);
840  
-            for ( i = 0; i < list_len; i++ ) {
  832
+        SET_BANG;
  833
+
  834
+        for ( i = 0; i < list_len; i++ ) {
  835
+            if (GIMME_V == G_ARRAY) {
841 836
                 eventfired = (pollitems[i].revents & pollitems[i].events) ? 1 : 0;
842  
-                av_store(events_fired, i, newSViv(eventfired));
843  
-                if (pollitems[i].revents & pollitems[i].events) {
844  
-                    dSP;
845  
-                    ENTER;
846  
-                    SAVETMPS;
847  
-                    PUSHMARK(SP);
848  
-                    PUTBACK;
849  
-
850  
-                    call_sv( (SV*)callbacks[i], G_SCALAR );
851  
-                    SPAGAIN;
852  
-
853  
-                    PUTBACK;
854  
-                    FREETMPS;
855  
-                    LEAVE;
856  
-                }
  837
+                mXPUSHi(eventfired);
  838
+            }
  839
+            if (pollitems[i].revents & pollitems[i].events) {
  840
+                dSP;
  841
+                ENTER;
  842
+                SAVETMPS;
  843
+                PUSHMARK(SP);
  844
+                PUTBACK;
  845
+
  846
+                call_sv( (SV*)callbacks[i], G_SCALAR );
  847
+                SPAGAIN;
  848
+
  849
+                PUTBACK;
  850
+                FREETMPS;
  851
+                LEAVE;
857 852
             }
858 853
         }
  854
+
  855
+        if (GIMME_V == G_SCALAR) {
  856
+            mXPUSHi(rv);
  857
+        }
859 858
         Safefree(pollitems);
860 859
         Safefree(callbacks);
861  
-    OUTPUT:
862  
-        RETVAL
863 860
 
864 861
 int
865 862
 PerlLibzmq2_zmq_device( device, insocket, outsocket )

0 notes on commit 3ebcdd5

Please sign in to comment.
Something went wrong with that request. Please try again.