Module: Ethon::Multi::Operations
- Included in:
- Ethon::Multi
- Defined in:
- lib/ethon/multi/operations.rb
Overview
This module contains logic to run a multi.
Constant Summary collapse
- STARTED_MULTI =
"ETHON: started MULTI"
- PERFORMED_MULTI =
"ETHON: performed MULTI"
Instance Method Summary collapse
-
#handle ⇒ FFI::Pointer
Return the multi handle.
-
#init_vars ⇒ void
Initialize variables.
-
#ongoing? ⇒ Boolean
Return whether the multi still contains requests or not.
-
#perform ⇒ nil
Perform multi.
-
#prepare ⇒ nil
deprecated
Deprecated.
It is no longer necessary to call prepare.
-
#socket_action(io = nil, readiness = 0) ⇒ Symbol
Continue execution with an external IO loop.
Instance Method Details
#handle ⇒ FFI::Pointer
Return the multi handle. Inititialize multi handle, in case it didn’t happened already.
16 17 18 |
# File 'lib/ethon/multi/operations.rb', line 16 def handle @handle ||= FFI::AutoPointer.new(Curl.multi_init, Curl.method(:multi_cleanup)) end |
#init_vars ⇒ void
This method returns an undefined value.
Initialize variables.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ethon/multi/operations.rb', line 26 def init_vars if @execution_mode == :perform @timeout = ::FFI::MemoryPointer.new(:long) @timeval = Curl::Timeval.new @fd_read = Curl::FDSet.new @fd_write = Curl::FDSet.new @fd_excep = Curl::FDSet.new @max_fd = ::FFI::MemoryPointer.new(:int) elsif @execution_mode == :socket_action @running_count_pointer = FFI::MemoryPointer.new(:int) end end |
#ongoing? ⇒ Boolean
Return whether the multi still contains requests or not.
113 114 115 |
# File 'lib/ethon/multi/operations.rb', line 113 def ongoing? easy_handles.size > 0 || (!defined?(@running_count) || running_count > 0) end |
#perform ⇒ nil
Perform multi.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ethon/multi/operations.rb', line 45 def perform ensure_execution_mode(:perform) Ethon.logger.debug(STARTED_MULTI) while ongoing? run timeout = get_timeout next if timeout == 0 reset_fds set_fds(timeout) end Ethon.logger.debug(PERFORMED_MULTI) nil end |
#prepare ⇒ nil
Deprecated.
It is no longer necessary to call prepare.
Prepare multi.
68 69 70 71 72 73 74 |
# File 'lib/ethon/multi/operations.rb', line 68 def prepare Ethon.logger.warn( "ETHON: It is no longer necessay to call "+ "Multi#prepare. Its going to be removed "+ "in future versions." ) end |
#socket_action(io = nil, readiness = 0) ⇒ Symbol
Continue execution with an external IO loop.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ethon/multi/operations.rb', line 88 def socket_action(io = nil, readiness = 0) ensure_execution_mode(:socket_action) fd = if io.nil? ::Ethon::Curl::SOCKET_TIMEOUT elsif io.is_a?(Integer) io else io.fileno end code = Curl.multi_socket_action(handle, fd, readiness, @running_count_pointer) @running_count = @running_count_pointer.read_int check code end |