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 start_server host, port sd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 ) sd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true ) sd.bind( Socket.pack_sockaddr_in( port, host )) sd.listen( 50 ) # 5 is what you see in all the books. Ain't enough. EvmaTCPServer.new sd end
Versions of ruby 1.8.4 later than May 26 2006 will work properly with an object of type TCPServer. Prior versions won't so we play it safe and just build a socket.
start_server
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 begin 10.times { descriptor,peername = io.accept_nonblock sd = EvmaTCPClient.new descriptor sd.is_server = true EventMachine::event_callback uuid, ConnectionAccepted, sd.uuid } rescue Errno::EWOULDBLOCK, Errno::EAGAIN end end
-- accept_nonblock returns an array consisting of the accepted socket and a sockaddr_in which names the peer. Don't accept more than 10 at a time.
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 start_server chain sd = Socket.new( Socket::AF_LOCAL, Socket::SOCK_STREAM, 0 ) sd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true ) sd.bind( Socket.pack_sockaddr_un( chain )) sd.listen( 50 ) # 5 is what you see in all the books. Ain't enough. EvmaUNIXServer.new sd end
Versions of ruby 1.8.4 later than May 26 2006 will work properly with an object of type TCPServer. Prior versions won't so we play it safe and just build a socket.
start_server
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 begin 10.times { descriptor,peername = io.accept_nonblock sd = StreamObject.new descriptor EventMachine::event_callback uuid, ConnectionAccepted, sd.uuid } rescue Errno::EWOULDBLOCK, Errno::EAGAIN end end
-- accept_nonblock returns an array consisting of the accepted socket and a sockaddr_in which names the peer. Don't accept more than 10 at a time.
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 40.times { break if @outbound_q.empty? begin data,target = @outbound_q.first # This damn better be nonblocking. io.send data.to_s, 0, target @outbound_q.shift rescue Errno::EAGAIN # It's not been observed in testing that we ever get here. # True to the definition, packets will be accepted and quietly dropped # if the system is under pressure. break rescue EOFError, Errno::ECONNRESET @close_scheduled = true @outbound_q.clear end } end
#eventable_write This really belongs in DatagramObject, but there is some UDP-specific stuff.
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
def eventable_read begin if io.respond_to?(:recvfrom_nonblock) 40.times { data,@return_address = io.recvfrom_nonblock(16384) EventMachine::event_callback uuid, ConnectionData, data @return_address = nil } else raise "unimplemented datagram-read operation on this Ruby" end rescue Errno::EAGAIN # no-op rescue Errno::ECONNRESET, EOFError @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.
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 pop(*a, &b) cb = EM::Callback(*a, &b) EM.schedule do if @drain.empty? @drain = @sink @sink = [] end if @drain.empty? @popq << cb else cb.call @drain.shift end end nil # Always returns nil end
Pop items off the queue, running the block on the reactor thread. The pop will not happen immediately, but at some point in the future, either in the next tick, if the queue has data, or when the queue is populated. @return [NilClass] nil
pop
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
Apache-2.0
def push(*items) EM.schedule do @sink.push(*items) unless @popq.empty? @drain = @sink @sink = [] @popq.shift.call @drain.shift until @drain.empty? || @popq.empty? end end end
Push items onto the queue in the reactor thread. The items will not appear in the queue immediately, but will be scheduled for addition during the next reactor tick.
push
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
Apache-2.0
def empty? @drain.empty? && @sink.empty? end
@return [Boolean] @note This is a peek, it's not thread safe, and may only tend toward accuracy.
empty?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
Apache-2.0
def size @drain.size + @sink.size end
@return [Integer] Queue size @note This is a peek, it's not thread safe, and may only tend toward accuracy.
size
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/queue.rb
Apache-2.0
def receive_data(data) msg = nil begin msg = Resolv::DNS::Message.decode data rescue else req = @requests[msg.id] if req @requests.delete(msg.id) stop_timer if @requests.length == 0 req.receive_answer(msg) end end end
Decodes the packet, looks for the request and passes the response over to the requester
receive_data
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/resolver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/resolver.rb
Apache-2.0
def notify *x me = self EM.next_tick { # A notification executes in the context of this # SpawnedProcess object. That makes self and notify # work as one would expect. # y = me.call(*x) if y and y.respond_to?(:pull_out_yield_block) a,b = y.pull_out_yield_block set_receiver a self.notify if b end } end
Send a message to the spawned process
notify
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/spawnable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/spawnable.rb
Apache-2.0
def initialize connection, filename, args = {} @connection = connection @http_chunks = args[:http_chunks] if File.exist?(filename) @size = File.size(filename) if @size <= MappingThreshold stream_without_mapping filename else stream_with_mapping filename end else fail "file not found" end end
@param [EventMachine::Connection] connection @param [String] filename File path @option args [Boolean] :http_chunks (false) Use HTTP 1.1 style chunked-encoding semantics.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/streamer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/streamer.rb
Apache-2.0
def stream_one_chunk loop { if @position < @size if @connection.get_outbound_data_size > BackpressureLevel EventMachine::next_tick {stream_one_chunk} break else len = @size - @position len = ChunkSize if (len > ChunkSize) @connection.send_data( "#{len.to_s(16)}\r\n" ) if @http_chunks @connection.send_data( @mapping.get_chunk( @position, len )) @connection.send_data("\r\n") if @http_chunks @position += len end else @connection.send_data "0\r\n\r\n" if @http_chunks @mapping.close succeed break end } end
Used internally to stream one chunk at a time over multiple reactor ticks @private
stream_one_chunk
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/streamer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/streamer.rb
Apache-2.0
def ensure_mapping_extension_is_present @@fastfilereader ||= (require 'fastfilereaderext') end
We use an outboard extension class to get memory-mapped files. It's outboard to avoid polluting the core distro, but that means there's a "hidden" dependency on it. The first time we get here in any run, try to load up the dependency extension. User code will see a LoadError if it's not available, but code that doesn't require mapped files will work fine without it. This is a somewhat difficult compromise between usability and proper modularization. @private
ensure_mapping_extension_is_present
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/streamer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/streamer.rb
Apache-2.0
def initialize @resource = yield @running = true @queue = ::Queue.new @thread = Thread.new do @queue.pop.call while @running end end
The block should return the resource that will be yielded in a dispatch.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/threaded_resource.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/threaded_resource.rb
Apache-2.0
def dispatch completion = EM::Completion.new @queue << lambda do begin result = yield @resource completion.succeed result rescue => e completion.fail e end end completion end
Called on the EM thread, generally in a perform block to return a completion for the work.
dispatch
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/threaded_resource.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/threaded_resource.rb
Apache-2.0
def shutdown @running = false @queue << lambda {} @thread.join end
Kill the internal thread. should only be used to cleanup - generally only required for tests.
shutdown
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/threaded_resource.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/threaded_resource.rb
Apache-2.0
def initialize(*a, &b) @work = EM::Callback(*a, &b) @stops = [] @stopped = true end
Arguments: A callback (EM::Callback) to call each tick. If the call returns +:stop+ then the loop will be stopped. Any other value is ignored.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
Apache-2.0
def on_stop(*a, &b) if @stopped EM::Callback(*a, &b).call else @stops << EM::Callback(*a, &b) end end
Arguments: A callback (EM::Callback) to call once on the next stop (or immediately if already stopped).
on_stop
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
Apache-2.0
def stop @stopped = true until @stops.empty? @stops.shift.call end end
Stop the tick loop immediately, and call it's on_stop callbacks.
stop
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
Apache-2.0
def start raise ArgumentError, "double start" unless @stopped @stopped = false schedule end
Start the tick loop, will raise argument error if the loop is already running.
start
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/tick_loop.rb
Apache-2.0
def initialize interval, callback=nil, &block @signature = EventMachine::add_timer(interval, callback || block) end
Create a new timer that fires after a given number of seconds
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/timers.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/timers.rb
Apache-2.0
def initialize interval, callback=nil, &block @interval = interval @code = callback || block @cancelled = false @work = method(:fire) schedule end
Create a new periodic timer that executes every interval seconds
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/timers.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/timers.rb
Apache-2.0
def headers_2_hash hdrs self.class.headers_2_hash hdrs end
Basically a convenience method. We might create a subclass that does this automatically. But it's such a performance killer.
headers_2_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/header_and_content.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/header_and_content.rb
Apache-2.0
def connection_completed @connected = true send_request @args end
We send the request when we get a connection. AND, we set an instance variable to indicate we passed through here. That allows #unbind to know whether there was a successful connection. NB: This naive technique won't work when we have to support multiple requests on a single connection.
connection_completed
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient.rb
Apache-2.0
def parse_response_line if @headers.first =~ /\AHTTP\/1\.[01] ([\d]{3})/ @status = $1.to_i else set_deferred_status :failed, { :status => 0 # crappy way of signifying an unrecognized response. TODO, find a better way to do this. } close_connection end end
We get called here when we have received an HTTP response line. It's an opportunity to throw an exception or trigger other exceptional handling.
parse_response_line
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient.rb
Apache-2.0
def receive_header_line ln if ln.length == 0 if @header_lines.length > 0 process_header else @blanks += 1 if @blanks > 10 @conn.close_connection end end else @header_lines << ln if @header_lines.length > 100 @internal_error = :bad_header @conn.close_connection end end end
-- Allow up to ten blank lines before we get a real response line. Allow no more than 100 lines in the header.
receive_header_line
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def receive_chunk_header ln if ln.length > 0 chunksize = ln.to_i(16) if chunksize > 0 @conn.set_text_mode(ln.to_i(16)) else @content = @content ? @content.join : '' @chunk_trailer = true end else # We correctly come here after each chunk gets read. # p "Got A BLANK chunk line" end end
-- Cf RFC 2616 pgh 3.6.1 for the format of HTTP chunks.
receive_chunk_header
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def receive_chunked_text text # p "RECEIVED #{text.length} CHUNK" (@content ||= []) << text end
-- We get a single chunk. Append it to the incoming content and switch back to line mode.
receive_chunked_text
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def receive_sized_text text @content = text @conn.pop_request succeed(self) end
-- At the present time, we only handle contents that have a length specified by the content-length header.
receive_sized_text
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def get args if args.is_a?(String) args = {:uri=>args} end args[:verb] = "GET" request args end
Get a url req = conn.get(:uri => '/') req.callback{|response| puts response.content }
get
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def post args if args.is_a?(String) args = {:uri=>args} end args[:verb] = "POST" request args end
Post to a url req = conn.post('/data') req.callback{|response| puts response.content } -- XXX there's no way to supply a POST body.. wtf?
post
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def set_default_host_header host, port, ssl if (ssl and port != 443) or (!ssl and port != 80) @host_header = "#{host}:#{port}" else @host_header = host end end
-- Compute and remember a string to be used as the host header in HTTP requests unless the user overrides it with an argument to #request. @private
set_default_host_header
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def unbind super @closed = true (@requests || []).each {|r| r.fail} end
-- All pending requests, if any, must fail. We might come here without ever passing through connection_completed in case we can't connect to the server. We'll also get here when the connection closes (either because the server closes it, or we close it due to detecting an internal error or security violation). In either case, run down all pending requests, if any, and signal failure on them. Set and remember a flag (@closed) so we can immediately fail any subsequent requests. @private
unbind
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/httpclient2.rb
Apache-2.0
def receive_data data return unless (data and data.length > 0) # Do this stuff in lieu of a constructor. @lt2_mode ||= :lines @lt2_delimiter ||= "\n" @lt2_linebuffer ||= [] remaining_data = data while remaining_data.length > 0 if @lt2_mode == :lines delimiter_string = case @lt2_delimiter when Regexp remaining_data.slice(@lt2_delimiter) else @lt2_delimiter end ix = remaining_data.index(delimiter_string) if delimiter_string if ix @lt2_linebuffer << remaining_data[0...ix] ln = @lt2_linebuffer.join @lt2_linebuffer.clear if @lt2_delimiter == "\n" ln.chomp! end receive_line ln remaining_data = remaining_data[(ix+delimiter_string.length)..-1] else @lt2_linebuffer << remaining_data remaining_data = "" end elsif @lt2_mode == :text if @lt2_textsize needed = @lt2_textsize - @lt2_textpos will_take = if remaining_data.length > needed needed else remaining_data.length end @lt2_textbuffer << remaining_data[0...will_take] tail = remaining_data[will_take..-1] @lt2_textpos += will_take if @lt2_textpos >= @lt2_textsize # Reset line mode (the default behavior) BEFORE calling the # receive_binary_data. This makes it possible for user code # to call set_text_mode, enabling chains of text blocks # (which can possibly be of different sizes). set_line_mode receive_binary_data @lt2_textbuffer.join receive_end_of_binary_data end remaining_data = tail else receive_binary_data remaining_data remaining_data = "" end end end end
-- Will loop internally until there's no data left to read. That way the user-defined handlers we call can modify the handling characteristics on a per-token basis.
receive_data
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/linetext2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/linetext2.rb
Apache-2.0
def set_binary_mode size=nil set_text_mode size end
Alias for #set_text_mode, added for back-compatibility with LineAndTextProtocol.
set_binary_mode
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/linetext2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/linetext2.rb
Apache-2.0
def unbind @lt2_mode ||= nil if @lt2_mode == :text and @lt2_textpos > 0 receive_binary_data @lt2_textbuffer.join end end
In case of a dropped connection, we'll send a partial buffer to user code when in sized text mode. User overrides of #receive_binary_data need to be aware that they may get a short buffer.
unbind
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/linetext2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/linetext2.rb
Apache-2.0
def lbp_init_line_state @lpb_buffer = BufferedTokenizer.new("\n") @lbp_mode = :lines end
-- For internal use, establish protocol baseline for handling lines.
lbp_init_line_state
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/line_and_text.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/line_and_text.rb
Apache-2.0
def get *keys raise ArgumentError unless block_given? callback{ keys = keys.map{|k| k.to_s.gsub(/\s/,'_') } send_data "get #{keys.join(' ')}\r\n" @get_cbs << [keys, proc{ |values| yield *keys.map{ |k| values[k] } }] } end
# commands Get the value associated with one or multiple keys cache.get(:a){ |v| p v } cache.get(:a,:b,:c,:d){ |a,b,c,d| p [a,b,c,d] }
get
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
Apache-2.0
def set key, val, exptime = 0, &cb callback{ val = val.to_s send_cmd :set, key, 0, exptime, val.respond_to?(:bytesize) ? val.bytesize : val.size, !block_given? send_data val send_data Cdelimiter @set_cbs << cb if cb } end
Set the value for a given key cache.set :a, 'hello' cache.set(:missing, 'abc'){ puts "stored the value!" }
set
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
Apache-2.0
def get_hash *keys raise ArgumentError unless block_given? get *keys do |*values| yield keys.inject({}){ |hash, k| hash.update k => values[keys.index(k)] } end end
Gets multiple values as a hash cache.get_hash(:a, :b, :c, :d){ |h| puts h[:a] }
get_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
Apache-2.0
def delete key, expires = 0, &cb callback{ send_data "delete #{key} #{expires}#{cb ? '' : ' noreply'}\r\n" @del_cbs << cb if cb } end
Delete the value associated with a key cache.del :a cache.del(:b){ puts "deleted the value!" }
delete
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
Apache-2.0
def receive_data data (@buffer||='') << data while index = @buffer.index(Cdelimiter) begin line = @buffer.slice!(0,index+2) process_cmd line rescue ParserError @buffer[0...0] = line break end end end
-- 19Feb09 Switched to a custom parser, LineText2 is recursive and can cause stack overflows when there is too much data. include EM::P::LineText2 @private
receive_data
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
Apache-2.0
def unbind if @connected or @reconnecting EM.add_timer(1){ reconnect @host, @port } @connected = false @reconnecting = true @deferred_status = nil else raise 'Unable to connect to memcached server' end end
-- def receive_binary_data data @values[@cur_key] = data[0..-3] end @private
unbind
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/memcache.rb
Apache-2.0
def send_object obj data = serializer.dump(obj) send_data [data.respond_to?(:bytesize) ? data.bytesize : data.size, data].pack('Na*') end
Sends a ruby object over the network
send_object
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/object_protocol.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/object_protocol.rb
Apache-2.0
def readbytes(n) str = read(n) if str == nil raise EOFError, "End of file reached" end if str.size < n raise IOError, "data truncated" end str end
Reads exactly +n+ bytes. If the data read is nil an EOFError is raised. If the data read is too short an IOError is raised
readbytes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/postgres3.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/postgres3.rb
Apache-2.0
def dispatch_conn_message msg case msg when AuthentificationClearTextPassword raise ArgumentError, "no password specified" if @password.nil? send_data PasswordMessage.new(@password).dump when AuthentificationCryptPassword raise ArgumentError, "no password specified" if @password.nil? send_data PasswordMessage.new(@password.crypt(msg.salt)).dump when AuthentificationMD5Password raise ArgumentError, "no password specified" if @password.nil? require 'digest/md5' m = Digest::MD5.hexdigest(@password + @user) m = Digest::MD5.hexdigest(m + msg.salt) m = 'md5' + m send_data PasswordMessage.new(m).dump when AuthentificationKerberosV4, AuthentificationKerberosV5, AuthentificationSCMCredential raise "unsupported authentification" when AuthentificationOk when ErrorResponse raise msg.field_values.join("\t") when NoticeResponse @notice_processor.call(msg) if @notice_processor when ParameterStatus @params[msg.key] = msg.value when BackendKeyData # TODO #p msg when ReadyForQuery # TODO: use transaction status pc,@pending_conn = @pending_conn,nil pc.succeed true else raise "unhandled message type" end end
Cloned and modified from the postgres-pr.
dispatch_conn_message
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/postgres3.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/postgres3.rb
Apache-2.0
def dispatch_query_message msg case msg when DataRow @r.rows << msg.columns when CommandComplete @r.cmd_tag = msg.cmd_tag when ReadyForQuery pq,@pending_query = @pending_query,nil pq.succeed true, @r, @e when RowDescription @r.fields = msg.fields when CopyInResponse when CopyOutResponse when EmptyQueryResponse when ErrorResponse # TODO @e << msg when NoticeResponse @notice_processor.call(msg) if @notice_processor else # TODO end end
Cloned and modified from the postgres-pr.
dispatch_query_message
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/postgres3.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/postgres3.rb
Apache-2.0
def unbind unless @succeeded @return_values.elapsed_time = Time.now - @return_values.start_time @return_values.responder = @responder @return_values.code = @code @return_values.message = @msg set_deferred_status(:failed, @return_values) end end
We can get here in a variety of ways, all of them being failures unless the @succeeded flag is set. If a protocol success was recorded, then don't set a deferred success because the caller will already have done it (no need to wait until the connection closes to invoke the callbacks). @private
unbind
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
Apache-2.0
def invoke_error @return_values.elapsed_time = Time.now - @return_values.start_time @return_values.responder = @responder @return_values.code = @code @return_values.message = @msg set_deferred_status :failed, @return_values send_data "QUIT\r\n" close_connection_after_writing end
We encountered an error from the server and will close the connection. Use the error and message the server returned.
invoke_error
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
Apache-2.0
def invoke_internal_error msg = "???" @return_values.elapsed_time = Time.now - @return_values.start_time @return_values.responder = @responder @return_values.code = 900 @return_values.message = msg set_deferred_status :failed, @return_values send_data "QUIT\r\n" close_connection_after_writing end
We encountered an error on our side of the protocol and will close the connection. Use an extra-protocol error code (900) and use the message from the caller.
invoke_internal_error
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
Apache-2.0
def invoke_auth if @args[:auth] if @args[:auth][:type] == :plain psw = @args[:auth][:password] if psw.respond_to?(:call) psw = psw.call end #str = Base64::encode64("\0#{@args[:auth][:username]}\0#{psw}").chomp str = ["\0#{@args[:auth][:username]}\0#{psw}"].pack("m").gsub(/\n/, '') send_data "AUTH PLAIN #{str}\r\n" @responder = :receive_auth_response else return invoke_internal_error("unsupported auth type") end else invoke_mail_from end end
Perform an authentication. If the caller didn't request one, then fall through to the mail-from state.
invoke_auth
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpclient.rb
Apache-2.0
def process_help send_data "250 Ok, but unimplemented\r\n" end
TODO - implement this properly, the implementation is a stub!
process_help
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_vrfy send_data "502 Command not implemented\r\n" end
RFC2821, 3.5.3 Meaning of VRFY or EXPN Success Response: A server MUST NOT return a 250 code in response to a VRFY or EXPN command unless it has actually verified the address. In particular, a server MUST NOT return 250 if all it has done is to verify that the syntax given is valid. In that case, 502 (Command not implemented) or 500 (Syntax error, command unrecognized) SHOULD be returned. TODO - implement this properly, the implementation is a stub!
process_vrfy
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_expn send_data "502 Command not implemented\r\n" end
TODO - implement this properly, the implementation is a stub!
process_expn
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def reset_protocol_state init_protocol_state s,@state = @state,[] @state << :starttls if s.include?(:starttls) @state << :ehlo if s.include?(:ehlo) receive_transaction end
-- This is called at several points to restore the protocol state to a pre-transaction state. In essence, we "forget" having seen any valid command except EHLO and STARTTLS. We also have to callback user code, in case they're keeping track of senders, recipients, and whatnot. We try to follow the convention of avoiding the verb "receive" for internal method names except receive_line (which we inherit), and using only receive_xxx for user-overridable stubs. init_protocol_state is called when we initialize the connection as well as during reset_protocol_state. It does NOT call the user override method. This enables us to promise the users that they won't see the overridable fire except after EHLO and RSET, and after a message has been received. Although the latter may be wrong. The standard may allow multiple DATA segments with the same set of senders and recipients.
reset_protocol_state
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_ehlo domain if receive_ehlo_domain domain send_data "250-#{get_server_domain}\r\n" if @@parms[:starttls] send_data "250-STARTTLS\r\n" end if @@parms[:auth] send_data "250-AUTH PLAIN\r\n" end send_data "250-NO-SOLICITING\r\n" # TODO, size needs to be configurable. send_data "250 SIZE 20000000\r\n" reset_protocol_state @state << :ehlo else send_data "550 Requested action not taken\r\n" end end
-- EHLO/HELO is always legal, per the standard. On success it always clears buffers and initiates a mail "transaction." Which means that a MAIL FROM must follow. Per the standard, an EHLO/HELO or a RSET "initiates" an email transaction. Thereafter, MAIL FROM must be received before RCPT TO, before DATA. Not sure what this specific ordering achieves semantically, but it does make it easier to implement. We also support user-specified requirements for STARTTLS and AUTH. We make it impossible to proceed to MAIL FROM without fulfilling tls and/or auth, if the user specified either or both as required. We need to check the extension standard for auth to see if a credential is discarded after a RSET along with all the rest of the state. We'll behave as if it is. Now clearly, we can't discard tls after its been negotiated without dropping the connection, so that flag doesn't get cleared.
process_ehlo
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_auth str if @state.include?(:auth) send_data "503 auth already issued\r\n" elsif str =~ /\APLAIN\s?/i if $'.length == 0 # we got a partial response, so let the client know to send the rest @state << :auth_incomplete send_data("334 \r\n") else # we got the initial response, so go ahead & process it process_auth_line($') end #elsif str =~ /\ALOGIN\s+/i else send_data "504 auth mechanism not available\r\n" end end
-- So far, only AUTH PLAIN is supported but we should do at least LOGIN as well. TODO, support clients that send AUTH PLAIN with no parameter, expecting a 3xx response and a continuation of the auth conversation.
process_auth
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_data unless @state.include?(:rcpt) send_data "503 Operation sequence error\r\n" else succeeded = proc { send_data "354 Send it\r\n" @state << :data @databuffer = [] } failed = proc { send_data "550 Operation failed\r\n" } d = receive_data_command if d.respond_to?(:callback) d.callback(&succeeded) d.errback(&failed) else (d ? succeeded : failed).call end end end
-- Unusually, we can deal with a Deferrable returned from the user application. This was added to deal with a special case in a particular application, but it would be a nice idea to add it to the other user-code callbacks.
process_data
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_starttls if @@parms[:starttls] if @state.include?(:starttls) send_data "503 TLS Already negotiated\r\n" elsif ! @state.include?(:ehlo) send_data "503 EHLO required before STARTTLS\r\n" else send_data "220 Start TLS negotiation\r\n" start_tls(@@parms[:starttls_options] || {}) @state << :starttls end else process_unknown end end
-- STARTTLS may not be issued before EHLO, or unless the user has chosen to support it. If :starttls_options is present and :starttls is set in the parms pass the options in :starttls_options to start_tls. Do this if you want to use your own certificate e.g. {:cert_chain_file => "/etc/ssl/cert.pem", :private_key_file => "/etc/ssl/private/cert.key"}
process_starttls
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def process_mail_from sender if (@@parms[:starttls]==:required and [email protected]?(:starttls)) send_data "550 This server requires STARTTLS before MAIL FROM\r\n" elsif (@@parms[:auth]==:required and [email protected]?(:auth)) send_data "550 This server requires authentication before MAIL FROM\r\n" elsif @state.include?(:mail_from) send_data "503 MAIL already given\r\n" else unless receive_sender sender send_data "550 sender is unacceptable\r\n" else send_data "250 Ok\r\n" @state << :mail_from end end end
-- Requiring TLS is touchy, cf RFC2784. Requiring AUTH seems to be much more reasonable. We don't currently support any notion of deriving an authentication from the TLS negotiation, although that would certainly be reasonable. We DON'T allow MAIL FROM to be given twice. We DON'T enforce all the various rules for validating the sender or the reverse-path (like whether it should be null), and notifying the reverse path in case of delivery problems. All of that is left to the calling application.
process_mail_from
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def get_server_greeting "EventMachine SMTP Server" end
------------------------------------------ Everything from here on can be overridden in user code. The greeting returned in the initial connection message to the client.
get_server_greeting
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def get_server_domain "Ok EventMachine SMTP Server" end
The domain name returned in the first line of the response to a successful EHLO or HELO command.
get_server_domain
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def receive_data_chunk data @smtps_msg_size ||= 0 @smtps_msg_size += data.join.length STDERR.write "<#{@smtps_msg_size}>" end
Sent when data from the remote peer is available. The size can be controlled by setting the :chunksize parameter. This call can be made multiple times. The goal is to strike a balance between sending the data to the application one line at a time, and holding all of a very large message in memory.
receive_data_chunk
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def receive_message @@parms[:verbose] and $>.puts "Received complete message" true end
Sent after a message has been completely received. User code must return true or false to indicate whether the message has been accepted for delivery.
receive_message
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/smtpserver.rb
Apache-2.0
def connect parms={} send_frame "CONNECT", parms end
CONNECT command, for authentication connect :login => 'guest', :passcode => 'guest'
connect
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
Apache-2.0
def send destination, body, parms={} send_frame "SEND", parms.merge( :destination=>destination ), body.to_s end
SEND command, for publishing messages to a topic send '/topic/name', 'some message here'
send
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
Apache-2.0
def subscribe dest, ack=false send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")} end
SUBSCRIBE command, for subscribing to topics subscribe '/topic/name', false
subscribe
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
Apache-2.0
def ack msgid send_frame "ACK", 'message-id'=> msgid end
ACK command, for acknowledging receipt of messages module StompClient include EM::P::Stomp def connection_completed connect :login => 'guest', :passcode => 'guest' # subscribe with ack mode subscribe '/some/topic', true end def receive_msg msg if msg.command == "MESSAGE" ack msg.headers['message-id'] puts msg.body end end end
ack
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/stomp.rb
Apache-2.0
def local_ips return @@local_ips if defined?(@@local_ips) @@local_ips = [] @@local_ips << "127.0.0.1" if self.class.local_ipv4? @@local_ips << "::1" if self.class.local_ipv6? @@local_ips end
Returns an array with the localhost addresses (IPv4 and/or IPv6).
local_ips
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/em_test_helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/em_test_helper.rb
Apache-2.0
def windows? RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ end
http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
windows?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/em_test_helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/em_test_helper.rb
Apache-2.0
def jruby? defined? JRUBY_VERSION end
http://stackoverflow.com/questions/1342535/how-can-i-tell-if-im-running-from-jruby-vs-ruby/1685970#1685970
jruby?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/em_test_helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/em_test_helper.rb
Apache-2.0
def test_run_block assert !EM.reactor_running? a = nil EM.run_block { a = "Worked" } assert a assert !EM.reactor_running? end
-------------------------------------- EM#run_block starts the reactor loop, runs the supplied block, and then STOPS the loop automatically. Contrast with EM#run, which keeps running the reactor even after the supplied block completes.
test_run_block
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_basic.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_basic.rb
Apache-2.0
def test_idle_connection_count_epoll EM.epoll if EM.epoll? count = nil EM.run { count = EM.connection_count EM.stop_event_loop } assert_equal(0, count) end
Run this again with epoll enabled (if available)
test_idle_connection_count_epoll
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_connection_count.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_connection_count.rb
Apache-2.0
def test_idle_connection_count_kqueue EM.kqueue if EM.kqueue? count = nil EM.run { count = EM.connection_count EM.stop_event_loop } assert_equal(0, count) end
Run this again with kqueue enabled (if available)
test_idle_connection_count_kqueue
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_connection_count.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_connection_count.rb
Apache-2.0
def _test_descriptors EM.epoll EM.set_descriptor_table_size 60000 EM.run { EM.start_server "127.0.0.1", 9800, TestEchoServer $n = 0 $max = 0 100.times { EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1} } } assert_equal(0, $n) assert_equal(100, $max) end
Run a high-volume version of this test by kicking the number of connections up past 512. (Each connection uses two sockets, a client and a server.) (Will require running the test as root) This test exercises TCP clients and servers. XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
_test_descriptors
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_epoll.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_epoll.rb
Apache-2.0
def test_a assert_raises(RuntimeError) { EM.run { raise "some exception" } } end
Read the commentary in EM#run. This test exercises the ensure block in #run that makes sure EM#release_machine gets called even if an exception is thrown within the user code. Without the ensured call to release_machine, the second call to EM#run will fail with a C++ exception because the machine wasn't cleaned up properly.
test_a
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_exc.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_exc.rb
Apache-2.0
def test_invalid_signature # This works fine with kqueue, only fails with linux inotify. omit_if(EM.kqueue?) EM.run { file = Tempfile.new('foo') w1 = EventMachine.watch_file(file.path) w2 = EventMachine.watch_file(file.path) assert_raise EventMachine::InvalidSignature do w2.stop_watching end EM.stop } end
Refer: https://github.com/eventmachine/eventmachine/issues/512
test_invalid_signature
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_file_watch.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_file_watch.rb
Apache-2.0
def test_em_watch_file_unsupported assert true end
Because some rubies will complain if a TestCase class has no tests
test_em_watch_file_unsupported
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_file_watch.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_file_watch.rb
Apache-2.0
def test_recursive_callbacks n = 0 # counter assures that all the tests actually run. rc = RecursiveCallback.new rc.callback {|a| assert_equal(100, a) n += 1 rc.set_deferred_status :succeeded, 101, 101 } rc.callback {|a,b| assert_equal(101, a) assert_equal(101, b) n += 1 rc.set_deferred_status :succeeded, 102, 102, 102 } rc.callback {|a,b,c| assert_equal(102, a) assert_equal(102, b) assert_equal(102, c) n += 1 } rc.set_deferred_status :succeeded, 100 assert_equal(3, n) end
A Deferrable callback can call #set_deferred_status to change the values passed to subsequent callbacks.
test_recursive_callbacks
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_futures.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_futures.rb
Apache-2.0
def test_double_calls s = 0 e = 0 d = EM::DefaultDeferrable.new d.callback {s += 1} d.errback {e += 1} d.succeed # We expect the callback to be called, and the errback to be DISCARDED. d.fail # Presumably an error. We expect the errback NOT to be called. d.succeed # We expect the callback to have been discarded and NOT to be called again. assert_equal(1, s) assert_equal(0, e) end
It doesn't raise an error to set deferred status more than once. In fact, this is a desired and useful idiom when it happens INSIDE a callback or errback. However, it's less useful otherwise, and in fact would generally be indicative of a programming error. However, we would like to be resistant to such errors. So whenever we set deferred status, we also clear BOTH stacks of handlers.
test_double_calls
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_futures.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_futures.rb
Apache-2.0
def test_delayed_callbacks s1 = 0 s2 = 0 e = 0 d = EM::DefaultDeferrable.new d.callback {s1 += 1} d.succeed # Triggers and discards the callback. d.callback {s2 += 1} # This callback is executed immediately and discarded. d.errback {e += 1} # This errback should be DISCARDED and never execute. d.fail # To prove it, fail and assert e is 0 assert_equal( [1,1], [s1,s2] ) assert_equal( 0, e ) end
Adding a callback to a Deferrable that is already in a success state executes the callback immediately. The same applies to a an errback added to an already-failed Deferrable. HOWEVER, we expect NOT to be able to add errbacks to succeeded Deferrables, or callbacks to failed ones. We illustrate this with a rather contrived test. The test calls #fail after #succeed, which ordinarily would not happen in a real program. What we're NOT attempting to specify is what happens if a Deferrable is succeeded and then failed (or vice-versa). Should we then be able to add callbacks/errbacks of the appropriate type for immediate execution? For now at least, the official answer is "don't do that."
test_delayed_callbacks
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_futures.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_futures.rb
Apache-2.0
def test_interpret_headers the_connection = nil content = "A" * 50 headers = [ "GET / HTTP/1.0", "Accept: aaa", "User-Agent: bbb", "Host: ccc", "x-tempest-header:ddd" ] EM.run { EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn| the_connection = conn end setup_timeout EM.connect( "127.0.0.1", @port, StopOnUnbind ) do |c| headers.each { |h| c.send_data "#{h}\r\n" } c.send_data "\n" c.send_data content c.close_connection_after_writing end } hsh = the_connection.headers_2_hash( the_connection.my_headers.shift ) expect = { :accept => "aaa", :user_agent => "bbb", :host => "ccc", :x_tempest_header => "ddd" } assert_equal(expect, hsh) end
def x_test_multiple_content_length_headers # This is supposed to throw a RuntimeError but it throws a C++ exception instead. the_connection = nil content = "A" * 50 headers = ["aaa", "bbb", ["Content-length: #{content.length}"]*2, "ccc"].flatten EM.run { EM.start_server( "127.0.0.1", @port, SimpleTest ) do |conn| the_connection = conn end EM.add_timer(4) {raise "test timed out"} test_proc = proc { t = TCPSocket.new "127.0.0.1", @port headers.each {|h| t.write "#{h}\r\n" } t.write "\n" t.write content t.close } EM.defer test_proc, proc { EM.stop } } end
test_interpret_headers
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_hc.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_hc.rb
Apache-2.0
def test_post response = nil EM.run { EM.start_server '127.0.0.1', @port, PostContent setup_timeout(2) c = silent { EM::P::HttpClient.request( :host => '127.0.0.1', :port => @port, :method => :post, :request => "/aaa", :content => "XYZ", :content_type => "text/plain" )} c.callback {|r| response = r EM.stop } } assert_equal( 200, response[:status] ) assert_equal( "0123456789", response[:content] ) end
TODO, this is WRONG. The handler is asserting an HTTP 1.1 request, but the client is sending a 1.0 request. Gotta fix the client
test_post
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient.rb
Apache-2.0
def test_cookie ok = false EM.run { c = silent { EM::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80, :cookie=>"aaa=bbb" } c.callback { ok = true c.close_connection EM.stop } c.errback {EM.stop} } assert ok end
TODO, need a more intelligent cookie tester. In fact, this whole test-harness needs a beefier server implementation.
test_cookie
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient.rb
Apache-2.0
def test_version_1_0 ok = false EM.run { c = silent { EM::P::HttpClient.request( :host => "www.google.com", :port => 80, :version => "1.0" )} c.callback { ok = true c.close_connection EM.stop } c.errback {EM.stop} } assert ok end
We can tell the client to send an HTTP/1.0 request (default is 1.1). This is useful for suppressing chunked responses until those are working.
test_version_1_0
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient.rb
Apache-2.0
def test_connect EM.run { setup_timeout(1) EM.start_server '127.0.0.1', @port, TestServer silent do EM::P::HttpClient2.connect '127.0.0.1', @port EM::P::HttpClient2.connect( :host=>'127.0.0.1', :port=>@port ) end EM.stop } end
#connect returns an object which has made a connection to an HTTP server and exposes methods for making HTTP requests on that connection. #connect can take either a pair of parameters (a host and a port), or a single parameter which is a Hash.
test_connect
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient2.rb
Apache-2.0
def _test_get_multiple content = nil EM.run { setup_timeout(1) http = silent { EM::P::HttpClient2.connect "google.com", :version => '1.0' } d = http.get "/" d.callback { e = http.get "/" e.callback { content = e.content EM.stop } } } assert(content) end
Not a pipelined request because we wait for one response before we request the next. XXX this test is broken because it sends the second request to the first connection XXX right before the connection closes
_test_get_multiple
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient2.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_httpclient2.rb
Apache-2.0
def test_em_comm_inactivity_timeout_not_implemented assert true end
Because some rubies will complain if a TestCase class has no tests
test_em_comm_inactivity_timeout_not_implemented
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_inactivity_timeout.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_inactivity_timeout.rb
Apache-2.0
def test_ipv4_tcp_local_server omit_if(!Test::Unit::TestCase.public_ipv4?) @@received_data = nil @local_port = next_port setup_timeout(2) EM.run do EM::start_server(@@public_ipv4, @local_port) do |s| def s.receive_data data @@received_data = data EM.stop end end EM::connect(@@public_ipv4, @local_port) do |c| c.send_data "ipv4/tcp" end end assert_equal "ipv4/tcp", @@received_data end
Runs a TCP server in the local IPv4 address, connects to it and sends a specific data. Timeout in 2 seconds.
test_ipv4_tcp_local_server
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
Apache-2.0
def test_ipv4_udp_local_server omit_if(!Test::Unit::TestCase.public_ipv4?) @@received_data = nil @local_port = next_port setup_timeout(2) EM.run do EM::open_datagram_socket(@@public_ipv4, @local_port) do |s| def s.receive_data data @@received_data = data EM.stop end end EM::open_datagram_socket(@@public_ipv4, next_port) do |c| c.send_datagram "ipv4/udp", @@public_ipv4, @local_port end end assert_equal "ipv4/udp", @@received_data end
Runs a UDP server in the local IPv4 address, connects to it and sends a specific data. Timeout in 2 seconds.
test_ipv4_udp_local_server
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
Apache-2.0
def test_tcp_connect_to_invalid_ipv4 omit_if(!Test::Unit::TestCase.public_ipv4?) invalid_ipv4 = "9.9:9" EM.run do begin error = nil EM.connect(invalid_ipv4, 1234) rescue => e error = e ensure EM.stop assert_equal EM::ConnectionError, (error && error.class) end end end
Try to connect via TCP to an invalid IPv4. EM.connect should raise EM::ConnectionError.
test_tcp_connect_to_invalid_ipv4
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
Apache-2.0
def test_udp_send_datagram_to_invalid_ipv4 omit_if(!Test::Unit::TestCase.public_ipv4?) invalid_ipv4 = "9.9:9" EM.run do begin error = nil EM.open_datagram_socket(@@public_ipv4, next_port) do |c| c.send_datagram "hello", invalid_ipv4, 1234 end rescue => e error = e ensure EM.stop assert_equal EM::ConnectionError, (error && error.class) end end end
Try to send a UDP datagram to an invalid IPv4. EM.send_datagram should raise EM::ConnectionError.
test_udp_send_datagram_to_invalid_ipv4
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv4.rb
Apache-2.0
def test_ipv6_tcp_local_server @@received_data = nil @local_port = next_port setup_timeout(2) EM.run do EM.start_server(@@public_ipv6, @local_port) do |s| def s.receive_data data @@received_data = data EM.stop end end EM::connect(@@public_ipv6, @local_port) do |c| def c.unbind(reason) warn "unbind: #{reason.inspect}" if reason # XXX at least find out why it failed end c.send_data "ipv6/tcp" end end assert_equal "ipv6/tcp", @@received_data end
Runs a TCP server in the local IPv6 address, connects to it and sends a specific data. Timeout in 2 seconds.
test_ipv6_tcp_local_server
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
Apache-2.0
def test_ipv6_udp_local_server @@received_data = nil @local_port = next_port @@remote_ip = nil setup_timeout(2) EM.run do EM.open_datagram_socket(@@public_ipv6, @local_port) do |s| def s.receive_data data _port, @@remote_ip = Socket.unpack_sockaddr_in(get_peername) @@received_data = data EM.stop end end EM.open_datagram_socket(@@public_ipv6, next_port) do |c| c.send_datagram "ipv6/udp", @@public_ipv6, @local_port end end assert_equal @@remote_ip, @@public_ipv6 assert_equal "ipv6/udp", @@received_data end
Runs a UDP server in the local IPv6 address, connects to it and sends a specific data. Timeout in 2 seconds.
test_ipv6_udp_local_server
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
Apache-2.0
def test_tcp_connect_to_invalid_ipv6 invalid_ipv6 = "1:A" EM.run do begin error = nil EM.connect(invalid_ipv6, 1234) rescue => e error = e ensure EM.stop assert_equal EM::ConnectionError, (error && error.class) end end end
Try to connect via TCP to an invalid IPv6. EM.connect should raise EM::ConnectionError.
test_tcp_connect_to_invalid_ipv6
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
Apache-2.0
def test_udp_send_datagram_to_invalid_ipv6 invalid_ipv6 = "1:A" EM.run do begin error = nil EM.open_datagram_socket(@@public_ipv6, next_port) do |c| c.send_datagram "hello", invalid_ipv6, 1234 end rescue => e error = e ensure EM.stop assert_equal EM::ConnectionError, (error && error.class) end end end
Try to send a UDP datagram to an invalid IPv6. EM.send_datagram should raise EM::ConnectionError.
test_udp_send_datagram_to_invalid_ipv6
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
Apache-2.0
def test_ipv6_unavailable assert true end
Because some rubies will complain if a TestCase class has no tests.
test_ipv6_unavailable
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_ipv6.rb
Apache-2.0
def get_time(n=1) time = EM.current_time time.strftime('%H:%M:%S.') + time.tv_usec.to_s[0, n] end
By default, format the time with tenths-of-seconds. Some tests should ask for extra decimal places to ensure that delays between iterations will receive a changed time.
get_time
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_iterator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/eventmachine-1.2.7/tests/test_iterator.rb
Apache-2.0