zmq 2.0.9 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/rbzmq.c +277 -31
- metadata +3 -3
data/rbzmq.c
CHANGED
@@ -136,18 +136,25 @@ static VALUE context_initialize (int argc_, VALUE* argv_, VALUE self_)
|
|
136
136
|
* call-seq:
|
137
137
|
* zmq.close() -> nil
|
138
138
|
*
|
139
|
-
* Terminates the 0MQ context.
|
140
|
-
*
|
141
|
-
*
|
142
|
-
*
|
143
|
-
*
|
144
|
-
*
|
145
|
-
*
|
146
|
-
*
|
147
|
-
*
|
148
|
-
*
|
149
|
-
*
|
150
|
-
*
|
139
|
+
* Terminates the 0MQ context.
|
140
|
+
*
|
141
|
+
* Context termination is performed in the following steps:
|
142
|
+
*
|
143
|
+
* 1. Any blocking operations currently in progress on sockets open
|
144
|
+
* within context shall return immediately with an error code of
|
145
|
+
* ETERM. With the exception of ZMQ::Socket#close(), any further operations on
|
146
|
+
* sockets open within context shall fail with an error code of ETERM.
|
147
|
+
*
|
148
|
+
* 2. After interrupting all blocking calls, zmq_term() shall block until
|
149
|
+
* the following conditions are satisfied:
|
150
|
+
* * All sockets open within context have been closed with ZMQ::Socket#close().
|
151
|
+
* * For each socket within context, all messages sent by the
|
152
|
+
* application with ZMQ::Socket#send() have either been physically
|
153
|
+
* transferred to a network peer, or the socket’s linger period
|
154
|
+
* set with the ZMQ::LINGER socket option has expired.
|
155
|
+
*
|
156
|
+
* For further details regarding socket linger behaviour refer to the
|
157
|
+
* ZMQ::LINGER option in ZMQ::Socket#setsockopt().
|
151
158
|
*/
|
152
159
|
static VALUE context_close (VALUE self_)
|
153
160
|
{
|
@@ -556,36 +563,36 @@ static VALUE context_socket (VALUE self_, VALUE type_)
|
|
556
563
|
* is connected to at least one _node_. When a pipeline stage is connected to
|
557
564
|
* multiple _nodes_ data is load-balanced among all connected _nodes_.
|
558
565
|
*
|
559
|
-
* == ZMQ::
|
566
|
+
* == ZMQ::PUSH
|
560
567
|
*
|
561
|
-
* A socket of type ZMQ::
|
568
|
+
* A socket of type ZMQ::PUSH is used by a pipeline node to send messages
|
562
569
|
* to downstream pipeline nodes. Messages are load-balanced to all connected
|
563
570
|
* downstream nodes. The ZMQ::recv() function is not implemented for this socket
|
564
571
|
* type.
|
565
572
|
*
|
566
|
-
* When a ZMQ::
|
573
|
+
* When a ZMQ::PUSH socket enters an exceptional state due to having
|
567
574
|
* reached the high water mark for all downstream _nodes_, or if there are no
|
568
575
|
* downstream _nodes_ at all, then any send() operations on the socket shall
|
569
576
|
* block until the exceptional state ends or at least one downstream _node_
|
570
577
|
* becomes available for sending; messages are not discarded.
|
571
578
|
*
|
572
|
-
* === Summary of ZMQ::
|
573
|
-
* [Compatible peer sockets] ZMQ::
|
579
|
+
* === Summary of ZMQ::PUSH characteristics
|
580
|
+
* [Compatible peer sockets] ZMQ::PULL
|
574
581
|
* [Direction] Unidirectional
|
575
582
|
* [Send/receive pattern] Send only
|
576
583
|
* [Incoming routing strategy] N/A
|
577
584
|
* [Outgoing routing strategy] Load-balanced
|
578
585
|
* [ZMQ::HWM option action] Block
|
579
586
|
*
|
580
|
-
* == ZMQ::
|
587
|
+
* == ZMQ::PULL
|
581
588
|
*
|
582
|
-
* A socket of type ZMQ::
|
589
|
+
* A socket of type ZMQ::PULL is used by a pipeline _node_ to receive messages
|
583
590
|
* from upstream pipeline _nodes_. Messages are fair-queued from among all
|
584
591
|
* connected upstream nodes. The send() function is not implemented for
|
585
592
|
* this socket type.
|
586
593
|
*
|
587
|
-
* === Summary of ZMQ::
|
588
|
-
* [Compatible peer sockets] ZMQ::
|
594
|
+
* === Summary of ZMQ::PULL characteristics
|
595
|
+
* [Compatible peer sockets] ZMQ::PUSH
|
589
596
|
* [Direction] Unidirectional
|
590
597
|
* [Send/receive pattern] Receive only
|
591
598
|
* [Incoming routing strategy] Fair-queued
|
@@ -608,7 +615,7 @@ static VALUE context_socket (VALUE self_, VALUE type_)
|
|
608
615
|
* send() operations on the socket shall block until the peer becomes
|
609
616
|
* available for sending; messages are not discarded.
|
610
617
|
*
|
611
|
-
* *NOTE*
|
618
|
+
* *NOTE* ZMQ::PAIR sockets are experimental, and are currently missing several
|
612
619
|
* features such as auto-reconnection.
|
613
620
|
*
|
614
621
|
* === Summary of ZMQ::PAIR characteristics
|
@@ -773,6 +780,102 @@ static VALUE context_socket (VALUE self_, VALUE type_)
|
|
773
780
|
* [Default value] 0
|
774
781
|
* [Applicable socket types] all
|
775
782
|
*
|
783
|
+
* == ZMQ::LINGER: Retrieve linger period for socket shutdown
|
784
|
+
* The ZMQ::LINGER option shall retrieve the linger period for the specified
|
785
|
+
* socket. The linger period determines how long pending messages which have
|
786
|
+
* yet to be sent to a peer shall linger in memory after a socket is closed
|
787
|
+
* with ZMQ::Socket#close(), and further affects the termination of the
|
788
|
+
* socket’s context with ZMQ#close(). The following outlines the different
|
789
|
+
* behaviours:
|
790
|
+
*
|
791
|
+
* * The default value of −1 specifies an infinite linger period.
|
792
|
+
* Pending messages shall not be discarded after a call to ZMQ::Socket#close();
|
793
|
+
* attempting to terminate the socket’s context with ZMQ::Context#close() shall block
|
794
|
+
* until all pending messages have been sent to a peer.
|
795
|
+
*
|
796
|
+
* * The value of 0 specifies no linger period. Pending messages shall be
|
797
|
+
* discarded immediately when the socket is closed with ZMQ::Socket#close.
|
798
|
+
*
|
799
|
+
* * Positive values specify an upper bound for the linger period in
|
800
|
+
* milliseconds. Pending messages shall not be discarded after a call to
|
801
|
+
* ZMQ::Socket#close(); attempting to terminate the socket’s context with
|
802
|
+
* ZMQ::Context#close() shall block until either all pending messages have been sent
|
803
|
+
* to a peer, or the linger period expires, after which any pending messages
|
804
|
+
* shall be discarded.
|
805
|
+
*
|
806
|
+
* [Option value type] Integer
|
807
|
+
* [Option value unit] milliseconds
|
808
|
+
* [Default value] -1 (infinite)
|
809
|
+
* [Applicable socket types] all
|
810
|
+
*
|
811
|
+
* == ZMQ::RECONNECT_IVL: Retrieve reconnection interval
|
812
|
+
* The ZMQ::RECONNECT_IVL option shall retrieve the reconnection interval for
|
813
|
+
* the specified socket. The reconnection interval is the maximum period 0MQ
|
814
|
+
* shall wait between attempts to reconnect disconnected peers when using
|
815
|
+
* connection−oriented transports.
|
816
|
+
*
|
817
|
+
* [Option value type] Integer
|
818
|
+
* [Option value unit] milliseconds
|
819
|
+
* [Default value] 100
|
820
|
+
* [Applicable socket types] all, only for connection-oriented transports
|
821
|
+
*
|
822
|
+
* == ZMQ::BACKLOG: Retrieve maximum length of the queue of outstanding connections
|
823
|
+
* The ZMQ::BACKLOG option shall retrieve the maximum length of the queue of
|
824
|
+
* outstanding peer connections for the specified socket; this only applies to
|
825
|
+
* connection−oriented transports. For details refer to your operating system
|
826
|
+
* documentation for the listen function.
|
827
|
+
*
|
828
|
+
* [Option value type] Integer
|
829
|
+
* [Option value unit] connections
|
830
|
+
* [Default value] 100
|
831
|
+
* [Applicable socket types] all, only for connection-oriented transports
|
832
|
+
*
|
833
|
+
* == ZMQ::FD: Retrieve file descriptor associated with the socket
|
834
|
+
* The ZMQ::FD option shall retrieve the file descriptor associated with the
|
835
|
+
* specified socket. The returned file descriptor can be used to integrate the
|
836
|
+
* socket into an existing event loop; the 0MQ library shall signal any pending
|
837
|
+
* events on the socket in an edge−triggered fashion by making the file
|
838
|
+
* descriptor become ready for reading.
|
839
|
+
*
|
840
|
+
* === Note
|
841
|
+
* The ability to read from the returned file descriptor does not necessarily
|
842
|
+
* indicate that messages are available to be read from, or can be written to,
|
843
|
+
* the underlying socket; applications must retrieve the actual event state
|
844
|
+
* with a subsequent retrieval of the ZMQ::EVENTS option.
|
845
|
+
*
|
846
|
+
* === Caution
|
847
|
+
* The returned file descriptor is intended for use with a poll or similar
|
848
|
+
* system call only. Applications must never attempt to read or write data
|
849
|
+
* to it directly.
|
850
|
+
*
|
851
|
+
* [Option value type] int on POSIX systems, SOCKT on Windows
|
852
|
+
* [Option value unit] N/A
|
853
|
+
* [Default value] N/A
|
854
|
+
* [Applicable socket types] all
|
855
|
+
*
|
856
|
+
* == ZMQ::EVENTS: Retrieve socket event state
|
857
|
+
* The ZMQ::EVENTS option shall retrieve the event state for the specified
|
858
|
+
* socket. The returned value is a bit mask constructed by OR’ing a combination
|
859
|
+
* of the following event flags:
|
860
|
+
*
|
861
|
+
* === ZMQ::POLLIN
|
862
|
+
* Indicates that at least one message may be received from the specified
|
863
|
+
* socket without blocking.
|
864
|
+
*
|
865
|
+
* == ZMQ::POLLOUT
|
866
|
+
* Indicates that at least one message may be sent to the specified socket
|
867
|
+
* without blocking.
|
868
|
+
*
|
869
|
+
* The combination of a file descriptor returned by the ZMQ::FD option being
|
870
|
+
* ready for reading but no actual events returned by a subsequent retrieval of
|
871
|
+
* the ZMQ::EVENTS option is valid; applications should simply ignore this case
|
872
|
+
* and restart their polling operation/event loop.
|
873
|
+
*
|
874
|
+
* [Option value type] uint32_t
|
875
|
+
* [Option value unit] N/A (flags)
|
876
|
+
* [Default value] N/A
|
877
|
+
* [Applicable socket types] all
|
878
|
+
*
|
776
879
|
*/
|
777
880
|
static VALUE socket_getsockopt (VALUE self_, VALUE option_)
|
778
881
|
{
|
@@ -793,6 +896,72 @@ static VALUE socket_getsockopt (VALUE self_, VALUE option_)
|
|
793
896
|
case ZMQ_MCAST_LOOP:
|
794
897
|
case ZMQ_SNDBUF:
|
795
898
|
case ZMQ_RCVBUF:
|
899
|
+
#if ZMQ_VERSION >= 20100
|
900
|
+
case ZMQ_FD:
|
901
|
+
{
|
902
|
+
#ifdef _WIN32
|
903
|
+
SOCKET optval;
|
904
|
+
#else
|
905
|
+
int optval;
|
906
|
+
#endif
|
907
|
+
size_t optvalsize = sizeof(optval);
|
908
|
+
|
909
|
+
rc = zmq_getsockopt (s, NUM2INT (option_), (void *)&optval,
|
910
|
+
&optvalsize);
|
911
|
+
|
912
|
+
if (rc != 0) {
|
913
|
+
rb_raise (rb_eRuntimeError, "%s", zmq_strerror (zmq_errno ()));
|
914
|
+
return Qnil;
|
915
|
+
}
|
916
|
+
|
917
|
+
if (NUM2INT (option_) == ZMQ_RCVMORE)
|
918
|
+
retval = optval ? Qtrue : Qfalse;
|
919
|
+
else
|
920
|
+
retval = INT2NUM (optval);
|
921
|
+
}
|
922
|
+
break;
|
923
|
+
case ZMQ_EVENTS:
|
924
|
+
{
|
925
|
+
uint32_t optval;
|
926
|
+
size_t optvalsize = sizeof(optval);
|
927
|
+
|
928
|
+
rc = zmq_getsockopt (s, NUM2INT (option_), (void *)&optval,
|
929
|
+
&optvalsize);
|
930
|
+
|
931
|
+
if (rc != 0) {
|
932
|
+
rb_raise (rb_eRuntimeError, "%s", zmq_strerror (zmq_errno ()));
|
933
|
+
return Qnil;
|
934
|
+
}
|
935
|
+
|
936
|
+
if (NUM2INT (option_) == ZMQ_RCVMORE)
|
937
|
+
retval = optval ? Qtrue : Qfalse;
|
938
|
+
else
|
939
|
+
retval = INT2NUM (optval);
|
940
|
+
}
|
941
|
+
break;
|
942
|
+
case ZMQ_TYPE:
|
943
|
+
case ZMQ_LINGER:
|
944
|
+
case ZMQ_RECONNECT_IVL:
|
945
|
+
case ZMQ_BACKLOG:
|
946
|
+
{
|
947
|
+
int optval;
|
948
|
+
size_t optvalsize = sizeof(optval);
|
949
|
+
|
950
|
+
rc = zmq_getsockopt (s, NUM2INT (option_), (void *)&optval,
|
951
|
+
&optvalsize);
|
952
|
+
|
953
|
+
if (rc != 0) {
|
954
|
+
rb_raise (rb_eRuntimeError, "%s", zmq_strerror (zmq_errno ()));
|
955
|
+
return Qnil;
|
956
|
+
}
|
957
|
+
|
958
|
+
if (NUM2INT (option_) == ZMQ_RCVMORE)
|
959
|
+
retval = optval ? Qtrue : Qfalse;
|
960
|
+
else
|
961
|
+
retval = INT2NUM (optval);
|
962
|
+
}
|
963
|
+
break;
|
964
|
+
#endif
|
796
965
|
{
|
797
966
|
int64_t optval;
|
798
967
|
size_t optvalsize = sizeof(optval);
|
@@ -1003,6 +1172,56 @@ static VALUE socket_getsockopt (VALUE self_, VALUE option_)
|
|
1003
1172
|
* [Default value] 0
|
1004
1173
|
* [Applicable socket types] all
|
1005
1174
|
*
|
1175
|
+
* == ZMQ::LINGER: Set linger period for socket shutdown
|
1176
|
+
* The ZMQ::LINGER option shall set the linger period for the specified
|
1177
|
+
* socket. The linger period determines how long pending messages which have
|
1178
|
+
* yet to be sent to a peer shall linger in memory after a socket is closed
|
1179
|
+
* with ZMQ::Socket#close(), and further affects the termination of the
|
1180
|
+
* socket’s context with ZMQ#close(). The following outlines the different
|
1181
|
+
* behaviours:
|
1182
|
+
*
|
1183
|
+
* * The default value of −1 specifies an infinite linger period.
|
1184
|
+
* Pending messages shall not be discarded after a call to ZMQ::Socket#close();
|
1185
|
+
* attempting to terminate the socket’s context with ZMQ::Context#close() shall block
|
1186
|
+
* until all pending messages have been sent to a peer.
|
1187
|
+
*
|
1188
|
+
* * The value of 0 specifies no linger period. Pending messages shall be
|
1189
|
+
* discarded immediately when the socket is closed with ZMQ::Socket#close.
|
1190
|
+
*
|
1191
|
+
* * Positive values specify an upper bound for the linger period in
|
1192
|
+
* milliseconds. Pending messages shall not be discarded after a call to
|
1193
|
+
* ZMQ::Socket#close(); attempting to terminate the socket’s context with
|
1194
|
+
* ZMQ::Context#close() shall block until either all pending messages have been sent
|
1195
|
+
* to a peer, or the linger period expires, after which any pending messages
|
1196
|
+
* shall be discarded.
|
1197
|
+
*
|
1198
|
+
* [Option value type] Integer
|
1199
|
+
* [Option value unit] milliseconds
|
1200
|
+
* [Default value] -1 (infinite)
|
1201
|
+
* [Applicable socket types] all
|
1202
|
+
*
|
1203
|
+
* == ZMQ::RECONNECT_IVL: Set reconnection interval
|
1204
|
+
* The ZMQ::RECONNECT_IVL option shall set the reconnection interval for
|
1205
|
+
* the specified socket. The reconnection interval is the maximum period 0MQ
|
1206
|
+
* shall wait between attempts to reconnect disconnected peers when using
|
1207
|
+
* connection−oriented transports.
|
1208
|
+
*
|
1209
|
+
* [Option value type] Integer
|
1210
|
+
* [Option value unit] milliseconds
|
1211
|
+
* [Default value] 100
|
1212
|
+
* [Applicable socket types] all, only for connection-oriented transports
|
1213
|
+
*
|
1214
|
+
* == ZMQ::BACKLOG: Set maximum length of the queue of outstanding connections
|
1215
|
+
* The ZMQ::BACKLOG option shall set the maximum length of the queue of
|
1216
|
+
* outstanding peer connections for the specified socket; this only applies to
|
1217
|
+
* connection−oriented transports. For details refer to your operating system
|
1218
|
+
* documentation for the listen function.
|
1219
|
+
*
|
1220
|
+
* [Option value type] Integer
|
1221
|
+
* [Option value unit] connections
|
1222
|
+
* [Default value] 100
|
1223
|
+
* [Applicable socket types] all, only for connection-oriented transports
|
1224
|
+
*
|
1006
1225
|
*/
|
1007
1226
|
static VALUE socket_setsockopt (VALUE self_, VALUE option_,
|
1008
1227
|
VALUE optval_)
|
@@ -1023,14 +1242,28 @@ static VALUE socket_setsockopt (VALUE self_, VALUE option_,
|
|
1023
1242
|
case ZMQ_MCAST_LOOP:
|
1024
1243
|
case ZMQ_SNDBUF:
|
1025
1244
|
case ZMQ_RCVBUF:
|
1245
|
+
{
|
1246
|
+
uint64_t optval = FIX2LONG (optval_);
|
1247
|
+
|
1248
|
+
// Forward the code to native 0MQ library.
|
1249
|
+
rc = zmq_setsockopt (s, NUM2INT (option_),
|
1250
|
+
(void*) &optval, sizeof (optval));
|
1251
|
+
}
|
1252
|
+
break;
|
1253
|
+
|
1254
|
+
#if ZMQ_VERSION >= 20100
|
1255
|
+
case ZMQ_LINGER:
|
1256
|
+
case ZMQ_RECONNECT_IVL:
|
1257
|
+
case ZMQ_BACKLOG:
|
1026
1258
|
{
|
1027
|
-
|
1259
|
+
int optval = FIX2LONG (optval_);
|
1028
1260
|
|
1029
1261
|
// Forward the code to native 0MQ library.
|
1030
1262
|
rc = zmq_setsockopt (s, NUM2INT (option_),
|
1031
1263
|
(void*) &optval, sizeof (optval));
|
1032
1264
|
}
|
1033
1265
|
break;
|
1266
|
+
#endif
|
1034
1267
|
|
1035
1268
|
case ZMQ_IDENTITY:
|
1036
1269
|
case ZMQ_SUBSCRIBE:
|
@@ -1332,12 +1565,12 @@ static VALUE socket_recv (int argc_, VALUE* argv_, VALUE self_)
|
|
1332
1565
|
* call-seq:
|
1333
1566
|
* socket.close() -> nil
|
1334
1567
|
*
|
1335
|
-
* Destroys the 0MQ socket.
|
1336
|
-
*
|
1337
|
-
*
|
1338
|
-
*
|
1339
|
-
*
|
1340
|
-
*
|
1568
|
+
* Destroys the 0MQ socket. Any outstanding messages physically received from
|
1569
|
+
* the network but not yet received by the application with ZMQ::Socket#recv()
|
1570
|
+
* shall be discarded. The behaviour for discarding messages sent by the
|
1571
|
+
* application with ZMQ::Socket#send() but not yet physically transferred to
|
1572
|
+
* the network depends on the value of the ZMQ::LINGER socket option for the
|
1573
|
+
* socket.
|
1341
1574
|
*/
|
1342
1575
|
static VALUE socket_close (VALUE self_)
|
1343
1576
|
{
|
@@ -1391,6 +1624,14 @@ void Init_zmq ()
|
|
1391
1624
|
rb_define_const (zmq_module, "RCVBUF", INT2NUM (ZMQ_RCVBUF));
|
1392
1625
|
rb_define_const (zmq_module, "SNDMORE", INT2NUM (ZMQ_SNDMORE));
|
1393
1626
|
rb_define_const (zmq_module, "RCVMORE", INT2NUM (ZMQ_RCVMORE));
|
1627
|
+
#if ZMQ_VERSION >= 20100
|
1628
|
+
rb_define_const (zmq_module, "FD", INT2NUM (ZMQ_FD));
|
1629
|
+
rb_define_const (zmq_module, "EVENTS", INT2NUM (ZMQ_EVENTS));
|
1630
|
+
rb_define_const (zmq_module, "TYPE", INT2NUM (ZMQ_TYPE));
|
1631
|
+
rb_define_const (zmq_module, "LINGER", INT2NUM (ZMQ_LINGER));
|
1632
|
+
rb_define_const (zmq_module, "RECONNECT_IVL", INT2NUM (ZMQ_RECONNECT_IVL));
|
1633
|
+
rb_define_const (zmq_module, "BACKLOG", INT2NUM (ZMQ_BACKLOG));
|
1634
|
+
#endif
|
1394
1635
|
|
1395
1636
|
rb_define_const (zmq_module, "NOBLOCK", INT2NUM (ZMQ_NOBLOCK));
|
1396
1637
|
|
@@ -1405,12 +1646,17 @@ void Init_zmq ()
|
|
1405
1646
|
#ifdef ZMQ_PUSH
|
1406
1647
|
rb_define_const (zmq_module, "PUSH", INT2NUM (ZMQ_PUSH));
|
1407
1648
|
rb_define_const (zmq_module, "PULL", INT2NUM (ZMQ_PULL));
|
1649
|
+
|
1650
|
+
// Deprecated
|
1651
|
+
rb_define_const (zmq_module, "UPSTREAM", INT2NUM (ZMQ_PULL));
|
1652
|
+
rb_define_const (zmq_module, "DOWNSTREAM", INT2NUM (ZMQ_PUSH));
|
1408
1653
|
#else
|
1409
1654
|
rb_define_const (zmq_module, "PUSH", INT2NUM (ZMQ_DOWNSTREAM));
|
1410
1655
|
rb_define_const (zmq_module, "PULL", INT2NUM (ZMQ_UPSTREAM));
|
1411
|
-
#endif
|
1412
1656
|
|
1413
|
-
//
|
1657
|
+
// Deprecated
|
1414
1658
|
rb_define_const (zmq_module, "UPSTREAM", INT2NUM (ZMQ_UPSTREAM));
|
1415
1659
|
rb_define_const (zmq_module, "DOWNSTREAM", INT2NUM (ZMQ_DOWNSTREAM));
|
1660
|
+
#endif
|
1661
|
+
|
1416
1662
|
}
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 2.0.9
|
9
|
+
version: 2.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Martin Sustrik
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-05 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|