Class: XRBP::WebSocket::Connection
- Inherits:
-
Object
- Object
- XRBP::WebSocket::Connection
- Includes:
- EventEmitter
- Defined in:
- lib/xrbp/websocket/connection.rb
Overview
Primary websocket interface, use Connection to perform websocket requests.
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#async_close! ⇒ Object
Close in a non-blocking way, and immediately return.
-
#close! ⇒ Object
Close the connection, blocking until completed.
- #close_cv ⇒ Object
-
#closed? ⇒ Boolean
Indicates the connection is closed (may not be completed).
-
#completed? ⇒ Boolean
Indicates if connection is completely closed and cleaned up.
- #completed_cv ⇒ Object
-
#connect ⇒ Object
Initiate new client connection.
-
#force_quit! ⇒ Object
Immediately terminate the connection and all related operations.
- #force_quit? ⇒ Boolean
-
#initialize(url) {|_self| ... } ⇒ Connection
constructor
A new instance of Connection.
-
#initialized? ⇒ Boolean
Indicates the connection is initialized.
-
#open? ⇒ Boolean
Indicates the connection is open.
- #open_cv ⇒ Object
- #plugin_namespace ⇒ Object
-
#send_data(data) ⇒ Object
Send raw data via this connection.
- #state_mutex ⇒ Object
-
#wait_for_close ⇒ Object
Block until connection is closed.
-
#wait_for_completed ⇒ Object
Block until connection is completed.
-
#wait_for_open ⇒ Object
Block until connection is open.
Constructor Details
#initialize(url) {|_self| ... } ⇒ Connection
Returns a new instance of Connection.
23 24 25 26 27 28 |
# File 'lib/xrbp/websocket/connection.rb', line 23 def initialize(url) @url = url @force_quit = false yield self if block_given? end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
21 22 23 |
# File 'lib/xrbp/websocket/connection.rb', line 21 def parent @parent end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
20 21 22 |
# File 'lib/xrbp/websocket/connection.rb', line 20 def url @url end |
Instance Method Details
#async_close! ⇒ Object
Close in a non-blocking way, and immediately return.
80 81 82 |
# File 'lib/xrbp/websocket/connection.rb', line 80 def async_close! client.async_close if open? end |
#close! ⇒ Object
Close the connection, blocking until completed
75 76 77 |
# File 'lib/xrbp/websocket/connection.rb', line 75 def close! client.close if open? end |
#close_cv ⇒ Object
139 140 141 |
# File 'lib/xrbp/websocket/connection.rb', line 139 def close_cv @close_cv ||= ConditionVariable.new end |
#closed? ⇒ Boolean
Indicates the connection is closed (may not be completed)
64 65 66 |
# File 'lib/xrbp/websocket/connection.rb', line 64 def closed? !open? end |
#completed? ⇒ Boolean
Indicates if connection is completely closed and cleaned up
70 71 72 |
# File 'lib/xrbp/websocket/connection.rb', line 70 def completed? client.completed? end |
#completed_cv ⇒ Object
143 144 145 |
# File 'lib/xrbp/websocket/connection.rb', line 143 def completed_cv @completed_cv ||= ConditionVariable.new end |
#connect ⇒ Object
Initiate new client connection
33 34 35 |
# File 'lib/xrbp/websocket/connection.rb', line 33 def connect client.connect end |
#force_quit! ⇒ Object
Immediately terminate the connection and all related operations
96 97 98 99 100 |
# File 'lib/xrbp/websocket/connection.rb', line 96 def force_quit! @force_quit = true wake_all # TODO immediate terminate socket connection end |
#force_quit? ⇒ Boolean
91 92 93 |
# File 'lib/xrbp/websocket/connection.rb', line 91 def force_quit? @force_quit end |
#initialized? ⇒ Boolean
Indicates the connection is initialized
53 54 55 |
# File 'lib/xrbp/websocket/connection.rb', line 53 def initialized? !!@client end |
#open? ⇒ Boolean
Indicates the connection is open
58 59 60 |
# File 'lib/xrbp/websocket/connection.rb', line 58 def open? initialized? && client.open? end |
#open_cv ⇒ Object
135 136 137 |
# File 'lib/xrbp/websocket/connection.rb', line 135 def open_cv @open_cv ||= ConditionVariable.new end |
#plugin_namespace ⇒ Object
16 17 18 |
# File 'lib/xrbp/websocket/connection.rb', line 16 def plugin_namespace WebSocket end |
#send_data(data) ⇒ Object
Send raw data via this connection
85 86 87 |
# File 'lib/xrbp/websocket/connection.rb', line 85 def send_data(data) client.send_data(data) end |
#state_mutex ⇒ Object
131 132 133 |
# File 'lib/xrbp/websocket/connection.rb', line 131 def state_mutex @state_mutex ||= Mutex.new end |
#wait_for_close ⇒ Object
Block until connection is closed
114 115 116 117 118 119 120 |
# File 'lib/xrbp/websocket/connection.rb', line 114 def wait_for_close return unless initialized? state_mutex.synchronize { close_cv.wait(state_mutex, 0.1) } while !force_quit? && open? end |
#wait_for_completed ⇒ Object
Block until connection is completed
123 124 125 126 127 128 129 |
# File 'lib/xrbp/websocket/connection.rb', line 123 def wait_for_completed return unless initialized? state_mutex.synchronize { completed_cv.wait(state_mutex, 0.1) } while !force_quit? && !completed? end |
#wait_for_open ⇒ Object
Block until connection is open
105 106 107 108 109 110 111 |
# File 'lib/xrbp/websocket/connection.rb', line 105 def wait_for_open return unless initialized? state_mutex.synchronize { open_cv.wait(state_mutex, 0.1) } until force_quit? || open? end |