dnssd 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c8d81b701b90525df7e2bc543879262595b7a36
4
- data.tar.gz: b329dcb5c3f3dd2aceb00c042303bd4311009983
3
+ metadata.gz: 989de29f15226a63499239537281158c788cc147
4
+ data.tar.gz: fe66a76c883a56f1ebb721278dc54104d84882b8
5
5
  SHA512:
6
- metadata.gz: c3e53069b168de693d9d3d46dff6697fe091092b635f4e5961d3819bc200a6349d3a2a8b292f4db7d107f9e88179e7f68b9d41ab52a5378580066c58ee1023ac
7
- data.tar.gz: 8f57f4190921acb814e3e74a86ddde676cf717b1807197661ccc406295f121c78ea522a7300df3869045286c3e9b7086befb532efe1483ba3c0df36ab8042636
6
+ metadata.gz: a3705b02794e1ca31da502189668bb71789d80f78d421277a99eeda3d86ae6b56f0f1b83e941516c232db85757ddd8bcb5c757f779cd0769168c9cca2cfd5af3
7
+ data.tar.gz: 8b8a09dab0888f3f4a27e72c59f6963db0274c69c6cf7b07991f8c5556201d2c951cf3a304b8c88daf7a58e50c88539d5d08aff32407176837522df82ef0b272
data/README.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  = dnssd
2
2
 
3
- * http://rubyforge.org/projects/dnssd
4
- * http://github.com/tenderlove/dnssd
3
+ * https://github.com/tenderlove/dnssd
4
+ * http://docs.seattlerb.org/dnssd
5
5
  * http://developer.apple.com/documentation/Networking/Conceptual/dns_discovery_api/Introduction.html
6
6
 
7
7
  == DESCRIPTION:
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ Hoe.plugin :compiler
10
10
 
11
11
  HOE = Hoe.spec 'dnssd' do
12
12
  developer 'Eric Hodel', 'drbrain@segment.net'
13
- developer 'Aaron Patterson', 'aaronp@rubyforge.org'
13
+ developer 'Aaron Patterson', 'aaron.patterson@gmail.com'
14
14
  developer 'Phil Hagelberg', 'phil@hagelb.org'
15
15
  developer 'Chad Fowler', 'chad@chadfowler.com'
16
16
  developer 'Charles Mills', ''
@@ -19,6 +19,11 @@ HOE = Hoe.spec 'dnssd' do
19
19
  rdoc_locations << 'docs.seattlerb.org:/data/www/docs.seattlerb.org/dnssd/'
20
20
 
21
21
  clean_globs << 'lib/dnssd/*.{so,bundle,dll}'
22
+
23
+ self.spec_extras = {
24
+ :extensions => ["ext/dnssd/extconf.rb"],
25
+ :required_ruby_version => '>= 2.1.0'
26
+ }
22
27
  end
23
28
 
24
29
  # vim: syntax=Ruby
@@ -5,37 +5,6 @@ void Init_DNSSD_Flags(void);
5
5
  void Init_DNSSD_Record(void);
6
6
  void Init_DNSSD_Service(void);
7
7
 
