Class: RocketChat::Realtime::Adapter
- Inherits:
-
Object
- Object
- RocketChat::Realtime::Adapter
- Defined in:
- lib/rocket_chat/realtime/adapter.rb
Overview
Socket Adapter for WebSocket::Driver
Instance Attribute Summary collapse
- #monitor ⇒ Object readonly
- #url ⇒ Object readonly
Instance Method Summary collapse
- #dispose ⇒ Object
-
#initialize(url, monitor) ⇒ Adapter
constructor
A new instance of Adapter.
- #pending? ⇒ Boolean
-
#pump_buffer ⇒ Number
Pump Buffer.
-
#write(data) ⇒ Object
Enqueue data to send to server.
Constructor Details
#initialize(url, monitor) ⇒ Adapter
Returns a new instance of Adapter.
15 16 17 18 19 20 |
# File 'lib/rocket_chat/realtime/adapter.rb', line 15 def initialize(url, monitor) @url = url @monitor = monitor @mutex = Mutex.new @buffer = '' end |
Instance Attribute Details
#monitor ⇒ Object (readonly)
10 11 12 |
# File 'lib/rocket_chat/realtime/adapter.rb', line 10 def monitor @monitor end |
#url ⇒ Object (readonly)
10 11 12 |
# File 'lib/rocket_chat/realtime/adapter.rb', line 10 def url @url end |
Instance Method Details
#dispose ⇒ Object
26 27 28 |
# File 'lib/rocket_chat/realtime/adapter.rb', line 26 def dispose @monitor = nil end |
#pending? ⇒ Boolean
22 23 24 |
# File 'lib/rocket_chat/realtime/adapter.rb', line 22 def pending? @buffer.empty? == false end |
#pump_buffer ⇒ Number
Pump Buffer
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rocket_chat/realtime/adapter.rb', line 48 def pump_buffer @mutex.synchronize do written = 0 written = monitor.io.write_nonblock @buffer unless @buffer.empty? @buffer = @buffer.byteslice(written..-1) if written.positive? written end rescue IO::WaitWritable, IO::WaitReadable written ensure monitor.interests = pending? ? :rw : :r end |