Class: Terminus::Connector
- Inherits:
-
Object
- Object
- Terminus::Connector
- Defined in:
- lib/terminus/connector.rb
Constant Summary collapse
- RECV_SIZE =
1024
- BIND_TIMEOUT =
5
Instance Method Summary collapse
- #close ⇒ Object
- #connected? ⇒ Boolean
- #drain_socket ⇒ Object
-
#initialize(browser, timeout = BIND_TIMEOUT) ⇒ Connector
constructor
A new instance of Connector.
- #port ⇒ Object
- #request(message) ⇒ Object
- #reset ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(browser, timeout = BIND_TIMEOUT) ⇒ Connector
Returns a new instance of Connector.
32 33 34 35 36 37 38 |
# File 'lib/terminus/connector.rb', line 32 def initialize(browser, timeout = BIND_TIMEOUT) @browser = browser @skips = 0 @server = start_server @timeout = timeout reset end |
Instance Method Details
#close ⇒ Object
72 73 74 75 76 77 |
# File 'lib/terminus/connector.rb', line 72 def close [@server, @socket].compact.each do |s| s.close_read s.close_write end end |
#connected? ⇒ Boolean
46 47 48 |
# File 'lib/terminus/connector.rb', line 46 def connected? not @socket.nil? end |
#drain_socket ⇒ Object
68 69 70 |
# File 'lib/terminus/connector.rb', line 68 def drain_socket @closing = true if @socket end |
#port ⇒ Object
50 51 52 |
# File 'lib/terminus/connector.rb', line 50 def port @server.addr[1] end |
#request(message) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/terminus/connector.rb', line 54 def request() @browser.debug(:send, @browser.id, ) accept unless connected? @driver.text() true while @closing && receive result = receive @browser.debug(:recv, @browser.id, result) reset if result.nil? result rescue Errno::EBADF, Errno::ECONNRESET, Errno::EPIPE, Errno::EWOULDBLOCK reset nil end |
#reset ⇒ Object
40 41 42 43 44 |
# File 'lib/terminus/connector.rb', line 40 def reset @closing = false @driver = nil @socket = nil end |
#write(data) ⇒ Object
79 80 81 |
# File 'lib/terminus/connector.rb', line 79 def write(data) @socket.write(data) end |