Class: Dnsruby::SelectThread::SendToken

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsruby/select_thread.rb

Overview

Cancellation and each nonblocking write are ordered without holding the selector mutex during I/O. Waiting for a connect or a writable socket never holds this lock, so closing a Resolver remains responsive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control = QueryControl.current, transmission_budget = nil) ⇒ SendToken

Returns a new instance of SendToken.



277
278
279
280
281
282
# File 'lib/dnsruby/select_thread.rb', line 277

def initialize(control = QueryControl.current, transmission_budget = nil)
  @mutex = Mutex.new
  @cancelled = false
  @control = control
  @transmission_budget = transmission_budget || TransmissionBudget.current || TransmissionBudget.new
end

Instance Attribute Details

#control ⇒ Object (readonly)

Returns the value of attribute control.



275
276
277
# File 'lib/dnsruby/select_thread.rb', line 275

def control
  @control
end

#transmission_budget ⇒ Object (readonly)

Returns the value of attribute transmission_budget.



275
276
277
# File 'lib/dnsruby/select_thread.rb', line 275

def transmission_budget
  @transmission_budget
end

Instance Method Details

#cancel ⇒ Object



284
285
286
# File 'lib/dnsruby/select_thread.rb', line 284

def cancel
  @mutex.synchronize { @cancelled = true }
end

#cancelled? ⇒ Boolean

Returns:

  • (Boolean)


288
289
290
291
292
293
# File 'lib/dnsruby/select_thread.rb', line 288

def cancelled?
  @control&.check!
  @mutex.synchronize { @cancelled }
rescue QueryControl::Stopped
  true
end

#write ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
# File 'lib/dnsruby/select_thread.rb', line 295

def write
  @mutex.synchronize do
    return false if @cancelled
    begin
      @control&.check!
    rescue QueryControl::Stopped
      return false
    end
    yield
  end
end