This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Enumerable | |
| class Reader | |
| def initialize(enumerable) | |
| @enumerable = enumerable | |
| @buffer = "".b | |
| end | |
| def read(nsize, buffer = nil) | |
| @iterator ||= @enumerable.enum_for(:each) | |
| (buffer ||= @buffer).clear |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # client | |
| > ruby test.rb 2>&1 | grep server | grep 'window_update\|data' > testframes.txt | |
| # server output, 143243 lines | |
| server (HTTP/2): {:type=>:data, :flags=>[], :payload=>40, :stream=>1} | |
| server (HTTP/2): {:type=>:data, :flags=>[], :payload=>20, :stream=>1} | |
| server (HTTP/2): {:type=>:data, :flags=>[], :payload=>312, :stream=>1} | |
| server (HTTP/2): {:type=>:data, :flags=>[], :payload=>58, :stream=>1} | |
| server (HTTP/2): {:type=>:data, :flags=>[], :payload=>22, :stream=>1} | |
| server (HTTP/2): {:type=>:data, :flags=>[], :payload=>83, :stream=>1} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Command: | |
| # server | |
| > bundle exec ruby test_script.rb 2>&1 | grep server | grep 'window_update\|data' > nghttpframes.txt | |
| # client | |
| > nghttp -vu http://#{host}:${port} | grep 'WINDOW_UPDATE\|DATA' | wc -l | |
| 7965 | |
| # server output, 7872 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def flatten(a, elems=[]) | |
| a.each do |e| | |
| case e | |
| when Array then flatten(e, elems) | |
| else elems << e | |
| end | |
| end | |
| el | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # chat.rb | |
| require 'sinatra/base' | |
| # this also loads celluloid io, let's keep that in mind | |
| require 'celluloid/current' | |
| require 'reel' | |
| # The chat server, an IO Event Loop held by the actor | |
| # Collects connections (Reel Event Streams) | |
| # | |
| # Contrary to EventMachine, there is no event callback for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module SEM | |
| module Celluloid | |
| module IOExtensions | |
| NEARZERO = 0.00001 | |
| def self.wait(t = nil) | |
| if t | |
| time = t.zero? ? NEARZERO : t | |
| Celluloid.timeout(time) { yield } | |
| else | |
| yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'celluloid/io' | |
| require 'mysql2' | |
| module Mysql2 | |
| module Celluloid | |
| # https://github.com/brianmario/mysql2/blob/master/lib/mysql2/em.rb | |
| # Almost direct copy of the eventmachine driver for mysql2. It's even less verbose, which can only be a plus. | |
| class Client < ::Mysql2::Client | |
| def query(sql, opts={}) | |
| if ::Celluloid::IO.evented? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'celluloid/io' | |
| require 'celluloid/autostart' | |
| class Server | |
| include Celluloid::IO | |
| finalizer :shutdown | |
| def initialize(host, port) | |
| puts "*** Starting server" | |
| @server = TCPServer.new(host, port) | |
| async.run |