Class: ZMQ::Beacon
- Inherits:
-
Object
- Object
- ZMQ::Beacon
- Defined in:
- ext/rbczmq/beacon.c
Class Method Summary collapse
-
.ZMQ::Beacon.new(9999) ⇒ ZMQ::Beacon
Create a new beacon.
Instance Method Summary collapse
-
#destroy ⇒ nil
Stop broadcasting a beacon.
-
#hostname ⇒ String
Returns the beacon’s IP address.
-
#interval=(100) ⇒ nil
Sets the broadcast interval in milliseconds.
-
#noecho ⇒ nil
Filter out any beacon that looks exactly like ours.
- #pipe ⇒ Object
-
#publish("address") ⇒ nil
Start broadcasting beacon to peers.
-
#silence ⇒ nil
Stop broadcasting beacons to peers.
-
#subscribe("channel") ⇒ nil
Start listening to other peers.
-
#unsubscribe ⇒ nil
Stop broadcasting beacons to peers.
Class Method Details
.ZMQ::Beacon.new(9999) ⇒ ZMQ::Beacon
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'ext/rbczmq/beacon.c', line 53
static VALUE rb_czmq_beacon_s_new(VALUE beacon, VALUE port)
{
zmq_beacon_wrapper *bcn = NULL;
int prt;
Check_Type(port, T_FIXNUM);
beacon = Data_Make_Struct(rb_cZmqBeacon, zmq_beacon_wrapper, 0, rb_czmq_free_beacon_gc, bcn);
prt = FIX2INT(port);
bcn->beacon = (zbeacon_t*)rb_thread_call_without_gvl(rb_czmq_nogvl_new_beacon, (void *)prt, RUBY_UBF_IO, 0);
ZmqAssertObjOnAlloc(bcn->beacon, bcn);
rb_obj_call_init(beacon, 0, NULL);
return beacon;
}
|
Instance Method Details
#destroy ⇒ nil
Stop broadcasting a beacon. The GC will take the same action if a beacon object is not reachable anymore on the next GC cycle. This is a lower level API.
Examples
beacon.destroy => nil
77 78 79 80 81 82 |
# File 'ext/rbczmq/beacon.c', line 77
static VALUE rb_czmq_beacon_destroy(VALUE obj)
{
GetZmqBeacon(obj);
rb_thread_call_without_gvl(rb_czmq_nogvl_beacon_destroy, beacon, RUBY_UBF_IO, 0);
return Qnil;
}
|
#hostname ⇒ String
Returns the beacon’s IP address
Examples
beacon.hostname => "127.0.0.1"
94 95 96 97 98 |
# File 'ext/rbczmq/beacon.c', line 94
static VALUE rb_czmq_beacon_hostname(VALUE obj)
{
GetZmqBeacon(obj);
return rb_str_new2(zbeacon_hostname(beacon->beacon));
}
|
#interval=(100) ⇒ nil
Sets the broadcast interval in milliseconds
Examples
beacon.interval = 100 => nil
123 124 125 126 127 128 129 130 131 132 |
# File 'ext/rbczmq/beacon.c', line 123
static VALUE rb_czmq_beacon_set_interval(VALUE obj, VALUE interval)
{
struct nogvl_beacon_interval_args args;
GetZmqBeacon(obj);
Check_Type(interval, T_FIXNUM);
args.beacon = beacon;
args.interval = FIX2INT(interval);
rb_thread_call_without_gvl(rb_czmq_nogvl_set_interval, (void *)&args, RUBY_UBF_IO, 0);
return Qnil;
}
|
#noecho ⇒ nil
Filter out any beacon that looks exactly like ours
Examples
beacon.noecho => nil
156 157 158 159 160 161 |
# File 'ext/rbczmq/beacon.c', line 156
static VALUE rb_czmq_beacon_noecho(VALUE obj)
{
GetZmqBeacon(obj);
rb_thread_call_without_gvl(rb_czmq_nogvl_noecho, (void *)beacon, RUBY_UBF_IO, 0);
return Qnil;
}
|
#pipe ⇒ Object
296 297 298 299 300 301 302 303 304 305 |
# File 'ext/rbczmq/beacon.c', line 296
static VALUE rb_czmq_beacon_pipe(VALUE obj)
{
zmq_sock_wrapper *sock = NULL;
VALUE socket;
GetZmqBeacon(obj);
socket = rb_czmq_socket_alloc(Qnil, NULL, zbeacon_socket(beacon->beacon));
GetZmqSocket(socket);
sock->state = ZMQ_SOCKET_BOUND;
return socket;
}
|
#publish("address") ⇒ nil
Start broadcasting beacon to peers.
Examples
beacon.publish("address") => nil
186 187 188 189 190 191 192 193 194 195 196 |
# File 'ext/rbczmq/beacon.c', line 186
static VALUE rb_czmq_beacon_publish(VALUE obj, VALUE transmit)
{
struct nogvl_beacon_publish_args args;
GetZmqBeacon(obj);
Check_Type(transmit, T_STRING);
args.beacon = beacon;
args.transmit = RSTRING_PTR(transmit);
args.length = (int)RSTRING_LEN(transmit);
rb_thread_call_without_gvl(rb_czmq_nogvl_publish, (void *)&args, RUBY_UBF_IO, 0);
return Qnil;
}
|
#silence ⇒ nil
Stop broadcasting beacons to peers.
Examples
beacon.silence => nil
220 221 222 223 224 225 |
# File 'ext/rbczmq/beacon.c', line 220
static VALUE rb_czmq_beacon_silence(VALUE obj)
{
GetZmqBeacon(obj);
rb_thread_call_without_gvl(rb_czmq_nogvl_silence, (void *)beacon, RUBY_UBF_IO, 0);
return Qnil;
}
|
#subscribe("channel") ⇒ nil
Start listening to other peers.
Examples
beacon.subscribe("channel") => nil
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'ext/rbczmq/beacon.c', line 250
static VALUE rb_czmq_beacon_subscribe(VALUE obj, VALUE filter)
{
struct nogvl_beacon_subscribe_args args;
GetZmqBeacon(obj);
args.beacon = beacon;
if (NIL_P(filter)) {
args.filter = NULL;
args.length = 0;
} else {
Check_Type(filter, T_STRING);
args.filter = RSTRING_PTR(filter);
args.length = (int)RSTRING_LEN(filter);
}
rb_thread_call_without_gvl(rb_czmq_nogvl_subscribe, (void *)&args, RUBY_UBF_IO, 0);
return Qnil;
}
|
#unsubscribe ⇒ nil
Stop broadcasting beacons to peers.
Examples
beacon.unsubscribe => nil
289 290 291 292 293 294 |
# File 'ext/rbczmq/beacon.c', line 289
static VALUE rb_czmq_beacon_unsubscribe(VALUE obj)
{
GetZmqBeacon(obj);
rb_thread_call_without_gvl(rb_czmq_nogvl_unsubscribe, (void *)beacon, RUBY_UBF_IO, 0);
return Qnil;
}
|