8
- /*
9
- * call-seq:
10
- * DNSSD.getservbyport(port, proto = nil) => service_name
11
- *
12
- * Wrapper for getservbyport(3) - returns the service name for +port+.
13
- *
14
- * DNSSD.getservbyport 1025 # => 'blackjack'
15
- */
16
-
17
- static VALUE
18
- dnssd_getservbyport(int argc, VALUE * argv, VALUE self) {
19
- VALUE _port, _proto;
20
- struct servent * result;
21
- int port;
22
- char * proto = NULL;
23
-
24
- rb_scan_args(argc, argv, "11", &_port, &_proto);
25
-
26
- port = htons(FIX2INT(_port));
27
-
28
- if (RTEST(_proto))
29
- proto = StringValueCStr(_proto);
30
-
31
- result = getservbyport(port, proto);
32
-
33
- if (result == NULL)
34
- return Qnil;
35
-
36
- return rb_str_new2(result->s_name);
37
- }
38
-
39
8
  /*
40
9
  * call-seq:
41
10
  * DNSSD.interface_name(interface_index) # => interface_name
@@ -89,8 +58,6 @@ Init_dnssd(void) {
89
58
  ULONG2NUM(kDNSServiceInterfaceIndexUnicast));
90
59
  #endif
91
60
 
92
- rb_define_singleton_method(mDNSSD, "getservbyport", dnssd_getservbyport, -1);
93
-
94
61
  rb_define_singleton_method(mDNSSD, "interface_index", dnssd_if_nametoindex, 1);
95
62
  rb_define_singleton_method(mDNSSD, "interface_name", dnssd_if_indextoname, 1);
96
63
 
@@ -23,7 +23,6 @@
23
23
  #define SIN_LEN(si) sizeof(struct sockaddr_in)
24
24
  #endif
25
25
 
26
- #ifdef HAVE_RUBY_ENCODING_H
27
26
  #include <ruby/encoding.h>
28
27
  #define dnssd_utf8_cstr(str, to) \
29
28
  do {\
@@ -32,11 +31,6 @@
32
31
  0, Qnil);\
33
32
  to = StringValueCStr(utf8);\
34
33
  } while (0)
35
- #else
36
- #define dnssd_utf8_cstr(str, to) \
37
- do { to = StringValueCStr(str); } while (0)
38
- #define rb_enc_associate(a, b) do {} while (0)
39
- #endif
40
34
 
41
35
  extern VALUE eDNSSDError;
42
36
 
@@ -45,13 +45,6 @@ else
45
45
  abort('unable to find if_indextoname or if_nametoindex')
46
46
  end
47
47
 
48
- # HACK prefer Socket.getservbyport in 1.9
49
- have_func('getservbyport', 'netdb.h') ||
50
- abort('unable to find getservbyport')
51
-
52
- have_func('rb_thread_fd_select', 'ruby/intern.h') ||
53
- abort('unable to find rb_thread_fd_select, your ruby is too old')
54
-
55
48
  have_type('struct sockaddr_in', 'netinet/in.h') ||
56
49
  abort('unable to find struct sockaddr_in')
57
50
 
@@ -79,4 +72,3 @@ have_header 'ruby/encoding.h'
79
72
 
80
73
  puts
81
74
  create_makefile 'dnssd/dnssd'
82
-
@@ -10,6 +10,7 @@ static VALUE cDNSSDReplyQueryRecord;
10
10
  static VALUE cDNSSDReplyRegister;
11
11
  static VALUE cDNSSDReplyResolve;
12
12
  static VALUE cDNSSDService;
13
+ static VALUE cDNSSDServiceRegister;
13
14
  static VALUE cDNSSDTextRecord;
14
15
  static VALUE rb_cSocket;
15
16
 
@@ -23,23 +24,6 @@ static ID dnssd_iv_service;
23
24
  static ID dnssd_iv_thread;
24
25
  static ID dnssd_iv_type;
25
26
 
26
- #define get(klass, obj, type, var) \
27
- do {\
28
- Check_Type(obj, T_DATA);\
29
- if (rb_obj_is_kind_of(obj, klass) != Qtrue)\
30
- rb_raise(rb_eTypeError,\
31
- "wrong argument type %s",\
32
- rb_class2name(CLASS_OF(obj)));\
33
- Data_Get_Struct(obj, type, var);\
34
- } while (0)
35
-
36
- static void
37
- dnssd_service_callback(VALUE self, VALUE reply) {
38
- VALUE replies = rb_ivar_get(self, dnssd_iv_replies);
39
-
40
- rb_funcall(replies, dnssd_id_push, 1, reply);
41
- }
42
-
43
27
  static void
44
28
  dnssd_service_free_client(DNSServiceRef *client) {
45
29
  if (*client) {
@@ -58,6 +42,25 @@ dnssd_service_free(void *ptr) {
58
42
  free(client);
59
43
  }
60
44
 
45
+ static const rb_data_type_t dnssd_service_type = {
46
+ "DNSSD/service",
47
+ {0, dnssd_service_free, 0,},
48
+ 0, 0,
49
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
50
+ RUBY_TYPED_FREE_IMMEDIATELY,
51
+ #endif
52
+ };
53
+
54
+ #define get(klass, obj, type, var) \
55
+ do {\
56
+ Check_Type(obj, T_DATA);\
57
+ if (rb_obj_is_kind_of(obj, klass) != Qtrue)\
58
+ rb_raise(rb_eTypeError,\
59
+ "wrong argument type %s",\
60
+ rb_class2name(CLASS_OF(obj)));\
61
+ Data_Get_Struct(obj, type, var);\
62
+ } while (0)
63
+
61
64
  static VALUE
62
65
  create_fullname(const char *name, const char *regtype,
63
66
  const char *domain) {
@@ -145,21 +148,6 @@ dnssd_service_s_allocate(VALUE klass) {
145
148
  return Data_Wrap_Struct(klass, 0, dnssd_service_free, client);
146
149
  }
147
150
 
148
- /* Returns true if the service has been stopped.
149
- */
150
-
151
- static VALUE
152
- dnssd_service_stopped_p(VALUE self) {
153
- DNSServiceRef *client;
154
-
155
- get(cDNSSDService, self, DNSServiceRef, client);
156
-
157
- if (client)
158
- return (*client) == NULL ? Qtrue : Qfalse;
159
-
160
- return Qtrue;
161
- }
162
-
163
151
  /* Stops the service, closing the underlying socket and killing the underlying
164
152
  * thread.
165
153
  *
@@ -174,84 +162,33 @@ dnssd_service_stopped_p(VALUE self) {
174
162
 
175
163
  static VALUE
176
164
  dnssd_service_stop(VALUE self) {
177
- VALUE thread;
178
165
  DNSServiceRef *client;
179
166
 
180
- get(cDNSSDService, self, DNSServiceRef, client);
181
-
182
- RDATA(self)->data = NULL;
183
-
184
- if (client == NULL)
185
- rb_raise(eDNSSDError, "service is already stopped");
186
-
187
- thread = rb_ivar_get(self, dnssd_iv_thread);
188
- rb_ivar_set(self, dnssd_iv_continue, Qfalse);
189
-
190
- if (!NIL_P(thread) && thread != rb_thread_current()) {
191
- rb_thread_run(thread);
192
- rb_funcall(thread, dnssd_id_join, 0);
193
- }
167
+ TypedData_Get_Struct(self, DNSServiceRef, &dnssd_service_type, client);
194
168
 
195
169
  dnssd_service_free_client(client);
196
170
 
197
- rb_ivar_set(self, dnssd_iv_type, Qnil);
198
-
199
171
  return self;
200
172
  }
201
173
 
202
- /* Binding to DNSServiceProcessResult
203
- *
204
- * When run with a single thread _process will block.
205
- *
206
- * _process works intelligently with threads. If a service is waiting on data
207
- * from the daemon in a thread you can force _process to abort by setting
208
- * @continue to false and running the thread.
209
- */
210
-
211
174
  static VALUE
