Class: Ethon::Multi::Bran

Inherits:
Object
  • Object
show all
Defined in:
lib/bran/ext/ethon/multi/bran.rb

Instance Method Summary collapse

Constructor Details

#initialize(fm, multi) ⇒ Bran

Returns a new instance of Bran.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bran/ext/ethon/multi/bran.rb', line 30

def initialize(fm, multi)
  @fm    = fm
  @multi = multi
  
  # We must hold a reference to these Procs, because the multi won't.
  # This prevents the Procs from being GC'd while C holds the callbacks.
  @socketfunction = method(:_socketfunction_callback).to_proc
  @timerfunction  = method(:_timerfunction_callback).to_proc
  @multi.socketfunction = @socketfunction
  @multi.timerfunction  = @timerfunction
end

Instance Method Details

#performObject

Raises:

  • (@callback_error)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bran/ext/ethon/multi/bran.rb', line 42

def perform
  fm = Thread.current.thread_variable_get(:fiber_manager)
  return unless fm == @fm # abort if not run within the same context.
  
  @curl_readables = {}
  @curl_writables = {}
  @fds_remaining_ptr = ::FFI::MemoryPointer.new(:int)
  
  raise @callback_error if @callback_error
  
  @perform_fiber = ::Fiber.current
  ::Fiber.yield
  @perform_fiber = nil
  
  raise @callback_error if @callback_error
  
  true
end