Module: GQTP::Backend::Eventmachine::Handler
- Included in:
- ServerHandler
- Defined in:
- lib/gqtp/backend/eventmachine.rb
Instance Method Summary collapse
- #post_init ⇒ Object
- #read(size, &block) ⇒ Object
- #receive_data(data) ⇒ Object
- #write(*chunks, &block) ⇒ Object
Instance Method Details
#post_init ⇒ Object
31 32 33 34 |
# File 'lib/gqtp/backend/eventmachine.rb', line 31 def post_init @read_callbacks = [] @buffer = "".force_encoding("ASCII-8BIT") end |
#read(size, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gqtp/backend/eventmachine.rb', line 47 def read(size, &block) if @buffer.bytesize >= size consume_data(size, block) else @read_callbacks << [size, block] end if block_given? nil else Request.new end end |
#receive_data(data) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/gqtp/backend/eventmachine.rb', line 60 def receive_data(data) @buffer << data until @read_callbacks.empty? size, callback = @read_callbacks.first break if @buffer.bytesize < size @read_callbacks.shift consume_data(size, callback) end end |
#write(*chunks, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gqtp/backend/eventmachine.rb', line 36 def write(*chunks, &block) chunks.each do |chunk| send_data(chunk) end if block_given? block.call else Request.new end end |