212
- dnssd_service_process(VALUE self) {
175
+ dnssd_ref_sock_fd(VALUE self) {
213
176
  DNSServiceRef *client;
214
- int dnssd_fd, result;
215
- rb_fdset_t read;
216
- struct timeval timeout;
217
-
218
- get(cDNSSDService, self, DNSServiceRef, client);
219
-
220
- if (client == NULL) {
221
- /* looks like this thread has already been stopped */
222
- return Qnil;
223
- }
224
-
225
- dnssd_fd = DNSServiceRefSockFD(*client);
226
-
227
- if (-1 == dnssd_fd)
228
- rb_raise(eDNSSDError, "unable to get DNSSD FD for result processing");
229
-
230
- timeout.tv_sec = 0;
231
- timeout.tv_usec = 10000;
232
-
233
- rb_fd_init(&read);
177
+ TypedData_Get_Struct(self, DNSServiceRef, &dnssd_service_type, client);
234
178
 
235
- retry:
236
- rb_fd_zero(&read);
237
- rb_fd_set(dnssd_fd, &read);
238
-
239
- result = rb_thread_fd_select(dnssd_fd + 1, &read, NULL, NULL, &timeout);
240
-
241
- if (result == -1)
242
- rb_sys_fail("select");
243
-
244
- if (rb_ivar_get(self, dnssd_iv_continue) == Qfalse)
245
- return Qnil;
179
+ return INT2NUM(DNSServiceRefSockFD(*client));
180
+ }
246
181
 
247
- /* timeout */
248
- if (result == 0)
249
- goto retry;
182
+ static VALUE
183
+ dnssd_process_result(VALUE self) {
184
+ DNSServiceRef *client;
185
+ DNSServiceErrorType e;
186
+ TypedData_Get_Struct(self, DNSServiceRef, &dnssd_service_type, client);
250
187
 
251
- DNSServiceErrorType e = DNSServiceProcessResult(*client);
188
+ e = DNSServiceProcessResult(*client);
252
189
  dnssd_check_error_code(e);
253
190
 
254
- return self;
191
+ return Qtrue;
255
192
  }
256
193
 
257
194
  /* call-seq:
@@ -277,10 +214,10 @@ dnssd_service_add_record(VALUE self, VALUE _flags, VALUE _rrtype, VALUE _rdata,
277
214
  flags = (DNSServiceFlags)NUM2ULONG(_flags);
278
215
  rrtype = NUM2UINT(_rrtype);
279
216
  rdlen = RSTRING_LEN(_rdata);
280
- rdata = (void *)RSTRING_PTR(_rdata);
217
+ rdata = (void *)StringValuePtr(_rdata);
281
218
  ttl = (uint32_t)NUM2ULONG(_ttl);
282
219
 
283
- get(cDNSSDService, self, DNSServiceRef, client);
220
+ TypedData_Get_Struct(self, DNSServiceRef, &dnssd_service_type, client);
284
221
 
285
222
  _record = rb_class_new_instance(0, NULL, cDNSSDRecord);
286
223
 
@@ -292,7 +229,6 @@ dnssd_service_add_record(VALUE self, VALUE _flags, VALUE _rrtype, VALUE _rdata,
292
229
 
293
230
  /* record will become invalid when this service is destroyed */
294
231
  rb_ivar_set(_record, dnssd_iv_service, self);
295
- rb_ary_push(rb_ivar_get(self, dnssd_iv_records), _record);
296
232
 
297
233
  return _record;
298
234
  }
