Class: Unbound::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/unbound/context.rb

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



6
7
8
# File 'lib/unbound/context.rb', line 6

def initialize
  @ub_ctx = Unbound::Bindings.ub_ctx_create()
end

Instance Method Details

#cancel_async_query(async_id) ⇒ Object



58
59
60
61
# File 'lib/unbound/context.rb', line 58

def cancel_async_query(async_id)
  check_closed!
  raise_if_error!(Unbound::Bindings.ub_cancel(@ub_ctx, async_id))
end

#check_closed!Object



10
11
12
13
14
# File 'lib/unbound/context.rb', line 10

def check_closed!
  if @ub_ctx.nil?
    raise ContextClosedError.new
  end
end

#closeObject



47
48
49
50
51
# File 'lib/unbound/context.rb', line 47

def close
  check_closed!
  Unbound::Bindings.ub_ctx_delete(@ub_ctx)
  @ub_ctx = nil
end

#closed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/unbound/context.rb', line 23

def closed?
  @ub_ctx.nil?
end

#fdObject



63
64
65
66
# File 'lib/unbound/context.rb', line 63

def fd
  check_closed!
  Unbound::Bindings.ub_fd(@ub_ctx)
end

#get_option(varname) ⇒ Object



32
33
34
35
36
37
# File 'lib/unbound/context.rb', line 32

def get_option(varname)
  check_closed!
  ret_ptr = FFI::MemoryPointer.new(:pointer)
  raise_if_error!(Unbound::Bindings.ub_ctx_get_option(@ub_ctx, varname, ret_ptr))
  ret_ptr.read_pointer().read_string()
end

#load_config(filename) ⇒ Object



27
28
29
30
# File 'lib/unbound/context.rb', line 27

def load_config(filename)
  check_closed!
  raise_if_error!(Unbound::Bindings.ub_ctx_config(@ub_ctx, filename))
end

#processObject



53
54
55
56
# File 'lib/unbound/context.rb', line 53

def process
  check_closed!
  raise_if_error!(Unbound::Bindings.ub_process(@ub_ctx))
end

#raise_if_error!(retval) ⇒ Object



16
17
18
19
20
21
# File 'lib/unbound/context.rb', line 16

def raise_if_error!(retval)
  if retval != 0
    raise APIError.new(retval)
  end
  return retval
end

#resolve_async(name, rrtype, rrclass, callback, private_data = nil) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/unbound/context.rb', line 68

def resolve_async(name, rrtype, rrclass, callback, private_data = nil)
  check_closed!
  async_id_ptr = FFI::MemoryPointer.new :int
  raise_if_error!(
    Unbound::Bindings.ub_resolve_async(
      @ub_ctx, name, rrtype, rrclass, private_data, callback, async_id_ptr))
  return async_id_ptr.get_int(0)
end

#set_option(varname, val) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/unbound/context.rb', line 39

def set_option(varname, val)
  check_closed!
  unless varname.end_with?(':')
    varname = varname + ":"
  end
  raise_if_error!(Unbound::Bindings.ub_ctx_set_option(@ub_ctx, varname, val))
end