code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def setup(easy)
@easy = easy
# Order is important, @easy will be used to provide access to options
# relevant to the following operations (like whether or not to escape
# values).
easy.set_attributes(options)
set_form(easy) unless form.empty?
if params.empty?
easy.url = url
else
set_params(easy)
end
end
|
Setup everything necessary for a proper request.
@example setup.
action.setup(easy)
@param [ easy ] easy the easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
Apache-2.0
|
def set_params(easy)
params.escape = easy.escape?
params.params_encoding = params_encoding
base_url, base_params = url.split('?')
base_url << '?'
base_url << base_params.to_s
base_url << '&' if base_params
base_url << params.to_s
easy.url = base_url
end
|
Setup request with params.
@example Setup nothing.
action.set_params(easy)
@param [ Easy ] easy The easy to setup.
|
set_params
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/actionable.rb
|
Apache-2.0
|
def setup(easy)
super
easy.customrequest = @verb
end
|
Setup easy to make a request.
@example Setup.
custom.set_params(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/custom.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/custom.rb
|
Apache-2.0
|
def setup(easy)
super
easy.customrequest = "DELETE"
end
|
Setup easy to make a DELETE request.
@example Setup customrequest.
delete.setup(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/delete.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/delete.rb
|
Apache-2.0
|
def setup(easy)
super
easy.customrequest = "GET" unless form.empty?
end
|
Setup easy to make a GET request.
@example Setup.
get.set_params(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/get.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/get.rb
|
Apache-2.0
|
def setup(easy)
super
easy.nobody = true
end
|
Setup easy to make a HEAD request.
@example Setup.
get.set_params(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/head.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/head.rb
|
Apache-2.0
|
def setup(easy)
super
easy.customrequest = "OPTIONS"
end
|
Setup easy to make a OPTIONS request.
@example Setup.
options.setup(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/options.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/options.rb
|
Apache-2.0
|
def setup(easy)
super
easy.customrequest = "PATCH"
end
|
Setup easy to make a PATCH request.
@example Setup.
patch.setup(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/patch.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/patch.rb
|
Apache-2.0
|
def setup(easy)
super
if form.empty?
easy.postfieldsize = 0
easy.copypostfields = ""
end
end
|
Setup easy to make a POST request.
@example Setup.
post.setup(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/post.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/post.rb
|
Apache-2.0
|
def set_form(easy)
easy.url ||= url
form.params_encoding = params_encoding
if form.multipart?
form.escape = false
form.materialize
easy.httppost = form.first.read_pointer
else
form.escape = easy.escape?
easy.postfieldsize = form.to_s.bytesize
easy.copypostfields = form.to_s
end
end
|
Set things up when form is provided.
Deals with multipart forms.
@example Setup.
post.set_form(easy)
@param [ Easy ] easy The easy to setup.
|
set_form
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/postable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/postable.rb
|
Apache-2.0
|
def setup(easy)
super
if form.empty?
easy.upload = true
easy.infilesize = 0
end
end
|
Setup easy to make a PUT request.
@example Setup.
put.setup(easy)
@param [ Easy ] easy The easy to setup.
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/put.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/put.rb
|
Apache-2.0
|
def set_form(easy)
easy.upload = true
form.escape = true
form.params_encoding = params_encoding
easy.infilesize = form.to_s.bytesize
easy.set_read_callback(form.to_s)
end
|
Set things up when form is provided.
Deals with multipart forms.
@example Setup.
put.set_form(easy)
@param [ Easy ] easy The easy to setup.
|
set_form
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/putable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/easy/http/putable.rb
|
Apache-2.0
|
def handle
@handle ||= FFI::AutoPointer.new(Curl.multi_init, Curl.method(:multi_cleanup))
end
|
Return the multi handle. Inititialize multi handle,
in case it didn't happened already.
@example Return multi handle.
multi.handle
@return [ FFI::Pointer ] The multi handle.
|
handle
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
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
|
Initialize variables.
@example Initialize variables.
multi.init_vars
@return [ void ]
|
init_vars
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
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
|
Perform multi.
@return [ nil ]
@example Perform multi.
multi.perform
|
perform
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def prepare
Ethon.logger.warn(
"ETHON: It is no longer necessay to call "+
"Multi#prepare. Its going to be removed "+
"in future versions."
)
end
|
Prepare multi.
@return [ nil ]
@example Prepare multi.
multi.prepare
@deprecated It is no longer necessary to call prepare.
|
prepare
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
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
|
Continue execution with an external IO loop.
@example When no sockets are ready yet, or to begin.
multi.socket_action
@example When a socket is readable
multi.socket_action(io_object, [:in])
@example When a socket is readable and writable
multi.socket_action(io_object, [:in, :out])
@return [ Symbol ] The Curl.multi_socket_action return code.
|
socket_action
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def ongoing?
easy_handles.size > 0 || (!defined?(@running_count) || running_count > 0)
end
|
Return whether the multi still contains requests or not.
@example Return if ongoing.
multi.ongoing?
@return [ Boolean ] True if ongoing, else false.
|
ongoing?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def get_timeout
code = Curl.multi_timeout(handle, @timeout)
raise Errors::MultiTimeout.new(code) unless code == :ok
timeout = @timeout.read_long
timeout = 1 if timeout < 0
timeout
end
|
Get timeout.
@example Get timeout.
multi.get_timeout
@return [ Integer ] The timeout.
@raise [ Ethon::Errors::MultiTimeout ] If getting the timeout fails.
|
get_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def reset_fds
@fd_read.clear
@fd_write.clear
@fd_excep.clear
end
|
Reset file describtors.
@example Reset fds.
multi.reset_fds
@return [ void ]
|
reset_fds
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def set_fds(timeout)
code = Curl.multi_fdset(handle, @fd_read, @fd_write, @fd_excep, @max_fd)
raise Errors::MultiFdset.new(code) unless code == :ok
max_fd = @max_fd.read_int
if max_fd == -1
sleep(0.001)
else
@timeval[:sec] = timeout / 1000
@timeval[:usec] = (timeout * 1000) % 1000000
loop do
code = Curl.select(max_fd + 1, @fd_read, @fd_write, @fd_excep, @timeval)
break unless code < 0 && ::FFI.errno == Errno::EINTR::Errno
end
raise Errors::Select.new(::FFI.errno) if code < 0
end
end
|
Set fds.
@example Set fds.
multi.set_fds
@return [ void ]
@raise [ Ethon::Errors::MultiFdset ] If setting the file descriptors fails.
@raise [ Ethon::Errors::Select ] If select fails.
|
set_fds
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def check
msgs_left = ::FFI::MemoryPointer.new(:int)
while true
msg = Curl.multi_info_read(handle, msgs_left)
break if msg.null?
next if msg[:code] != :done
easy = easy_handles.find{ |e| e.handle == msg[:easy_handle] }
easy.return_code = msg[:data][:code]
Ethon.logger.debug { "ETHON: performed #{easy.log_inspect}" }
delete(easy)
easy.complete
end
end
|
Check.
@example Check.
multi.check
@return [ void ]
|
check
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def run
running_count_pointer = FFI::MemoryPointer.new(:int)
begin code = trigger(running_count_pointer) end while code == :call_multi_perform
check
end
|
Run.
@example Run
multi.run
@return [ void ]
|
run
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def trigger(running_count_pointer)
code = Curl.multi_perform(handle, running_count_pointer)
@running_count = running_count_pointer.read_int
code
end
|
Trigger.
@example Trigger.
multi.trigger
@return [ Symbol ] The Curl.multi_perform return code.
|
trigger
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def running_count
@running_count ||= nil
end
|
Return number of running requests.
@example Return count.
multi.running_count
@return [ Integer ] Number running requests.
|
running_count
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/operations.rb
|
Apache-2.0
|
def value_for(value, type, option = nil)
return nil if value.nil?
if type == :bool
value ? 1 : 0
elsif type == :int
value.to_i
elsif value.is_a?(String)
Ethon::Easy::Util.escape_zero_byte(value)
else
value
end
end
|
Return the value to set to multi handle. It is converted with the help
of bool_options, enum_options and int_options.
@example Return casted the value.
multi.value_for(:verbose)
@return [ Object ] The casted value.
|
value_for
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/options.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/options.rb
|
Apache-2.0
|
def easy_handles
@easy_handles ||= []
end
|
Return easy handles.
@example Return easy handles.
multi.easy_handles
@return [ Array ] The easy handles.
|
easy_handles
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/stack.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/stack.rb
|
Apache-2.0
|
def add(easy)
return nil if easy_handles.include?(easy)
code = Curl.multi_add_handle(handle, easy.handle)
raise Errors::MultiAdd.new(code, easy) unless code == :ok
easy_handles << easy
end
|
Add an easy to the stack.
@example Add easy.
multi.add(easy)
@param [ Easy ] easy The easy to add.
@raise [ Ethon::Errors::MultiAdd ] If adding an easy failed.
|
add
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/stack.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/stack.rb
|
Apache-2.0
|
def delete(easy)
if easy_handles.delete(easy)
code = Curl.multi_remove_handle(handle, easy.handle)
raise Errors::MultiRemove.new(code, handle) unless code == :ok
end
end
|
Delete an easy from stack.
@example Delete easy from stack.
@param [ Easy ] easy The easy to delete.
@raise [ Ethon::Errors::MultiRemove ] If removing an easy failed.
|
delete
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/stack.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/lib/ethon/multi/stack.rb
|
Apache-2.0
|
def rss_bytes
if ENV['OS'] == 'Windows_NT'
0
else
`ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
end
end
|
amount of memory the current process "is using", in RAM
(doesn't include any swap memory that it may be using, just that in actual RAM)
Code loosely based on https://github.com/rdp/os/blob/master/lib/os.rb
returns 0 on windows
|
rss_bytes
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/profile/support/os_memory_leak_tracker.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/ethon-0.16.0/profile/support/os_memory_leak_tracker.rb
|
Apache-2.0
|
def append_library(libs, lib)
libs + " " + format(LIBARG, lib)
end
|
#
OpenSSL:
override append_library, so it actually appends (instead of prepending)
this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
|
append_library
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/ext/extconf.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/ext/extconf.rb
|
Apache-2.0
|
def extract(data)
if @trim > 0
tail_end = @tail.slice!(-@trim, @trim) # returns nil if string is too short
data = tail_end + data if tail_end
end
@input << @tail
entities = data.split(@delimiter, -1)
@tail = entities.shift
unless entities.empty?
@input << @tail
entities.unshift @input.join
@input.clear
@tail = entities.pop
end
entities
end
|
Extract takes an arbitrary string of input data and returns an array of
tokenized entities, provided there were any available to extract. This
makes for easy processing of datagrams using a pattern like:
tokenizer.extract(data).map { |entity| Decode(entity) }.each do ...
Using -1 makes split to return "" if the token is at the end of
the string, meaning the last element is the start of the next chunk.
|
extract
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/buftok.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/buftok.rb
|
Apache-2.0
|
def flush
@input << @tail
buffer = @input.join
@input.clear
@tail = "" # @tail.clear is slightly faster, but not supported on 1.8.7
buffer
end
|
Flush the contents of the input buffer, i.e. return the input buffer even though
a token has not yet been encountered
|
flush
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/buftok.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/buftok.rb
|
Apache-2.0
|
def num_subscribers
return @subs.size
end
|
Return the number of current subscribers.
|
num_subscribers
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
Apache-2.0
|
def subscribe(*a, &b)
name = gen_id
EM.schedule { @subs[name] = EM::Callback(*a, &b) }
name
end
|
Takes any arguments suitable for EM::Callback() and returns a subscriber
id for use when unsubscribing.
@return [Integer] Subscribe identifier
@see #unsubscribe
|
subscribe
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
Apache-2.0
|
def unsubscribe(name)
EM.schedule { @subs.delete name }
end
|
Removes subscriber from the list.
@param [Integer] Subscriber identifier
@see #subscribe
|
unsubscribe
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
Apache-2.0
|
def push(*items)
items = items.dup
EM.schedule { items.each { |i| @subs.values.each { |s| s.call i } } }
end
|
Add items to the channel, which are pushed out to all subscribers.
|
push
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
Apache-2.0
|
def pop(*a, &b)
EM.schedule {
name = subscribe do |*args|
unsubscribe(name)
EM::Callback(*a, &b).call(*args)
end
}
end
|
Fetches one message from the channel.
|
pop
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/channel.rb
|
Apache-2.0
|
def succeed(*args)
change_state(:succeeded, *args)
end
|
Enter the :succeeded state, setting the result value if given.
|
succeed
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def fail(*args)
change_state(:failed, *args)
end
|
Enter the :failed state, setting the result value if given.
|
fail
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def stateback(state, *a, &b)
# The following is quite unfortunate special casing for :completed
# statebacks, but it's a necessary evil for latent completion
# definitions.
if :completed == state || !completed? || @state == state
@callbacks[state] << EM::Callback(*a, &b)
end
execute_callbacks
self
end
|
Statebacks are called when you enter (or are in) the named state.
|
stateback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def callback(*a, &b)
stateback(:succeeded, *a, &b)
end
|
Callbacks are called when you enter (or are in) a :succeeded state.
|
callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def errback(*a, &b)
stateback(:failed, *a, &b)
end
|
Errbacks are called when you enter (or are in) a :failed state.
|
errback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def completion(*a, &b)
stateback(:completed, *a, &b)
end
|
Completions are called when you enter (or are in) either a :failed or a
:succeeded state. They are stored as a special (reserved) state called
:completed.
|
completion
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def change_state(state, *args)
@value = args
@state = state
EM.schedule { execute_callbacks }
end
|
Enter a new state, setting the result value if given. If the state is one
of :succeeded or :failed, then :completed callbacks will also be called.
|
change_state
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def completed?
completion_states.any? { |s| state == s }
end
|
Indicates that we've reached some kind of completion state, by default
this is :succeeded or :failed. Due to these semantics, the :completed
state is reserved for internal use.
|
completed?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def completion_states
[:succeeded, :failed]
end
|
Completion states simply returns a list of completion states, by default
this is :succeeded and :failed.
|
completion_states
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def timeout(time, *args)
cancel_timeout
@timeout_timer = EM::Timer.new(time) do
fail(*args) unless completed?
end
end
|
Schedule a time which if passes before we enter a completion state, this
deferrable will be failed with the given arguments.
|
timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def cancel_errback(*a, &b)
@callbacks[:failed].delete(EM::Callback(*a, &b))
end
|
Remove an errback. N.B. Some errbacks cannot be deleted. Usage is NOT
recommended, this is an anti-pattern.
|
cancel_errback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def cancel_callback(*a, &b)
@callbacks[:succeeded].delete(EM::Callback(*a, &b))
end
|
Remove a callback. N.B. Some callbacks cannot be deleted. Usage is NOT
recommended, this is an anti-pattern.
|
cancel_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def execute_callbacks
execute_state_callbacks(state)
if completed?
execute_state_callbacks(:completed)
clear_dead_callbacks
cancel_timeout
end
end
|
Execute all callbacks for the current state. If in a completed state, then
call any statebacks associated with the completed state.
|
execute_callbacks
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def execute_state_callbacks(state)
while callback = @callbacks[state].shift
callback.call(*value)
end
end
|
Iterate all callbacks for a given state, and remove then call them.
|
execute_state_callbacks
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def clear_dead_callbacks
completion_states.each do |state|
@callbacks[state].clear
end
end
|
If we enter a completion state, clear other completion states after all
callback chains are completed. This means that operation specific
callbacks can't be dual-called, which is most common user error.
|
clear_dead_callbacks
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/completion.rb
|
Apache-2.0
|
def receive_data data
puts "............>>>#{data.length}"
end
|
Called by the event loop whenever data has been received by the network connection.
It is never called by user code. {#receive_data} is called with a single parameter, a String containing
the network protocol data, which may of course be binary. You will
generally redefine this method to perform your own processing of the incoming data.
Here's a key point which is essential to understanding the event-driven
programming model: <i>EventMachine knows absolutely nothing about the protocol
which your code implements.</i> You must not make any assumptions about
the size of the incoming data packets, or about their alignment on any
particular intra-message or PDU boundaries (such as line breaks).
receive_data can and will send you arbitrary chunks of data, with the
only guarantee being that the data is presented to your code in the order
it was collected from the network. Don't even assume that the chunks of
data will correspond to network packets, as EventMachine can and will coalesce
several incoming packets into one, to improve performance. The implication for your
code is that you generally will need to implement some kind of a state machine
in your redefined implementation of receive_data. For a better understanding
of this, read through the examples of specific protocol handlers in EventMachine::Protocols
The base-class implementation (which will be invoked only if you didn't override it in your protocol handler)
simply prints incoming data packet size to stdout.
@param [String] data Opaque incoming data.
@note Depending on the protocol, buffer sizes and OS networking stack configuration, incoming data may or may not be "a complete message".
It is up to this handler to detect content boundaries to determine whether all the content (for example, full HTTP request)
has been received and can be processed.
@see #post_init
@see #connection_completed
@see #unbind
@see #send_data
@see file:docs/GettingStarted.md EventMachine tutorial
|
receive_data
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def proxy_incoming_to(conn,bufsize=0)
EventMachine::enable_proxy(self, conn, bufsize)
end
|
EventMachine::Connection#proxy_incoming_to is called only by user code. It sets up
a low-level proxy relay for all data inbound for this connection, to the connection given
as the argument. This is essentially just a helper method for enable_proxy.
@see EventMachine.enable_proxy
|
proxy_incoming_to
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def close_connection after_writing = false
EventMachine::close_connection @signature, after_writing
end
|
EventMachine::Connection#close_connection is called only by user code, and never
by the event loop. You may call this method against a connection object in any
callback handler, whether or not the callback was made against the connection
you want to close. close_connection <i>schedules</i> the connection to be closed
at the next available opportunity within the event loop. You may not assume that
the connection is closed when close_connection returns. In particular, the framework
will callback the unbind method for the particular connection at a point shortly
after you call close_connection. You may assume that the unbind callback will
take place sometime after your call to close_connection completes. In other words,
the unbind callback will not re-enter your code "inside" of your call to close_connection.
However, it's not guaranteed that a future version of EventMachine will not change
this behavior.
{#close_connection} will *silently discard* any outbound data which you have
sent to the connection using {EventMachine::Connection#send_data} but which has not
yet been sent across the network. If you want to avoid this behavior, use
{EventMachine::Connection#close_connection_after_writing}.
|
close_connection
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def detach
EventMachine::detach_fd @signature
end
|
Removes given connection from the event loop.
The connection's socket remains open and its file descriptor number is returned.
|
detach
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def send_data data
data = data.to_s
size = data.bytesize if data.respond_to?(:bytesize)
size ||= data.size
EventMachine::send_data @signature, data, size
end
|
Call this method to send data to the remote end of the network connection. It takes a single String argument,
which may contain binary data. Data is buffered to be sent at the end of this event loop tick (cycle).
When used in a method that is event handler (for example, {#post_init} or {#connection_completed}, it will send
data to the other end of the connection that generated the event.
You can also call {#send_data} to write to other connections. For more information see The Chat Server Example in the
{file:docs/GettingStarted.md EventMachine tutorial}.
If you want to send some data and then immediately close the connection, make sure to use {#close_connection_after_writing}
instead of {#close_connection}.
@param [String] data Data to send asynchronously
@see file:docs/GettingStarted.md EventMachine tutorial
@see Connection#receive_data
@see Connection#post_init
@see Connection#unbind
|
send_data
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def error?
errno = EventMachine::report_connection_error_status(@signature)
case errno
when 0
false
when -1
true
else
EventMachine::ERRNOS[errno]
end
end
|
Returns true if the connection is in an error state, false otherwise.
In general, you can detect the occurrence of communication errors or unexpected
disconnection by the remote peer by handing the {#unbind} method. In some cases, however,
it's useful to check the status of the connection using {#error?} before attempting to send data.
This function is synchronous but it will return immediately without blocking.
@return [Boolean] true if the connection is in an error state, false otherwise
|
error?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def start_tls args={}
priv_key = args[:private_key_file]
cert_chain = args[:cert_chain_file]
verify_peer = args[:verify_peer]
sni_hostname = args[:sni_hostname]
cipher_list = args[:cipher_list]
ssl_version = args[:ssl_version]
ecdh_curve = args[:ecdh_curve]
dhparam = args[:dhparam]
fail_if_no_peer_cert = args[:fail_if_no_peer_cert]
[priv_key, cert_chain].each do |file|
next if file.nil? or file.empty?
raise FileNotFoundException,
"Could not find #{file} for start_tls" unless File.exist? file
end
protocols_bitmask = 0
if ssl_version.nil?
protocols_bitmask |= EventMachine::EM_PROTO_TLSv1
protocols_bitmask |= EventMachine::EM_PROTO_TLSv1_1
protocols_bitmask |= EventMachine::EM_PROTO_TLSv1_2
else
[ssl_version].flatten.each do |p|
case p.to_s.downcase
when 'sslv2'
protocols_bitmask |= EventMachine::EM_PROTO_SSLv2
when 'sslv3'
protocols_bitmask |= EventMachine::EM_PROTO_SSLv3
when 'tlsv1'
protocols_bitmask |= EventMachine::EM_PROTO_TLSv1
when 'tlsv1_1'
protocols_bitmask |= EventMachine::EM_PROTO_TLSv1_1
when 'tlsv1_2'
protocols_bitmask |= EventMachine::EM_PROTO_TLSv1_2
else
raise("Unrecognized SSL/TLS Protocol: #{p}")
end
end
end
EventMachine::set_tls_parms(@signature, priv_key || '', cert_chain || '', verify_peer, fail_if_no_peer_cert, sni_hostname || '', cipher_list || '', ecdh_curve || '', dhparam || '', protocols_bitmask)
EventMachine::start_tls @signature
end
|
Call {#start_tls} at any point to initiate TLS encryption on connected streams.
The method is smart enough to know whether it should perform a server-side
or a client-side handshake. An appropriate place to call {#start_tls} is in
your redefined {#post_init} method, or in the {#connection_completed} handler for
an outbound connection.
@option args [String] :cert_chain_file (nil) local path of a readable file that contants a chain of X509 certificates in
the [PEM format](http://en.wikipedia.org/wiki/Privacy_Enhanced_Mail),
with the most-resolved certificate at the top of the file, successive intermediate
certs in the middle, and the root (or CA) cert at the bottom.
@option args [String] :private_key_file (nil) local path of a readable file that must contain a private key in the [PEM format](http://en.wikipedia.org/wiki/Privacy_Enhanced_Mail).
@option args [Boolean] :verify_peer (false) indicates whether a server should request a certificate from a peer, to be verified by user code.
If true, the {#ssl_verify_peer} callback on the {EventMachine::Connection} object is called with each certificate
in the certificate chain provided by the peer. See documentation on {#ssl_verify_peer} for how to use this.
@option args [Boolean] :fail_if_no_peer_cert (false) Used in conjunction with verify_peer. If set the SSL handshake will be terminated if the peer does not provide a certificate.
@option args [String] :cipher_list ("ALL:!ADH:!LOW:!EXP:!DES-CBC3-SHA:@STRENGTH") indicates the available SSL cipher values. Default value is "ALL:!ADH:!LOW:!EXP:!DES-CBC3-SHA:@STRENGTH". Check the format of the OpenSSL cipher string at http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT.
@option args [String] :ecdh_curve (nil) The curve for ECDHE ciphers. See available ciphers with 'openssl ecparam -list_curves'
@option args [String] :dhparam (nil) The local path of a file containing DH parameters for EDH ciphers in [PEM format](http://en.wikipedia.org/wiki/Privacy_Enhanced_Mail) See: 'openssl dhparam'
@option args [Array] :ssl_version (TLSv1 TLSv1_1 TLSv1_2) indicates the allowed SSL/TLS versions. Possible values are: {SSLv2}, {SSLv3}, {TLSv1}, {TLSv1_1}, {TLSv1_2}.
@example Using TLS with EventMachine
require 'rubygems'
require 'eventmachine'
module Handler
def post_init
start_tls(:private_key_file => '/tmp/server.key', :cert_chain_file => '/tmp/server.crt', :verify_peer => false)
end
end
EventMachine.run do
EventMachine.start_server("127.0.0.1", 9999, Handler)
end
@param [Hash] args
@todo support passing an encryption parameter, which can be string or Proc, to get a passphrase
for encrypted private keys.
@todo support passing key material via raw strings or Procs that return strings instead of
just filenames.
@see #ssl_verify_peer
|
start_tls
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def get_peer_cert
EventMachine::get_peer_cert @signature
end
|
If [TLS](http://en.wikipedia.org/wiki/Transport_Layer_Security) is active on the connection, returns the remote [X509 certificate](http://en.wikipedia.org/wiki/X.509)
as a string, in the popular [PEM format](http://en.wikipedia.org/wiki/Privacy_Enhanced_Mail). This can then be used for arbitrary validation
of a peer's certificate in your code.
This should be called in/after the {#ssl_handshake_completed} callback, which indicates
that SSL/TLS is active. Using this callback is important, because the certificate may not
be available until the time it is executed. Using #post_init or #connection_completed is
not adequate, because the SSL handshake may still be taking place.
This method will return `nil` if:
* EventMachine is not built with [OpenSSL](http://www.openssl.org) support
* [TLS](http://en.wikipedia.org/wiki/Transport_Layer_Security) is not active on the connection
* TLS handshake is not yet complete
* Remote peer for any other reason has not presented a certificate
@example Getting peer TLS certificate information in EventMachine
module Handler
def post_init
puts "Starting TLS"
start_tls
end
def ssl_handshake_completed
puts get_peer_cert
close_connection
end
def unbind
EventMachine::stop_event_loop
end
end
EventMachine.run do
EventMachine.connect "mail.google.com", 443, Handler
end
# Will output:
# -----BEGIN CERTIFICATE-----
# MIIDIjCCAougAwIBAgIQbldpChBPqv+BdPg4iwgN8TANBgkqhkiG9w0BAQUFADBM
# MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg
# THRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBDQTAeFw0wODA1MDIxNjMyNTRaFw0w
# OTA1MDIxNjMyNTRaMGkxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlh
# MRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRgw
# FgYDVQQDEw9tYWlsLmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
# AoGBALlkxdh2QXegdElukCSOV2+8PKiONIS+8Tu9K7MQsYpqtLNC860zwOPQ2NLI
# 3Zp4jwuXVTrtzGuiqf5Jioh35Ig3CqDXtLyZoypjZUQcq4mlLzHlhIQ4EhSjDmA7
# Ffw9y3ckSOQgdBQWNLbquHh9AbEUjmhkrYxIqKXeCnRKhv6nAgMBAAGjgecwgeQw
# KAYDVR0lBCEwHwYIKwYBBQUHAwEGCCsGAQUFBwMCBglghkgBhvhCBAEwNgYDVR0f
# BC8wLTAroCmgJ4YlaHR0cDovL2NybC50aGF3dGUuY29tL1RoYXd0ZVNHQ0NBLmNy
# bDByBggrBgEFBQcBAQRmMGQwIgYIKwYBBQUHMAGGFmh0dHA6Ly9vY3NwLnRoYXd0
# ZS5jb20wPgYIKwYBBQUHMAKGMmh0dHA6Ly93d3cudGhhd3RlLmNvbS9yZXBvc2l0
# b3J5L1RoYXd0ZV9TR0NfQ0EuY3J0MAwGA1UdEwEB/wQCMAAwDQYJKoZIhvcNAQEF
# BQADgYEAsRwpLg1dgCR1gYDK185MFGukXMeQFUvhGqF8eT/CjpdvezyKVuz84gSu
# 6ccMXgcPQZGQN/F4Xug+Q01eccJjRSVfdvR5qwpqCj+6BFl5oiKDBsveSkrmL5dz
# s2bn7TdTSYKcLeBkjXxDLHGBqLJ6TNCJ3c4/cbbG5JhGvoema94=
# -----END CERTIFICATE-----
You can do whatever you want with the certificate String, such as load it
as a certificate object using the OpenSSL library, and check its fields.
@return [String] the remote [X509 certificate](http://en.wikipedia.org/wiki/X.509), in the popular [PEM format](http://en.wikipedia.org/wiki/Privacy_Enhanced_Mail),
if TLS is active on the connection
@see Connection#start_tls
@see Connection#ssl_handshake_completed
|
get_peer_cert
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def get_peername
EventMachine::get_peername @signature
end
|
This method is used with stream-connections to obtain the identity
of the remotely-connected peer. If a peername is available, this method
returns a sockaddr structure. The method returns nil if no peername is available.
You can use Socket.unpack_sockaddr_in and its variants to obtain the
values contained in the peername structure returned from #get_peername.
@example How to get peer IP address and port with EventMachine
require 'socket'
module Handler
def receive_data data
port, ip = Socket.unpack_sockaddr_in(get_peername)
puts "got #{data.inspect} from #{ip}:#{port}"
end
end
|
get_peername
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def get_sockname
EventMachine::get_sockname @signature
end
|
Used with stream-connections to obtain the identity
of the local side of the connection. If a local name is available, this method
returns a sockaddr structure. The method returns nil if no local name is available.
You can use {Socket.unpack_sockaddr_in} and its variants to obtain the
values contained in the local-name structure returned from this method.
@example
require 'socket'
module Handler
def receive_data data
port, ip = Socket.unpack_sockaddr_in(get_sockname)
puts "got #{data.inspect}"
end
end
|
get_sockname
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def get_pid
EventMachine::get_subprocess_pid @signature
end
|
Returns the PID (kernel process identifier) of a subprocess
associated with this Connection object. For use with {EventMachine.popen}
and similar methods. Returns nil when there is no meaningful subprocess.
@return [Integer]
|
get_pid
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def get_status
EventMachine::get_subprocess_status @signature
end
|
Returns a subprocess exit status. Only useful for {EventMachine.popen}. Call it in your
{#unbind} handler.
@return [Integer]
|
get_status
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def get_idle_time
EventMachine::get_idle_time @signature
end
|
The number of seconds since the last send/receive activity on this connection.
|
get_idle_time
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def comm_inactivity_timeout
EventMachine::get_comm_inactivity_timeout @signature
end
|
comm_inactivity_timeout returns the current value (float in seconds) of the inactivity-timeout
property of network-connection and datagram-socket objects. A nonzero value
indicates that the connection or socket will automatically be closed if no read or write
activity takes place for at least that number of seconds.
A zero value (the default) specifies that no automatic timeout will take place.
|
comm_inactivity_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def pending_connect_timeout
EventMachine::get_pending_connect_timeout @signature
end
|
The duration after which a TCP connection in the connecting state will fail.
It is important to distinguish this value from {EventMachine::Connection#comm_inactivity_timeout},
which looks at how long since data was passed on an already established connection.
The value is a float in seconds.
@return [Float] The duration after which a TCP connection in the connecting state will fail, in seconds.
|
pending_connect_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def reconnect server, port
EventMachine::reconnect server, port, self
end
|
Reconnect to a given host/port with the current instance
@param [String] server Hostname or IP address
@param [Integer] port Port to reconnect to
|
reconnect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def send_file_data filename
EventMachine::send_file_data @signature, filename
end
|
Like {EventMachine::Connection#send_data}, this sends data to the remote end of
the network connection. {EventMachine::Connection#send_file_data} takes a
filename as an argument, though, and sends the contents of the file, in one
chunk.
@param [String] filename Local path of the file to send
@see #send_data
@author Kirk Haines
|
send_file_data
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def stream_file_data filename, args={}
EventMachine::FileStreamer.new( self, filename, args )
end
|
Open a file on the filesystem and send it to the remote peer. This returns an
object of type {EventMachine::Deferrable}. The object's callbacks will be executed
on the reactor main thread when the file has been completely scheduled for
transmission to the remote peer. Its errbacks will be called in case of an error (such as file-not-found).
This method employs various strategies to achieve the fastest possible performance,
balanced against minimum consumption of memory.
Warning: this feature has an implicit dependency on an outboard extension,
evma_fastfilereader. You must install this extension in order to use {#stream_file_data}
with files larger than a certain size (currently 8192 bytes).
@option args [Boolean] :http_chunks (false) If true, this method will stream the file data in a format
compatible with the HTTP chunked-transfer encoding
@param [String] filename Local path of the file to stream
@param [Hash] args Options
@return [EventMachine::Deferrable]
|
stream_file_data
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def notify_readable?
EventMachine::is_notify_readable @signature
end
|
@return [Boolean] true if the connection is being watched for readability.
|
notify_readable?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def notify_writable?
EventMachine::is_notify_writable @signature
end
|
Returns true if the connection is being watched for writability.
|
notify_writable?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def pause
EventMachine::pause_connection @signature
end
|
Pause a connection so that {#send_data} and {#receive_data} events are not fired until {#resume} is called.
@see #resume
|
pause
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def resume
EventMachine::resume_connection @signature
end
|
Resume a connection's {#send_data} and {#receive_data} events.
@see #pause
|
resume
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def paused?
EventMachine::connection_paused? @signature
end
|
@return [Boolean] true if the connect was paused using {EventMachine::Connection#pause}.
@see #pause
@see #resume
|
paused?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/connection.rb
|
Apache-2.0
|
def callback &block
return unless block
@deferred_status ||= :unknown
if @deferred_status == :succeeded
block.call(*@deferred_args)
elsif @deferred_status != :failed
@callbacks ||= []
@callbacks.unshift block # << block
end
self
end
|
Specify a block to be executed if and when the Deferrable object receives
a status of :succeeded. See #set_deferred_status for more information.
Calling this method on a Deferrable object whose status is not yet known
will cause the callback block to be stored on an internal list.
If you call this method on a Deferrable whose status is :succeeded, the
block will be executed immediately, receiving the parameters given to the
prior #set_deferred_status call.
--
If there is no status, add a callback to an internal list.
If status is succeeded, execute the callback immediately.
If status is failed, do nothing.
|
callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
Apache-2.0
|
def cancel_callback block
@callbacks ||= []
@callbacks.delete block
end
|
Cancels an outstanding callback to &block if any. Undoes the action of #callback.
|
cancel_callback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
Apache-2.0
|
def errback &block
return unless block
@deferred_status ||= :unknown
if @deferred_status == :failed
block.call(*@deferred_args)
elsif @deferred_status != :succeeded
@errbacks ||= []
@errbacks.unshift block # << block
end
self
end
|
Specify a block to be executed if and when the Deferrable object receives
a status of :failed. See #set_deferred_status for more information.
--
If there is no status, add an errback to an internal list.
If status is failed, execute the errback immediately.
If status is succeeded, do nothing.
|
errback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
Apache-2.0
|
def cancel_errback block
@errbacks ||= []
@errbacks.delete block
end
|
Cancels an outstanding errback to &block if any. Undoes the action of #errback.
|
cancel_errback
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
Apache-2.0
|
def timeout seconds, *args
cancel_timeout
me = self
@deferred_timeout = EventMachine::Timer.new(seconds) {me.fail(*args)}
self
end
|
Setting a timeout on a Deferrable causes it to go into the failed state after
the Timeout expires (passing no arguments to the object's errbacks).
Setting the status at any time prior to a call to the expiration of the timeout
will cause the timer to be cancelled.
|
timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
Apache-2.0
|
def cancel_timeout
@deferred_timeout ||= nil
if @deferred_timeout
@deferred_timeout.cancel
@deferred_timeout = nil
end
end
|
Cancels an outstanding timeout if any. Undoes the action of #timeout.
|
cancel_timeout
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb
|
Apache-2.0
|
def initialize(list, concurrency = 1)
raise ArgumentError, 'concurrency must be bigger than zero' unless (concurrency > 0)
if list.respond_to?(:call)
@list = nil
@list_proc = list
elsif list.respond_to?(:to_a)
@list = list.to_a.dup
@list_proc = nil
else
raise ArgumentError, 'argument must be a proc or an array'
end
@concurrency = concurrency
@started = false
@ended = false
end
|
Create a new parallel async iterator with specified concurrency.
i = EM::Iterator.new(1..100, 10)
will create an iterator over the range that processes 10 items at a time. Iteration
is started via #each, #map or #inject
The list may either be an array-like object, or a proc that returns a new object
to be processed each time it is called. If a proc is used, it must return
EventMachine::Iterator::Stop to signal the end of the iterations.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
Apache-2.0
|
def each(foreach=nil, after=nil, &blk)
raise ArgumentError, 'proc or block required for iteration' unless foreach ||= blk
raise RuntimeError, 'cannot iterate over an iterator more than once' if @started or @ended
@started = true
@pending = 0
@workers = 0
all_done = proc{
after.call if after and @ended and @pending == 0
}
@process_next = proc{
# p [:process_next, :pending=, @pending, :workers=, @workers, :ended=, @ended, :concurrency=, @concurrency, :list=, @list]
unless @ended or @workers > @concurrency
item = next_item()
if item.equal?(Stop)
@ended = true
@workers -= 1
all_done.call
else
@pending += 1
is_done = false
on_done = proc{
raise RuntimeError, 'already completed this iteration' if is_done
is_done = true
@pending -= 1
if @ended
all_done.call
else
EM.next_tick(@process_next)
end
}
class << on_done
alias :next :call
end
foreach.call(item, on_done)
end
else
@workers -= 1
end
}
spawn_workers
self
end
|
Iterate over a set of items using the specified block or proc.
EM::Iterator.new(1..100).each do |num, iter|
puts num
iter.next
end
An optional second proc is invoked after the iteration is complete.
EM::Iterator.new(1..100).each(
proc{ |num,iter| iter.next },
proc{ puts 'all done' }
)
|
each
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
Apache-2.0
|
def map(foreach, after)
index = 0
inject([], proc{ |results,item,iter|
i = index
index += 1
is_done = false
on_done = proc{ |res|
raise RuntimeError, 'already returned a value for this iteration' if is_done
is_done = true
results[i] = res
iter.return(results)
}
class << on_done
alias :return :call
def next
raise NoMethodError, 'must call #return on a map iterator'
end
end
foreach.call(item, on_done)
}, proc{ |results|
after.call(results)
})
end
|
Collect the results of an asynchronous iteration into an array.
EM::Iterator.new(%w[ pwd uptime uname date ], 2).map(proc{ |cmd,iter|
EM.system(cmd){ |output,status|
iter.return(output)
}
}, proc{ |results|
p results
})
|
map
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
Apache-2.0
|
def inject(obj, foreach, after)
each(proc{ |item,iter|
is_done = false
on_done = proc{ |res|
raise RuntimeError, 'already returned a value for this iteration' if is_done
is_done = true
obj = res
iter.next
}
class << on_done
alias :return :call
def next
raise NoMethodError, 'must call #return on an inject iterator'
end
end
foreach.call(obj, item, on_done)
}, proc{
after.call(obj)
})
end
|
Inject the results of an asynchronous iteration onto a given object.
EM::Iterator.new(%w[ pwd uptime uname date ], 2).inject({}, proc{ |hash,cmd,iter|
EM.system(cmd){ |output,status|
hash[cmd] = status.exitstatus == 0 ? output.strip : nil
iter.return(hash)
}
}, proc{ |results|
p results
})
|
inject
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
Apache-2.0
|
def spawn_workers
EM.next_tick(start_worker = proc{
if @workers < @concurrency and !@ended
# p [:spawning_worker, :workers=, @workers, :concurrency=, @concurrency, :ended=, @ended]
@workers += 1
@process_next.call
EM.next_tick(start_worker)
end
})
nil
end
|
Spawn workers to consume items from the iterator's enumerator based on the current concurrency level.
|
spawn_workers
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
Apache-2.0
|
def next_item
if @list_proc
@list_proc.call
else
@list.empty? ? Stop : @list.shift
end
end
|
Return the next item from @list or @list_proc.
Once items have run out, will return EM::Iterator::Stop. Procs must supply this themselves
|
next_item
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/iterator.rb
|
Apache-2.0
|
def on_error *a, &b
@on_error = EM::Callback(*a, &b)
end
|
Define a default catch-all for when the deferrables returned by work
blocks enter a failed state. By default all that happens is that the
resource is returned to the pool. If on_error is defined, this block is
responsible for re-adding the resource to the pool if it is still usable.
In other words, it is generally assumed that on_error blocks explicitly
handle the rest of the lifetime of the resource.
|
on_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pool.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pool.rb
|
Apache-2.0
|
def perform(*a, &b)
work = EM::Callback(*a, &b)
@resources.pop do |resource|
if removed? resource
@removed.delete resource
reschedule work
else
process work, resource
end
end
end
|
Perform a given #call-able object or block. The callable object will be
called with a resource from the pool as soon as one is available, and is
expected to return a deferrable.
The deferrable will have callback and errback added such that when the
deferrable enters a finished state, the object is returned to the pool.
If on_error is defined, then objects are not automatically returned to the
pool.
|
perform
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pool.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pool.rb
|
Apache-2.0
|
def removed? resource
@removed.include? resource
end
|
Removed will show resources in a partial pruned state. Resources in the
removed list may not appear in the contents list if they are currently in
use.
|
removed?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pool.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pool.rb
|
Apache-2.0
|
def add_oneshot_timer interval
Reactor.instance.install_oneshot_timer(interval / 1000)
end
|
Changed 04Oct06: intervals from the caller are now in milliseconds, but our native-ruby
processor still wants them in seconds.
@private
|
add_oneshot_timer
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def send_datagram target, data, datalength, host, port
selectable = Reactor.instance.get_selectable( target ) or raise "unknown send_data target"
selectable.send_datagram data, Socket::pack_sockaddr_in(port, host)
end
|
This is currently only for UDP!
We need to make it work with unix-domain sockets as well.
@private
|
send_datagram
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def set_timer_quantum interval
Reactor.instance.set_timer_quantum(( 1.0 * interval) / 1000.0)
end
|
Sets reactor quantum in milliseconds. The underlying Reactor function wants a (possibly
fractional) number of seconds.
@private
|
set_timer_quantum
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def set_tls_parms signature, priv_key, cert_chain, verify_peer, fail_if_no_peer_cert, sni_hostname, cipher_list, ecdh_curve, dhparam, protocols_bitmask
bitmask = protocols_bitmask
ssl_options = OpenSSL::SSL::OP_ALL
ssl_options |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2) && EM_PROTO_SSLv2 & bitmask == 0
ssl_options |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3) && EM_PROTO_SSLv3 & bitmask == 0
ssl_options |= OpenSSL::SSL::OP_NO_TLSv1 if defined?(OpenSSL::SSL::OP_NO_TLSv1) && EM_PROTO_TLSv1 & bitmask == 0
ssl_options |= OpenSSL::SSL::OP_NO_TLSv1_1 if defined?(OpenSSL::SSL::OP_NO_TLSv1_1) && EM_PROTO_TLSv1_1 & bitmask == 0
ssl_options |= OpenSSL::SSL::OP_NO_TLSv1_2 if defined?(OpenSSL::SSL::OP_NO_TLSv1_2) && EM_PROTO_TLSv1_2 & bitmask == 0
@tls_parms ||= {}
@tls_parms[signature] = {
:verify_peer => verify_peer,
:fail_if_no_peer_cert => fail_if_no_peer_cert,
:ssl_options => ssl_options
}
@tls_parms[signature][:priv_key] = File.read(priv_key) if tls_parm_set?(priv_key)
@tls_parms[signature][:cert_chain] = File.read(cert_chain) if tls_parm_set?(cert_chain)
@tls_parms[signature][:sni_hostname] = sni_hostname if tls_parm_set?(sni_hostname)
@tls_parms[signature][:cipher_list] = cipher_list.gsub(/,\s*/, ':') if tls_parm_set?(cipher_list)
@tls_parms[signature][:dhparam] = File.read(dhparam) if tls_parm_set?(dhparam)
@tls_parms[signature][:ecdh_curve] = ecdh_curve if tls_parm_set?(ecdh_curve)
end
|
This method takes a series of positional arguments for specifying such
things as private keys and certificate chains. It's expected that the
parameter list will grow as we add more supported features. ALL of these
parameters are optional, and can be specified as empty or nil strings.
@private
|
set_tls_parms
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def initialize_for_run
@running = false
@stop_scheduled = false
@selectables ||= {}; @selectables.clear
@timers = SortedSet.new # []
set_timer_quantum(0.1)
@current_loop_time = Time.now
@next_heartbeat = @current_loop_time + HeartbeatInterval
end
|
Called before run, this is a good place to clear out arrays
with cruft that may be left over from a previous run.
@private
|
initialize_for_run
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def select_for_reading?
true unless (@close_scheduled || @close_requested)
end
|
If we have to close, or a close-after-writing has been requested,
then don't read any more data.
|
select_for_reading?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def select_for_writing?
unless @close_scheduled
if @outbound_q.empty?
@close_scheduled = true if @close_requested
false
else
true
end
end
end
|
If we have to close, don't select for writing.
Otherwise, see if the protocol is ready to close.
If not, see if he has data to send.
If a close-after-writing has been requested and the outbound queue
is empty, convert the status to close_scheduled.
|
select_for_writing?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def eventable_read
@last_activity = Reactor.instance.current_loop_time
begin
if io.respond_to?(:read_nonblock)
10.times {
data = io.read_nonblock(4096)
EventMachine::event_callback uuid, ConnectionData, data
}
else
data = io.sysread(4096)
EventMachine::event_callback uuid, ConnectionData, data
end
rescue Errno::EAGAIN, Errno::EWOULDBLOCK, SSLConnectionWaitReadable
# no-op
rescue Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Errno::EPIPE, OpenSSL::SSL::SSLError
@close_scheduled = true
EventMachine::event_callback uuid, ConnectionUnbound, nil
end
end
|
Proper nonblocking I/O was added to Ruby 1.8.4 in May 2006.
If we have it, then we can read multiple times safely to improve
performance.
The last-activity clock ASSUMES that we only come here when we
have selected readable.
TODO, coalesce multiple reads into a single event.
TODO, do the function check somewhere else and cache it.
|
eventable_read
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
def eventable_write
# coalesce the outbound array here, perhaps
@last_activity = Reactor.instance.current_loop_time
while data = @outbound_q.shift do
begin
data = data.to_s
w = if io.respond_to?(:write_nonblock)
io.write_nonblock data
else
io.syswrite data
end
if w < data.length
@outbound_q.unshift data[w..-1]
break
end
rescue Errno::EAGAIN, SSLConnectionWaitReadable, SSLConnectionWaitWritable
@outbound_q.unshift data
break
rescue EOFError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EPIPE, OpenSSL::SSL::SSLError
@close_scheduled = true
@outbound_q.clear
end
end
end
|
Provisional implementation. Will be re-implemented in subclasses.
TODO: Complete this implementation. As it stands, this only writes
a single packet per cycle. Highly inefficient, but required unless
we're running on a Ruby with proper nonblocking I/O (Ruby 1.8.4
built from sources from May 25, 2006 or newer).
We need to improve the loop so it writes multiple times, however
not more than a certain number of bytes per cycle, otherwise
one busy connection could hog output buffers and slow down other
connections. Also we should coalesce small writes.
URGENT TODO: Coalesce small writes. They are a performance killer.
The last-activity recorder ASSUMES we'll only come here if we've
selected writable.
|
eventable_write
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/pure_ruby.rb
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.