@@ -319,7 +255,7 @@ dnssd_service_browse_reply(DNSServiceRef client, DNSServiceFlags flags,
319
255
 
320
256
  reply = rb_class_new_instance(6, argv, cDNSSDReplyBrowse);
321
257
 
322
- dnssd_service_callback(service, reply);
258
+ rb_funcall(service, dnssd_id_push, 1, reply);
323
259
  }
324
260
 
325
261
  /* call-seq:
@@ -329,7 +265,7 @@ dnssd_service_browse_reply(DNSServiceRef client, DNSServiceFlags flags,
329
265
  */
330
266
 
331
267
  static VALUE
332
- dnssd_service_browse(VALUE self, VALUE _flags, VALUE _interface, VALUE _type,
268
+ dnssd_service_browse(VALUE klass, VALUE _flags, VALUE _interface, VALUE _type,
333
269
  VALUE _domain) {
334
270
  const char *type;
335
271
  const char *domain = NULL;
@@ -338,6 +274,7 @@ dnssd_service_browse(VALUE self, VALUE _flags, VALUE _interface, VALUE _type,
338
274
 
339
275
  DNSServiceErrorType e;
340
276
  DNSServiceRef *client;
277
+ VALUE self;
341
278
 
342
279
  dnssd_utf8_cstr(_type, type);
343
280
 
@@ -350,7 +287,9 @@ dnssd_service_browse(VALUE self, VALUE _flags, VALUE _interface, VALUE _type,
350
287
  if (!NIL_P(_interface))
351
288
  interface = (uint32_t)NUM2ULONG(_interface);
352
289
 
353
- get(cDNSSDService, self, DNSServiceRef, client);
290
+ client = xcalloc(1, sizeof(DNSServiceRef));
291
+ self = TypedData_Wrap_Struct(klass, &dnssd_service_type, client);
292
+ rb_obj_call_init(self, 0, 0);
354
293
 
355
294
  e = DNSServiceBrowse(client, flags, interface, type, domain,
356
295
  dnssd_service_browse_reply, (void *)self);
@@ -378,7 +317,7 @@ dnssd_service_enumerate_domains_reply(DNSServiceRef client,
378
317
 
379
318
  reply = rb_class_new_instance(4, argv, cDNSSDReplyDomain);
380
319
 
381
- dnssd_service_callback(service, reply);
320
+ rb_funcall(service, dnssd_id_push, 1, reply);
382
321
  }
383
322
 
384
323
  /* call-seq:
@@ -388,9 +327,10 @@ dnssd_service_enumerate_domains_reply(DNSServiceRef client,
388
327
  */
389
328
 
390
329
  static VALUE
391
- dnssd_service_enumerate_domains(VALUE self, VALUE _flags, VALUE _interface) {
330
+ dnssd_service_enumerate_domains(VALUE klass, VALUE _flags, VALUE _interface) {
392
331
  DNSServiceFlags flags = 0;
393
332
  uint32_t interface = 0;
333
+ VALUE self;
394
334
 
395
335
  DNSServiceErrorType e;
396
336
  DNSServiceRef *client;
@@ -401,7 +341,9 @@ dnssd_service_enumerate_domains(VALUE self, VALUE _flags, VALUE _interface) {
401
341
  if (!NIL_P(_interface))
402
342
  interface = (uint32_t)NUM2ULONG(_interface);
403
343
 
404
- get(cDNSSDService, self, DNSServiceRef, client);
344
+ client = xcalloc(1, sizeof(DNSServiceRef));
345
+ self = TypedData_Wrap_Struct(klass, &dnssd_service_type, client);
346
+ rb_obj_call_init(self, 0, 0);
405
347
 
406
348
  e = DNSServiceEnumerateDomains(client, flags, interface,
407
349
  dnssd_service_enumerate_domains_reply, (void *)self);
@@ -433,7 +375,7 @@ dnssd_service_getaddrinfo_reply(DNSServiceRef client, DNSServiceFlags flags,
433
375
 
434
376
  reply = rb_class_new_instance(6, argv, cDNSSDReplyAddrInfo);
435
377
 
436
- dnssd_service_callback(service, reply);
378
+ rb_funcall(service, dnssd_id_push, 1, reply);
437
379
  }
438
380
 
439
381
  /* call-seq:
@@ -443,12 +385,13 @@ dnssd_service_getaddrinfo_reply(DNSServiceRef client, DNSServiceFlags flags,
443
385
  */
444
386
 
445
387
  static VALUE
446
- dnssd_service_getaddrinfo(VALUE self, VALUE _flags, VALUE _interface,
388
+ dnssd_service_getaddrinfo(VALUE klass, VALUE _flags, VALUE _interface,
447
389
  VALUE _protocol, VALUE _host) {
448
390
  DNSServiceFlags flags = 0;
449
391
  uint32_t interface = 0;
450
392
  DNSServiceProtocol protocol = 0;
451
393
  const char *host;
394
+ VALUE self;
452
395
 
453
396
  DNSServiceErrorType e;
454
397
  DNSServiceRef *client;
@@ -463,7 +406,9 @@ dnssd_service_getaddrinfo(VALUE self, VALUE _flags, VALUE _interface,
463
406
  if (!NIL_P(_interface))
464
407
  interface = (uint32_t)NUM2ULONG(_interface);
465
408
 
466
- get(cDNSSDService, self, DNSServiceRef, client);
409
+ client = xcalloc(1, sizeof(DNSServiceRef));
410
+ self = TypedData_Wrap_Struct(klass, &dnssd_service_type, client);
411
+ rb_obj_call_init(self, 0, 0);
467
412
 
468
413
  e = DNSServiceGetAddrInfo(client, flags, interface, protocol, host,
469
414
  dnssd_service_getaddrinfo_reply, (void *)self);
@@ -498,7 +443,7 @@ dnssd_service_query_record_reply(DNSServiceRef client, DNSServiceFlags flags,
498
443
 
499
444
  reply = rb_class_new_instance(8, argv, cDNSSDReplyQueryRecord);
500
445
 
501
- dnssd_service_callback(service, reply);
446
+ rb_funcall(service, dnssd_id_push, 1, reply);
502
447
  }
503
448
 
504
449
  /* call-seq:
@@ -508,7 +453,7 @@ dnssd_service_query_record_reply(DNSServiceRef client, DNSServiceFlags flags,
508
453
  */
509
454
 
510
455
  static VALUE
511
- dnssd_service_query_record(VALUE self, VALUE _flags, VALUE _interface,
456
+ dnssd_service_query_record(VALUE klass, VALUE _flags, VALUE _interface,
512
457
  VALUE _fullname, VALUE _rrtype, VALUE _rrclass) {
513
458
  DNSServiceRef *client;
514
459
  DNSServiceFlags flags;
@@ -517,6 +462,7 @@ dnssd_service_query_record(VALUE self, VALUE _flags, VALUE _interface,
517
462
  uint32_t interface;
518
463
  uint16_t rrtype;
519
464
  uint16_t rrclass;
465
+ VALUE self;
520
466
 
521
467
  flags = (DNSServiceFlags)NUM2ULONG(_flags);
522
468
  interface = (uint32_t)NUM2ULONG(_interface);
@@ -524,7 +470,9 @@ dnssd_service_query_record(VALUE self, VALUE _flags, VALUE _interface,
524
470
  rrtype = NUM2UINT(_rrtype);
525
471
  rrclass = NUM2UINT(_rrclass);
526
472
 
527
- get(cDNSSDService, self, DNSServiceRef, client);
473
+ client = xcalloc(1, sizeof(DNSServiceRef));
474
+ self = TypedData_Wrap_Struct(klass, &dnssd_service_type, client);
475
+ rb_obj_call_init(self, 0, 0);
528
476
 
529
477
  e = DNSServiceQueryRecord(client, flags, interface, fullname, rrtype,
530
478
  rrclass, dnssd_service_query_record_reply, (void *)self);
@@ -555,7 +503,7 @@ dnssd_service_register_reply(DNSServiceRef client, DNSServiceFlags flags,
555
503
 
556
504
  reply = rb_class_new_instance(5, argv, cDNSSDReplyRegister);
557
505
 
558
- dnssd_service_callback(service, reply);
506
+ rb_funcall(service, dnssd_id_push, 1, reply);
559
507
  }
560
508
 
561
509
  /* call-seq:
@@ -565,7 +513,7 @@ dnssd_service_register_reply(DNSServiceRef client, DNSServiceFlags flags,
565
513
  */
566
514
 
567
515
  static VALUE
568
- dnssd_service_register(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
516
+ dnssd_service_register(VALUE klass, VALUE _flags, VALUE _interface, VALUE _name,
569
517
  VALUE _type, VALUE _domain, VALUE _host, VALUE _port, VALUE _text_record) {
570
518
  const char *name, *type, *host = NULL, *domain = NULL;
571
519
  uint16_t port;
@@ -577,20 +525,30 @@ dnssd_service_register(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
577
525
 
578
526
  DNSServiceErrorType e;
579
527
  DNSServiceRef *client;
528
+ VALUE self;
580
529
 
581
- dnssd_utf8_cstr(_name, name);
530
+ if (!NIL_P(_name)) {
531
+ Check_Type(_name, T_STRING);
532
+ dnssd_utf8_cstr(_name, name);
533
+ }
534
+
535
+ Check_Type(_type, T_STRING);
582
536
  dnssd_utf8_cstr(_type, type);
583
537
 
584
- if (!NIL_P(_host))
538
+ if (!NIL_P(_host)) {
539
+ Check_Type(_host, T_STRING);
585
540
  dnssd_utf8_cstr(_host, host);
541
+ }
586
542
 
587
- if (!NIL_P(_domain))
543
+ if (!NIL_P(_domain)) {
544
+ Check_Type(_domain, T_STRING);
588
545
  dnssd_utf8_cstr(_domain, domain);
546
+ }
589
547
 
590
548
  port = htons((uint16_t)NUM2UINT(_port));
591
549
 
592
550
  if (!NIL_P(_text_record)) {
593
- txt_rec = RSTRING_PTR(_text_record);
551
+ txt_rec = StringValuePtr(_text_record);
594
552
  txt_len = RSTRING_LEN(_text_record);
595
553
  }
596
554
 
@@ -600,10 +558,11 @@ dnssd_service_register(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
600
558
  if (!NIL_P(_interface))
601
559
  interface = (uint32_t)NUM2ULONG(_interface);
602
560
 
603
- if (rb_block_given_p())
604
- callback = dnssd_service_register_reply;
561
+ callback = dnssd_service_register_reply;
605
562
 
606
- get(cDNSSDService, self, DNSServiceRef, client);
563
+ client = xcalloc(1, sizeof(DNSServiceRef));
564
+ self = TypedData_Wrap_Struct(cDNSSDServiceRegister, &dnssd_service_type, client);
565
+ rb_obj_call_init(self, 0, 0);
607
566
 
608
567
  e = DNSServiceRegister(client, flags, interface, name, type,
609
568
  domain, host, port, txt_len, txt_rec, callback, (void*)self);
@@ -637,7 +596,7 @@ dnssd_service_resolve_reply(DNSServiceRef client, DNSServiceFlags flags,
637
596
 
638
597
  reply = rb_class_new_instance(7, argv, cDNSSDReplyResolve);
639
598
 
640
- dnssd_service_callback(service, reply);
599
+ rb_funcall(service, dnssd_id_push, 1, reply);
641
600
  }
642
601
 
643
602
  /* call-seq:
@@ -647,11 +606,12 @@ dnssd_service_resolve_reply(DNSServiceRef client, DNSServiceFlags flags,
647
606
  */
648
607
 
649
608
  static VALUE
650
- dnssd_service_resolve(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
609
+ dnssd_service_resolve(VALUE klass, VALUE _flags, VALUE _interface, VALUE _name,
651
610
  VALUE _type, VALUE _domain) {
652
611
  const char *name, *type, *domain;
653
612
  DNSServiceFlags flags = 0;
654
613
  uint32_t interface = 0;
614
+ VALUE self;
655
615
 
656
616
  DNSServiceErrorType e;
657
617
  DNSServiceRef *client;
@@ -666,7 +626,9 @@ dnssd_service_resolve(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
666
626
  if (!NIL_P(_interface))
667
627
  interface = (uint32_t)NUM2ULONG(_interface);
668
628
 
669
- get(cDNSSDService, self, DNSServiceRef, client);
629
+ client = xcalloc(1, sizeof(DNSServiceRef));
630
+ self = TypedData_Wrap_Struct(klass, &dnssd_service_type, client);
631
+ rb_obj_call_init(self, 0, 0);
670
632
 
671
633
  e = DNSServiceResolve(client, flags, interface, name, type, domain,
672
634
  dnssd_service_resolve_reply, (void *)self);
@@ -678,6 +640,8 @@ dnssd_service_resolve(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
678
640
 
679
641
  void
680
642
  Init_DNSSD_Service(void) {
643
+ VALUE sDNSSDService;
644
+
681
645
  mDNSSD = rb_define_module("DNSSD");
682
646
 
683
647
  dnssd_id_join = rb_intern("join");
@@ -690,9 +654,10 @@ Init_DNSSD_Service(void) {
690
654
  dnssd_iv_thread = rb_intern("@thread");
691
655
  dnssd_iv_type = rb_intern("@type");
692
656
 
693
- cDNSSDFlags = rb_define_class_under(mDNSSD, "Flags", rb_cObject);
694
- cDNSSDRecord = rb_define_class_under(mDNSSD, "Record", rb_cObject);
695
- cDNSSDService = rb_define_class_under(mDNSSD, "Service", rb_cObject);
657
+ cDNSSDFlags = rb_define_class_under(mDNSSD, "Flags", rb_cObject);
658
+ cDNSSDRecord = rb_define_class_under(mDNSSD, "Record", rb_cObject);
659
+ cDNSSDService = rb_define_class_under(mDNSSD, "Service", rb_cObject);
660
+ cDNSSDServiceRegister = rb_define_class_under(cDNSSDService, "Register", cDNSSDService);
696
661
  cDNSSDTextRecord = rb_path2class("DNSSD::TextRecord");
697
662
 
698
663
  cDNSSDReplyAddrInfo = rb_path2class("DNSSD::Reply::AddrInfo");
@@ -701,6 +666,7 @@ Init_DNSSD_Service(void) {
701
666
  cDNSSDReplyQueryRecord = rb_path2class("DNSSD::Reply::QueryRecord");
702
667
  cDNSSDReplyRegister = rb_path2class("DNSSD::Reply::Register");
703
668
  cDNSSDReplyResolve = rb_path2class("DNSSD::Reply::Resolve");
669
+ sDNSSDService = rb_singleton_class(cDNSSDService);
704
670
 
705
671
  rb_cSocket = rb_path2class("Socket");
706
672
 
@@ -742,19 +708,20 @@ Init_DNSSD_Service(void) {
742
708
  rb_define_singleton_method(cDNSSDService, "get_property", dnssd_service_s_get_property, 1);
743
709
  #endif
744
710
 
745
- rb_define_method(cDNSSDService, "stop", dnssd_service_stop, 0);
746
- rb_define_method(cDNSSDService, "stopped?", dnssd_service_stopped_p, 0);
711
+ rb_define_private_method(cDNSSDService, "_stop", dnssd_service_stop, 0);
747
712
 
748
- rb_define_method(cDNSSDService, "_add_record", dnssd_service_add_record, 4);
749
- rb_define_method(cDNSSDService, "_browse", dnssd_service_browse, 4);
750
- rb_define_method(cDNSSDService, "_enumerate_domains", dnssd_service_enumerate_domains, 2);
713
+ rb_define_private_method(cDNSSDServiceRegister, "_add_record", dnssd_service_add_record, 4);
714
+ rb_define_private_method(cDNSSDService, "ref_sock_fd", dnssd_ref_sock_fd, 0);
715
+ rb_define_private_method(cDNSSDService, "process_result", dnssd_process_result, 0);
716
+
717
+ /* private class methods */
718
+ rb_define_private_method(sDNSSDService, "_browse", dnssd_service_browse, 4);
719
+ rb_define_private_method(sDNSSDService, "_enumerate_domains", dnssd_service_enumerate_domains, 2);
751
720
  #ifdef HAVE_DNSSERVICEGETADDRINFO
752
- rb_define_method(cDNSSDService, "_getaddrinfo", dnssd_service_getaddrinfo, 4);
721
+ rb_define_private_method(sDNSSDService, "_getaddrinfo", dnssd_service_getaddrinfo, 4);
753
722
  #endif
754
- rb_define_method(cDNSSDService, "_query_record", dnssd_service_query_record, 5);
755
- rb_define_method(cDNSSDService, "_register", dnssd_service_register, 8);
756
- rb_define_method(cDNSSDService, "_resolve", dnssd_service_resolve, 5);
723
+ rb_define_private_method(sDNSSDService, "_query_record", dnssd_service_query_record, 5);
724
+ rb_define_private_method(sDNSSDService, "_register", dnssd_service_register, 8);
725
+ rb_define_private_method(sDNSSDService, "_resolve", dnssd_service_resolve, 5);
757
726
 
758
- rb_define_method(cDNSSDService, "_process", dnssd_service_process, 0);
759
727
  }
760
-