88static VALUE rb_czmq_nogvl_beacon_destroy (void * ptr )
99{
1010 zmq_beacon_wrapper * beacon = ptr ;
11+
1112 if (beacon -> beacon ) {
12- zbeacon_destroy (& beacon -> beacon );
13+ zactor_destroy (& beacon -> beacon );
1314 beacon -> beacon = NULL ;
1415 }
16+
17+ if (beacon -> hostname ) {
18+ zstr_free (& beacon -> hostname );
19+ }
1520 return Qnil ;
1621}
1722
@@ -36,8 +41,16 @@ static void rb_czmq_free_beacon_gc(void *ptr)
3641*/
3742static VALUE rb_czmq_nogvl_new_beacon (void * ptr )
3843{
39- int port = (int )ptr ;
40- return (VALUE )zbeacon_new (port );
44+ zmq_beacon_wrapper * beacon = ptr ;
45+
46+ beacon -> beacon = zactor_new (zbeacon , NULL );
47+ beacon -> interval = 1000 ;
48+
49+ zsock_send (beacon -> beacon , "si" , "CONFIGURE" , beacon -> port );
50+ beacon -> hostname = zstr_recv (beacon -> beacon );
51+ assert (beacon -> hostname != NULL );
52+
53+ return Qnil ;
4154}
4255
4356/*
@@ -53,11 +66,12 @@ static VALUE rb_czmq_nogvl_new_beacon(void *ptr)
5366static VALUE rb_czmq_beacon_s_new (VALUE beacon , VALUE port )
5467{
5568 zmq_beacon_wrapper * bcn = NULL ;
56- int prt ;
5769 Check_Type (port , T_FIXNUM );
5870 beacon = Data_Make_Struct (rb_cZmqBeacon , zmq_beacon_wrapper , 0 , rb_czmq_free_beacon_gc , bcn );
59- prt = FIX2INT (port );
60- bcn -> beacon = (zbeacon_t * )rb_thread_call_without_gvl (rb_czmq_nogvl_new_beacon , (void * )prt , RUBY_UBF_IO , 0 );
71+ bcn -> port = FIX2INT (port );
72+ if (bcn -> port == 0 )
73+ rb_raise (rb_eArgError , "port must not be zero!" );
74+ rb_thread_call_without_gvl (rb_czmq_nogvl_new_beacon , (void * )bcn , RUBY_UBF_IO , 0 );
6175 ZmqAssertObjOnAlloc (bcn -> beacon , bcn );
6276 rb_obj_call_init (beacon , 0 , NULL );
6377 return beacon ;
@@ -94,20 +108,7 @@ static VALUE rb_czmq_beacon_destroy(VALUE obj)
94108static VALUE rb_czmq_beacon_hostname (VALUE obj )
95109{
96110 GetZmqBeacon (obj );
97- return rb_str_new2 (zbeacon_hostname (beacon -> beacon ));
98- }
99-
100- /*
101- * :nodoc:
102- * Set the beacon broadcast interval while the GIL is released.
103- *
104- */
105- static VALUE rb_czmq_nogvl_set_interval (void * ptr )
106- {
107- struct nogvl_beacon_interval_args * args = ptr ;
108- zmq_beacon_wrapper * beacon = args -> beacon ;
109- zbeacon_set_interval (beacon -> beacon , args -> interval );
110- return Qnil ;
111+ return rb_str_new2 (beacon -> hostname );
111112}
112113
113114/*
@@ -125,21 +126,7 @@ static VALUE rb_czmq_beacon_set_interval(VALUE obj, VALUE interval)
125126 struct nogvl_beacon_interval_args args ;
126127 GetZmqBeacon (obj );
127128 Check_Type (interval , T_FIXNUM );
128- args .beacon = beacon ;
129- args .interval = FIX2INT (interval );
130- rb_thread_call_without_gvl (rb_czmq_nogvl_set_interval , (void * )& args , RUBY_UBF_IO , 0 );
131- return Qnil ;
132- }
133-
134- /*
135- * :nodoc:
136- * Filter beacons while the GIL is released.
137- *
138- */
139- static VALUE rb_czmq_nogvl_noecho (void * ptr )
140- {
141- zmq_beacon_wrapper * beacon = ptr ;
142- zbeacon_noecho (beacon -> beacon );
129+ beacon -> interval = FIX2INT (interval );
143130 return Qnil ;
144131}
145132
@@ -156,7 +143,7 @@ static VALUE rb_czmq_nogvl_noecho(void *ptr)
156143static VALUE rb_czmq_beacon_noecho (VALUE obj )
157144{
158145 GetZmqBeacon (obj );
159- rb_thread_call_without_gvl ( rb_czmq_nogvl_noecho , ( void * ) beacon , RUBY_UBF_IO , 0 );
146+ /* XXX: Nothing to do here, as v3 always filters out our own message */
160147 return Qnil ;
161148}
162149
@@ -169,7 +156,8 @@ static VALUE rb_czmq_nogvl_publish(void *ptr)
169156{
170157 struct nogvl_beacon_publish_args * args = ptr ;
171158 zmq_beacon_wrapper * beacon = args -> beacon ;
172- zbeacon_publish (beacon -> beacon , (byte * )args -> transmit ,args -> length );
159+ zsock_send (beacon -> beacon , "sbi" , "PUBLISH" , (byte * )args -> transmit ,
160+ args -> length , beacon -> interval );
173161 return Qnil ;
174162}
175163
@@ -203,7 +191,7 @@ static VALUE rb_czmq_beacon_publish(VALUE obj, VALUE transmit)
203191static VALUE rb_czmq_nogvl_silence (void * ptr )
204192{
205193 zmq_beacon_wrapper * beacon = ptr ;
206- zbeacon_silence (beacon -> beacon );
194+ zstr_sendx (beacon -> beacon , "SILENCE" , NULL );
207195 return Qnil ;
208196}
209197
@@ -233,7 +221,8 @@ static VALUE rb_czmq_nogvl_subscribe(void *ptr)
233221{
234222 struct nogvl_beacon_subscribe_args * args = ptr ;
235223 zmq_beacon_wrapper * beacon = args -> beacon ;
236- zbeacon_subscribe (beacon -> beacon , (byte * )args -> filter ,args -> length );
224+ zsock_send (beacon -> beacon , "sb" , "SUBSCRIBE" , (byte * )args -> filter ,
225+ args -> length );
237226 return Qnil ;
238227}
239228
@@ -272,7 +261,7 @@ static VALUE rb_czmq_beacon_subscribe(VALUE obj, VALUE filter)
272261static VALUE rb_czmq_nogvl_unsubscribe (void * ptr )
273262{
274263 zmq_beacon_wrapper * beacon = ptr ;
275- zbeacon_unsubscribe (beacon -> beacon );
264+ zstr_sendx (beacon -> beacon , "UNSUBSCRIBE" , NULL );
276265 return Qnil ;
277266}
278267
@@ -298,7 +287,7 @@ static VALUE rb_czmq_beacon_pipe(VALUE obj)
298287 zmq_sock_wrapper * sock = NULL ;
299288 VALUE socket ;
300289 GetZmqBeacon (obj );
301- socket = rb_czmq_socket_alloc (Qnil , NULL , zbeacon_socket (beacon -> beacon ));
290+ socket = rb_czmq_socket_alloc (Qnil , NULL , zsock_resolve (beacon -> beacon ));
302291 GetZmqSocket (socket );
303292 sock -> state = ZMQ_SOCKET_BOUND ;
304293 return socket ;
0 commit comments