Class: Unbound::Context
- Inherits:
-
Object
- Object
- Unbound::Context
- Defined in:
- lib/unbound/context.rb
Instance Method Summary collapse
- #cancel_async_query(async_id) ⇒ Object
- #check_closed! ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#fd ⇒ Object
Returns the number for the file descriptor.
- #get_option(varname) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#io ⇒ FFI::IO
Returns a brand new IO for the file descriptor that can be selected to determine if processing needs to be done.
- #load_config(filename) ⇒ Object
- #process ⇒ Object
- #raise_if_error!(retval) ⇒ Object
- #raise_on_noid=(b) ⇒ Object
- #raise_on_noid? ⇒ Boolean
- #resolve_async(name, rrtype, rrclass, callback, private_data = nil) ⇒ Object
- #set_option(varname, val) ⇒ Object
Constructor Details
Instance Method Details
#cancel_async_query(async_id) ⇒ Object
69 70 71 72 |
# File 'lib/unbound/context.rb', line 69 def cancel_async_query(async_id) check_closed! raise_if_error!(Unbound::Bindings.ub_cancel(@ub_ctx, async_id)) end |
#check_closed! ⇒ Object
19 20 21 22 23 |
# File 'lib/unbound/context.rb', line 19 def check_closed! if @ub_ctx.nil? raise ContextClosedError.new end end |
#close ⇒ Object
58 59 60 61 62 |
# File 'lib/unbound/context.rb', line 58 def close check_closed! Unbound::Bindings.ub_ctx_delete(@ub_ctx) @ub_ctx = nil end |
#closed? ⇒ Boolean
34 35 36 |
# File 'lib/unbound/context.rb', line 34 def closed? @ub_ctx.nil? end |
#fd ⇒ Object
Returns the number for the file descriptor.
85 86 87 88 |
# File 'lib/unbound/context.rb', line 85 def fd check_closed! Unbound::Bindings.ub_fd(@ub_ctx) end |
#get_option(varname) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/unbound/context.rb', line 43 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 |
#io ⇒ FFI::IO
Returns a brand new IO for the file descriptor that can be selected to determine if processing needs to be done. Warning: DO NOT CLOSE THIS IO OBJECT! Use Context#close, instead.
78 79 80 81 82 |
# File 'lib/unbound/context.rb', line 78 def io ret = ::FFI::IO.for_fd(self.fd) ret.autoclose = false return ret end |
#load_config(filename) ⇒ Object
38 39 40 41 |
# File 'lib/unbound/context.rb', line 38 def load_config(filename) check_closed! raise_if_error!(Unbound::Bindings.ub_ctx_config(@ub_ctx, filename)) end |
#process ⇒ Object
64 65 66 67 |
# File 'lib/unbound/context.rb', line 64 def process check_closed! raise_if_error!(Unbound::Bindings.ub_process(@ub_ctx)) end |
#raise_if_error!(retval) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/unbound/context.rb', line 25 def raise_if_error!(retval) return retval if retval == :noerror if retval == :noid && @raise_on_noid == false return retval end raise APIError.new(retval) end |
#raise_on_noid=(b) ⇒ Object
11 12 13 |
# File 'lib/unbound/context.rb', line 11 def raise_on_noid=(b) @raise_on_noid = (b == true) end |
#raise_on_noid? ⇒ Boolean
15 16 17 |
# File 'lib/unbound/context.rb', line 15 def raise_on_noid? @raise_on_noid end |
#resolve_async(name, rrtype, rrclass, callback, private_data = nil) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/unbound/context.rb', line 90 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 |