Class: Chocomint::Console::Server::Connection
- Inherits:
-
Object
- Object
- Chocomint::Console::Server::Connection
- Defined in:
- lib/chocomint/console/server.rb
Overview
1 つの WebSocket 接続を ConPTY ワーカーへ橋渡しするアダプタ。
Instance Method Summary collapse
-
#initialize(socket, command:, cwd:, token:, logger:) ⇒ Connection
constructor
A new instance of Connection.
- #run ⇒ Object
-
#write(data) ⇒ Object
websocket-driver は write(String) を持つオブジェクトを要求する。.
Constructor Details
#initialize(socket, command:, cwd:, token:, logger:) ⇒ Connection
Returns a new instance of Connection.
63 64 65 66 67 68 69 70 71 |
# File 'lib/chocomint/console/server.rb', line 63 def initialize(socket, command:, cwd:, token:, logger:) @socket = socket @command = command @cwd = cwd @token = token @logger = logger @open = false @worker = nil end |
Instance Method Details
#run ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/chocomint/console/server.rb', line 78 def run @driver = WebSocket::Driver.server(self) setup_driver(@driver) loop do data = @socket.readpartial(65_536) @driver.parse(data) end rescue EOFError, IOError, Errno::ECONNRESET # クライアント切断。 ensure @pump&.kill @worker&.close end |
#write(data) ⇒ Object
websocket-driver は write(String) を持つオブジェクトを要求する。
74 75 76 |
# File 'lib/chocomint/console/server.rb', line 74 def write(data) @socket.write(data) end |