Class: Dnsruby::SelectThread::SendToken
- Inherits:
-
Object
- Object
- Dnsruby::SelectThread::SendToken
- 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
-
#control ⇒ Object
readonly
Returns the value of attribute control.
-
#transmission_budget ⇒ Object
readonly
Returns the value of attribute transmission_budget.
Instance Method Summary collapse
- #cancel ⇒ Object
- #cancelled? ⇒ Boolean
-
#initialize(control = QueryControl.current, transmission_budget = nil) ⇒ SendToken
constructor
A new instance of SendToken.
- #write ⇒ Object
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
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 |