Class: EventMachine::IOStreamer
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Deferrable
|
|
Inherits: | Object |
Defined in: | lib/em/io_streamer.rb |
Constant Summary
Class Method Summary
- .new(connection, io, opts = {}) ⇒ IOStreamer constructor
Instance Method Summary
-
#stream_one_chunk
private
Internal use only
Internal use only
Used internally to stream one chunk at a time over multiple reactor ticks.
Deferrable
- Included
#callback | Specify a block to be executed if and when the |
#cancel_callback | Cancels an outstanding callback to &block if any. |
#cancel_errback | Cancels an outstanding errback to &block if any. |
#cancel_timeout | Cancels an outstanding timeout if any. |
#errback | Specify a block to be executed if and when the |
#fail | Sugar for set_deferred_status(:failed, ...). |
#set_deferred_failure | Alias for Deferrable#fail. |
#set_deferred_status | Sets the "disposition" (status) of the |
#set_deferred_success | Alias for Deferrable#succeed. |
#succeed | Sugar for set_deferred_status(:succeeded, ...). |
#timeout | Setting a timeout on a |
Constructor Details
.new(connection, io, opts = {}) ⇒ IOStreamer
# File 'lib/em/io_streamer.rb', line 33
def initialize(connection, io, opts = {}) @connection = connection @io = io @http_chunks = opts[:http_chunks] @buff = String.new @io.binmode if @io.respond_to?(:binmode) stream_one_chunk end
Instance Method Details
#stream_one_chunk (private)
Used internally to stream one chunk at a time over multiple reactor ticks
# File 'lib/em/io_streamer.rb', line 47
def stream_one_chunk loop do if @io.eof? @connection.send_data "0\r\n\r\n" if @http_chunks succeed break end if @connection.respond_to?(:get_outbound_data_size) && (@connection.get_outbound_data_size > FileStreamer::BackpressureLevel) EventMachine::next_tick { stream_one_chunk } break end if @io.read(CHUNK_SIZE, @buff) @connection.send_data("#{@buff.length.to_s(16)}\r\n") if @http_chunks @connection.send_data(@buff) @connection.send_data("\r\n") if @http_chunks end end end