Class: ADNS::Query

Inherits:
Object
  • Object
show all
Defined in:
ext/adns/mod_adns.c,
ext/adns/mod_adns.c

Overview

ADNS::Query class defines asychronous/synchronous methods to check the query submitted using one of the ADNS::State.submit* methods.

Instance Method Summary collapse

Constructor Details

#initializeObject



331
332
333
334
# File 'ext/adns/mod_adns.c', line 331

static VALUE cQuery_init(VALUE self)
{
	return self;
}

Instance Method Details

#cancelnil

Cancel current pending asynchronous request.

Returns:

  • (nil)


426
427
428
429
430
431
432
433
434
435
436
437
# File 'ext/adns/mod_adns.c', line 426

static VALUE cQuery_cancel(VALUE self)
{
	rb_adns_query_t *rb_adq_r;
	int ecode;
    
	Data_Get_Struct(self, rb_adns_query_t, rb_adq_r);
	if (!rb_adq_r->adq)
		rb_raise(mADNS__eQueryError, "query invalidated");
	(void) adns_cancel(rb_adq_r->adq);
	cQuery_free((void *)rb_adq_r);
	return Qnil;
}

#checkHash, raises ADNS::NotReadyError

Check pending asynchronous request and retrieve answer or raises ADNS::NotReadyError, if request is still pending.

Returns:



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'ext/adns/mod_adns.c', line 356

static VALUE cQuery_check(VALUE self)
{
    rb_adns_query_t *rb_adq_r;
    adns_answer *answer_r;
    int ecode;
	
    Data_Get_Struct(self, rb_adns_query_t, rb_adq_r);
	if (rb_adq_r->answer != Qnil)
		return rb_adq_r->answer;
	if (!rb_adq_r->adq)
		rb_raise(mADNS__eQueryError, "invalid query");
	ecode = adns_check(rb_adq_r->rb_ads_r->ads, &rb_adq_r->adq, &answer_r, NULL);
	if (ecode)
    {
		if (ecode == EWOULDBLOCK)
			rb_raise(mADNS__eNotReadyError, strerror(ecode));
		else
        {
			rb_adq_r->adq = NULL;
			rb_raise(mADNS__eError, strerror(ecode));
		}
	}
	rb_adq_r->answer = rb_hash_new();
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("type"), INT2FIX(answer_r->type));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("owner"), CSTR2STR(answer_r->owner));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("status"), INT2FIX(answer_r->status));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("expires"), INT2FIX(answer_r->expires));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("answer"), parse_adns_answer(answer_r));
	rb_adq_r->adq = NULL; /* mark query as completed, thus making it invalid */
	return rb_adq_r->answer;
}

#waitHash

Wait until answer is received.

Returns:

  • (Hash)


393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'ext/adns/mod_adns.c', line 393

static VALUE cQuery_wait(int argc, VALUE argv[], VALUE self)
{
    rb_adns_query_t *rb_adq_r;
    adns_answer *answer_r;
    int ecode;
	
    Data_Get_Struct(self, rb_adns_query_t, rb_adq_r);
	if (rb_adq_r->answer != Qnil)
		return rb_adq_r->answer;
	if (!rb_adq_r->adq)
		rb_raise(mADNS__eQueryError, "query invalidated");
	ecode = adns_wait(rb_adq_r->rb_ads_r->ads, &rb_adq_r->adq, &answer_r, NULL);
	if (ecode)
	{
		rb_adq_r->adq = NULL;
		rb_adq_r->answer = Qnil;
		rb_raise(mADNS__eError, strerror(ecode));
	}
	rb_adq_r->answer = rb_hash_new();
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("type"), INT2FIX(answer_r->type));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("owner"), CSTR2STR(answer_r->owner));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("status"), INT2FIX(answer_r->status));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("expires"), INT2FIX(answer_r->expires));
	rb_hash_aset(rb_adq_r->answer, CSTR2SYM("answer"), parse_adns_answer(answer_r));
	rb_adq_r->adq = NULL;
	return rb_adq_r->answer;
}