BidiBuffer
is a Buffer
which can be receive data from threads othr than the thread of the corresponding Connection/Session.
It synchronizes access to a secondary internal +@oob_buffer+, which periodically is reconciled to the main internal +@buffer+.
Public Class methods
new(*)
[show source]
# File lib/httpx/plugins/stream_bidi.rb 90 def initialize(*) 91 super 92 @parent_thread = Thread.current 93 @oob_mutex = Thread::Mutex.new 94 @oob_buffer = "".b 95 end
Public Instance methods
<<(chunk)
[show source]
# File lib/httpx/plugins/stream_bidi.rb 97 def <<(chunk) 98 return super if Thread.current == @parent_thread 99 100 @oob_mutex.synchronize { @oob_buffer << chunk } 101 end
rebuffer()
reconciles the main and secondary buffer (which receives data from other threads).
[show source]
# File lib/httpx/plugins/stream_bidi.rb 104 def rebuffer 105 raise Error, "can only rebuffer while waiting on a response" unless Thread.current == @parent_thread 106 107 @oob_mutex.synchronize do 108 @buffer << @oob_buffer 109 @oob_buffer.clear 110 end 111 end