withruntime 0.28.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/withruntime/generated/apps.rb +192 -0
- data/lib/withruntime/generated/audit.rb +78 -0
- data/lib/withruntime/generated/browsers.rb +192 -0
- data/lib/withruntime/generated/builds.rb +192 -0
- data/lib/withruntime/generated/ci.rb +192 -0
- data/lib/withruntime/generated/containers.rb +192 -0
- data/lib/withruntime/generated/desktops.rb +192 -0
- data/lib/withruntime/generated/domains.rb +152 -0
- data/lib/withruntime/generated/egress_ips.rb +81 -0
- data/lib/withruntime/generated/events.rb +60 -0
- data/lib/withruntime/generated/feedback.rb +96 -0
- data/lib/withruntime/generated/functions.rb +192 -0
- data/lib/withruntime/generated/identities.rb +68 -0
- data/lib/withruntime/generated/images.rb +391 -0
- data/lib/withruntime/generated/job_runs.rb +110 -0
- data/lib/withruntime/generated/jobs.rb +333 -0
- data/lib/withruntime/generated/keys.rb +261 -0
- data/lib/withruntime/generated/kit.rb +111 -0
- data/lib/withruntime/generated/me.rb +69 -0
- data/lib/withruntime/generated/networks.rb +72 -0
- data/lib/withruntime/generated/notebooks.rb +192 -0
- data/lib/withruntime/generated/otel.rb +94 -0
- data/lib/withruntime/generated/ports.rb +118 -0
- data/lib/withruntime/generated/previews.rb +124 -0
- data/lib/withruntime/generated/projects.rb +108 -0
- data/lib/withruntime/generated/roles.rb +68 -0
- data/lib/withruntime/generated/routes.rb +11 -0
- data/lib/withruntime/generated/runtime.rb +188 -0
- data/lib/withruntime/generated/sandboxes.rb +1835 -0
- data/lib/withruntime/generated/secrets.rb +294 -0
- data/lib/withruntime/generated/sessions.rb +143 -0
- data/lib/withruntime/generated/sites.rb +192 -0
- data/lib/withruntime/generated/snapshots.rb +32 -0
- data/lib/withruntime/generated/tunnels.rb +165 -0
- data/lib/withruntime/generated/usage.rb +287 -0
- data/lib/withruntime/generated/volumes.rb +61 -0
- data/lib/withruntime/generated/webhooks.rb +91 -0
- data/lib/withruntime/generated/workspaces.rb +192 -0
- data/lib/withruntime/signing.rb +162 -0
- data/lib/withruntime/version.rb +2 -2
- data/lib/withruntime.rb +5 -43
- metadata +45 -35
- data/lib/withruntime/agents.rb +0 -877
- data/lib/withruntime/api_defaults.rb +0 -17
- data/lib/withruntime/apps.rb +0 -377
- data/lib/withruntime/browsers.rb +0 -104
- data/lib/withruntime/builds.rb +0 -218
- data/lib/withruntime/ci.rb +0 -164
- data/lib/withruntime/client.rb +0 -140
- data/lib/withruntime/containers.rb +0 -39
- data/lib/withruntime/credentials.rb +0 -111
- data/lib/withruntime/fields.rb +0 -40
- data/lib/withruntime/file_watch.rb +0 -73
- data/lib/withruntime/images.rb +0 -258
- data/lib/withruntime/network_products.rb +0 -49
- data/lib/withruntime/parity_products.rb +0 -51
- data/lib/withruntime/products.rb +0 -560
- data/lib/withruntime/record.rb +0 -99
- data/lib/withruntime/reservations.rb +0 -76
- data/lib/withruntime/sandbox.rb +0 -775
- data/lib/withruntime/tar.rb +0 -292
- data/lib/withruntime/transport.rb +0 -575
- data/lib/withruntime/tunnel.rb +0 -275
- data/lib/withruntime/wallet.rb +0 -68
- data/lib/withruntime/websocket.rb +0 -384
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "socket"
|
|
4
|
-
require "digest"
|
|
5
|
-
|
|
6
|
-
module WithRuntime
|
|
7
|
-
# One bounded RFC6455 connection, using the transport's origin, key and proxy rules.
|
|
8
|
-
class WebSocket
|
|
9
|
-
# The close code the server sent, once it closed.
|
|
10
|
-
attr_reader :timeout, :close_code
|
|
11
|
-
def initialize(transport, path, query = nil)
|
|
12
|
-
@transport = transport
|
|
13
|
-
@timeout = transport.timeout
|
|
14
|
-
@write_lock, @close_lock = Mutex.new, Mutex.new
|
|
15
|
-
@closed = false
|
|
16
|
-
uri = URI(transport.base_url)
|
|
17
|
-
proxy = Transport.send(:proxy_for, uri)
|
|
18
|
-
if proxy && proxy.scheme != "http"
|
|
19
|
-
raise Error.new("WebSocket proxy must use http CONNECT.", code: "proxy_unsupported")
|
|
20
|
-
end
|
|
21
|
-
@raw = Socket.tcp(proxy ? proxy.host : uri.host, proxy ? proxy.port : uri.port, connect_timeout: @timeout)
|
|
22
|
-
@io = @raw
|
|
23
|
-
deadline = now + @timeout
|
|
24
|
-
if proxy
|
|
25
|
-
authority = "#{uri.host}:#{uri.port}"
|
|
26
|
-
auth = proxy.user ? "Proxy-Authorization: Basic #{["#{URI.decode_www_form_component(proxy.user)}:#{URI.decode_www_form_component(proxy.password.to_s)}"].pack("m0")}\r\n" : ""
|
|
27
|
-
write_all("CONNECT #{authority} HTTP/1.1\r\nHost: #{authority}\r\n#{auth}\r\n", deadline)
|
|
28
|
-
raise Error.new("The proxy refused the WebSocket connection.", code: "proxy_refused") unless headers(deadline).first.match?(/\AHTTP\/1\.[01] 200 /)
|
|
29
|
-
end
|
|
30
|
-
if uri.scheme == "https"
|
|
31
|
-
context = OpenSSL::SSL::SSLContext.new
|
|
32
|
-
context.set_params
|
|
33
|
-
tls = OpenSSL::SSL::SSLSocket.new(@raw, context)
|
|
34
|
-
tls.hostname = uri.host
|
|
35
|
-
@io = tls
|
|
36
|
-
loop do
|
|
37
|
-
result = tls.connect_nonblock(exception: false)
|
|
38
|
-
break unless %i[wait_readable wait_writable].include?(result)
|
|
39
|
-
wait(result, deadline)
|
|
40
|
-
end
|
|
41
|
-
tls.post_connection_check(uri.host)
|
|
42
|
-
end
|
|
43
|
-
key = [SecureRandom.random_bytes(16)].pack("m0")
|
|
44
|
-
target = path + (query && !query.empty? ? "?#{URI.encode_www_form(query.reject { |_, value| value.nil? })}" : "")
|
|
45
|
-
host = uri.port == uri.default_port ? uri.host : "#{uri.host}:#{uri.port}"
|
|
46
|
-
write_all("GET #{target} HTTP/1.1\r\nHost: #{host}\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: #{key}\r\nAuthorization: Bearer #{transport.api_key}\r\nX-Runtime-Client: sdk-ruby/#{VERSION}\r\n\r\n", deadline)
|
|
47
|
-
status, fields = headers(deadline)
|
|
48
|
-
accept = [Digest::SHA1.digest(key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")].pack("m0")
|
|
49
|
-
unless status.match?(/\AHTTP\/1\.[01] 101 /) && fields["sec-websocket-accept"] == accept && fields["upgrade"].to_s.downcase == "websocket"
|
|
50
|
-
raise Error.new("The server refused the WebSocket upgrade.", code: "websocket_refused", status: status[/\AHTTP\/1\.[01] (\d{3})/, 1].to_i)
|
|
51
|
-
end
|
|
52
|
-
rescue *Transport::NETWORK_ERRORS => error
|
|
53
|
-
close
|
|
54
|
-
raise @transport.connection_error(error.is_a?(Timeout::Error), false, nil, error)
|
|
55
|
-
rescue StandardError
|
|
56
|
-
close
|
|
57
|
-
raise
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
61
|
-
def wait(direction, deadline)
|
|
62
|
-
left = deadline && deadline - now
|
|
63
|
-
raise Error.new("The stream deadline passed.", code: "timeout") if left && left <= 0
|
|
64
|
-
selected = direction == :wait_writable ? IO.select(nil, [@io], nil, left) : IO.select([@io], nil, nil, left)
|
|
65
|
-
raise Error.new("The stream deadline passed.", code: "timeout") unless selected
|
|
66
|
-
end
|
|
67
|
-
def exact(length, deadline = nil)
|
|
68
|
-
out = +"".b
|
|
69
|
-
while out.bytesize < length
|
|
70
|
-
part = @io.read_nonblock(length - out.bytesize, exception: false)
|
|
71
|
-
raise EOFError if part.nil?
|
|
72
|
-
if part.is_a?(Symbol)
|
|
73
|
-
wait(part, deadline)
|
|
74
|
-
else
|
|
75
|
-
out << part
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
out
|
|
79
|
-
end
|
|
80
|
-
def write_all(bytes, deadline)
|
|
81
|
-
at = 0
|
|
82
|
-
while at < bytes.bytesize
|
|
83
|
-
n = @io.write_nonblock(bytes.byteslice(at..), exception: false)
|
|
84
|
-
n.is_a?(Symbol) ? wait(n, deadline) : at += n
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
def headers(deadline)
|
|
88
|
-
text = +""
|
|
89
|
-
until text.end_with?("\r\n\r\n")
|
|
90
|
-
raise Error.new("WebSocket response headers are too large.", code: "websocket_protocol") if text.bytesize >= 65536
|
|
91
|
-
text << exact(1, deadline)
|
|
92
|
-
end
|
|
93
|
-
lines = text.split("\r\n")
|
|
94
|
-
[lines.shift, lines.to_h { |line| name, value = line.split(":", 2); [name.downcase, value.to_s.strip] }]
|
|
95
|
-
end
|
|
96
|
-
def send_frame(op, bytes)
|
|
97
|
-
bytes = bytes.b
|
|
98
|
-
@write_lock.synchronize do
|
|
99
|
-
raise IOError, "WebSocket closed" if @closed
|
|
100
|
-
mask = SecureRandom.random_bytes(4)
|
|
101
|
-
size = bytes.bytesize
|
|
102
|
-
header = [0x80 | op].pack("C")
|
|
103
|
-
header << if size < 126 then [0x80 | size].pack("C") elsif size <= 65535 then [0xfe, size].pack("Cn") else [0xff, size].pack("CQ>") end
|
|
104
|
-
masked = bytes.bytes.each_with_index.map { |value, index| value ^ mask.getbyte(index % 4) }.pack("C*")
|
|
105
|
-
write_all(header + mask + masked, now + @timeout)
|
|
106
|
-
end
|
|
107
|
-
rescue *Transport::NETWORK_ERRORS => error
|
|
108
|
-
raise @transport.connection_error(error.is_a?(Timeout::Error), false, nil, error)
|
|
109
|
-
end
|
|
110
|
-
def read(deadline = nil)
|
|
111
|
-
message = +"".b
|
|
112
|
-
kind = nil
|
|
113
|
-
loop do
|
|
114
|
-
first, second = exact(2, deadline).unpack("CC")
|
|
115
|
-
raise Error.new("Invalid WebSocket frame.", code: "websocket_protocol") unless (first & 0x70).zero? && (second & 0x80).zero?
|
|
116
|
-
op, final, length = first & 15, (first & 0x80) != 0, second & 127
|
|
117
|
-
length = exact(2, deadline).unpack1("n") if length == 126
|
|
118
|
-
length = exact(8, deadline).unpack1("Q>") if length == 127
|
|
119
|
-
if length > 1_048_581 || (op >= 8 && (!final || length > 125))
|
|
120
|
-
raise Error.new("WebSocket frame exceeds its bound.", code: "stream_overflow")
|
|
121
|
-
end
|
|
122
|
-
data = exact(length, deadline)
|
|
123
|
-
if op == 8
|
|
124
|
-
@close_code = data.bytesize >= 2 ? data.unpack1("n") : 1005
|
|
125
|
-
return nil
|
|
126
|
-
end
|
|
127
|
-
if op == 9
|
|
128
|
-
send_frame(10, data)
|
|
129
|
-
next
|
|
130
|
-
end
|
|
131
|
-
next if op == 10
|
|
132
|
-
if op == 0
|
|
133
|
-
raise Error.new("Unexpected continuation.", code: "websocket_protocol") unless kind
|
|
134
|
-
else
|
|
135
|
-
raise Error.new("Invalid data frame.", code: "websocket_protocol") unless [1, 2].include?(op) && kind.nil?
|
|
136
|
-
kind = op
|
|
137
|
-
end
|
|
138
|
-
message << data
|
|
139
|
-
raise Error.new("WebSocket message exceeds its bound.", code: "stream_overflow") if message.bytesize > 1_048_581
|
|
140
|
-
return [kind, message] if final
|
|
141
|
-
end
|
|
142
|
-
rescue *Transport::NETWORK_ERRORS => error
|
|
143
|
-
raise @transport.connection_error(error.is_a?(Timeout::Error), false, nil, error)
|
|
144
|
-
end
|
|
145
|
-
def close
|
|
146
|
-
return unless @close_lock
|
|
147
|
-
@close_lock.synchronize do
|
|
148
|
-
return if @closed
|
|
149
|
-
@closed = true
|
|
150
|
-
@raw&.close unless @raw&.closed?
|
|
151
|
-
end
|
|
152
|
-
rescue IOError, SystemCallError
|
|
153
|
-
nil
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# A terminal's or tunnel's WebSocket that outlives a restart of the API behind it
|
|
158
|
-
# (packages/cloud/src/api/tunnels.ts, "Hand-off"): on {"type":"restart"} it holds what is
|
|
159
|
-
# sent and answers; on {"type":"resume"} and close 1012 it opens the socket again with
|
|
160
|
-
# ?resume=<token>, sends {"type":"replay"} first, then what it held. Output continues from
|
|
161
|
-
# the byte it stopped at, and the reader sees no close.
|
|
162
|
-
class ResumableSocket
|
|
163
|
-
# RFC 6455 close code 1012, Service Restart.
|
|
164
|
-
SERVICE_RESTART = 1012
|
|
165
|
-
# How long reconnecting may take: within the token's 30 s, after which the API ends it.
|
|
166
|
-
RESUME_SECONDS = 25
|
|
167
|
-
attr_reader :timeout, :resumes, :replays
|
|
168
|
-
def initialize(transport, path, query = nil)
|
|
169
|
-
@transport, @path = transport, path
|
|
170
|
-
@socket = WebSocket.new(transport, path, query)
|
|
171
|
-
@timeout = @socket.timeout
|
|
172
|
-
# Orders sends, the restart's answer and the switch to a new socket. close never takes
|
|
173
|
-
# it, so it can close a socket under a send blocked holding it.
|
|
174
|
-
@send_lock = Mutex.new
|
|
175
|
-
@paused, @held, @closed, @resumes, @replays = false, [], false, 0, 0
|
|
176
|
-
end
|
|
177
|
-
def now = @socket.now
|
|
178
|
-
def send_frame(op, bytes)
|
|
179
|
-
@send_lock.synchronize do
|
|
180
|
-
raise IOError, "WebSocket closed" if @closed
|
|
181
|
-
next @held << [op, bytes.b] if @paused
|
|
182
|
-
@socket.send_frame(op, bytes)
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
# The next message the reader sees; the restart's own are not.
|
|
186
|
-
def read(deadline = nil)
|
|
187
|
-
loop do
|
|
188
|
-
socket = @socket
|
|
189
|
-
message = socket.read(deadline)
|
|
190
|
-
unless message
|
|
191
|
-
socket.close
|
|
192
|
-
token = @token
|
|
193
|
-
next if token && socket.close_code == SERVICE_RESTART && !@closed && resume(token)
|
|
194
|
-
said, @said = @said, nil
|
|
195
|
-
return said
|
|
196
|
-
end
|
|
197
|
-
if message[0] == 1 && message[1].bytesize <= 4096
|
|
198
|
-
reply = begin
|
|
199
|
-
JSON.parse(message[1])
|
|
200
|
-
rescue JSON::ParserError
|
|
201
|
-
nil
|
|
202
|
-
end
|
|
203
|
-
if reply.is_a?(Hash) && reply["type"] == "restart"
|
|
204
|
-
@send_lock.synchronize do
|
|
205
|
-
@paused = true
|
|
206
|
-
socket.send_frame(1, JSON.generate(type: "restart"))
|
|
207
|
-
end
|
|
208
|
-
next
|
|
209
|
-
end
|
|
210
|
-
if reply.is_a?(Hash) && reply["type"] == "resume" && reply["token"]
|
|
211
|
-
@token, @replay = reply["token"], reply["replay"]
|
|
212
|
-
next
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
return message
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
def close
|
|
219
|
-
@closed = true
|
|
220
|
-
@attempt&.close
|
|
221
|
-
# First unblocks a send in flight; then, under its lock, the socket a resume may have
|
|
222
|
-
# swapped in meanwhile.
|
|
223
|
-
@socket.close
|
|
224
|
-
@send_lock.synchronize do
|
|
225
|
-
@held.clear
|
|
226
|
-
@socket.close
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
private
|
|
231
|
-
|
|
232
|
-
# Opens the socket again where it stopped; false when it cannot.
|
|
233
|
-
def resume(token)
|
|
234
|
-
replay = @replay
|
|
235
|
-
@token = @replay = nil
|
|
236
|
-
deadline = now + RESUME_SECONDS
|
|
237
|
-
wait = 0.05
|
|
238
|
-
while !@closed && now < deadline
|
|
239
|
-
socket = nil
|
|
240
|
-
begin
|
|
241
|
-
socket = @attempt = WebSocket.new(@transport, @path, { "resume" => token })
|
|
242
|
-
# A close that came while it opened.
|
|
243
|
-
break socket.close if @closed
|
|
244
|
-
# A server that never answers must not hold this past the deadline.
|
|
245
|
-
message = socket.read(deadline)
|
|
246
|
-
reply = message && message[0] == 1 ? JSON.parse(message[1]) : nil
|
|
247
|
-
if reply.is_a?(Hash) && reply["type"] == "ready" && reply["resumed"]
|
|
248
|
-
return @send_lock.synchronize do
|
|
249
|
-
if @closed
|
|
250
|
-
socket.close
|
|
251
|
-
next false
|
|
252
|
-
end
|
|
253
|
-
@socket = socket
|
|
254
|
-
@resumes += 1
|
|
255
|
-
if replay && !replay.empty?
|
|
256
|
-
@replays += 1
|
|
257
|
-
socket.send_frame(1, JSON.generate(type: "replay", data: replay))
|
|
258
|
-
end
|
|
259
|
-
@held.each { |op, bytes| socket.send_frame(op, bytes) }
|
|
260
|
-
@held.clear
|
|
261
|
-
@paused = false
|
|
262
|
-
true
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
socket.close
|
|
266
|
-
if reply.is_a?(Hash) && reply["type"] == "error"
|
|
267
|
-
# Refused for good (the sandbox stopped, say): the reader reads the error.
|
|
268
|
-
@said = message
|
|
269
|
-
return false
|
|
270
|
-
end
|
|
271
|
-
rescue Error => error
|
|
272
|
-
socket&.close
|
|
273
|
-
# A 4xx other than 429: the token or the sandbox is not good, and asking again
|
|
274
|
-
# changes nothing.
|
|
275
|
-
return false if error.status.between?(400, 499) && error.status != 429
|
|
276
|
-
rescue JSON::ParserError, IOError, SystemCallError
|
|
277
|
-
socket&.close
|
|
278
|
-
ensure
|
|
279
|
-
@attempt = nil
|
|
280
|
-
end
|
|
281
|
-
sleep wait
|
|
282
|
-
wait = [wait * 2, 1].min
|
|
283
|
-
end
|
|
284
|
-
false
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
# Producer never waits for a reader. The stream owner decides how overflow is reported.
|
|
289
|
-
class StreamBuffer
|
|
290
|
-
def initialize
|
|
291
|
-
@lock, @changed = Mutex.new, ConditionVariable.new
|
|
292
|
-
@queue, @bytes, @ended = [], 0, false
|
|
293
|
-
end
|
|
294
|
-
def push(bytes)
|
|
295
|
-
@lock.synchronize do
|
|
296
|
-
return true if @ended
|
|
297
|
-
return false if @bytes + bytes.bytesize > 1 << 20 || @queue.length >= 1024
|
|
298
|
-
unless bytes.empty?
|
|
299
|
-
@queue << bytes
|
|
300
|
-
@bytes += bytes.bytesize
|
|
301
|
-
@changed.broadcast
|
|
302
|
-
end
|
|
303
|
-
true
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
def finish(error = nil)
|
|
307
|
-
@lock.synchronize { unless @ended; @ended = true; @error = error; @changed.broadcast; end }
|
|
308
|
-
end
|
|
309
|
-
def read(length = 65536)
|
|
310
|
-
raise ArgumentError, "length must be positive" unless length.positive?
|
|
311
|
-
@lock.synchronize do
|
|
312
|
-
@changed.wait(@lock) while @queue.empty? && !@ended
|
|
313
|
-
if @queue.empty?
|
|
314
|
-
raise @error if @error
|
|
315
|
-
return nil
|
|
316
|
-
end
|
|
317
|
-
data = @queue.shift
|
|
318
|
-
if data.bytesize > length
|
|
319
|
-
@queue.unshift(data.byteslice(length..))
|
|
320
|
-
data = data.byteslice(0, length)
|
|
321
|
-
end
|
|
322
|
-
@bytes -= data.bytesize
|
|
323
|
-
data
|
|
324
|
-
end
|
|
325
|
-
end
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
class Terminal
|
|
329
|
-
attr_reader :process_id, :exit_code
|
|
330
|
-
def initialize(sandbox, **options)
|
|
331
|
-
@socket = ResumableSocket.new(sandbox.transport, sandbox.path("/terminal"), Fields.body(options))
|
|
332
|
-
@buffer = StreamBuffer.new
|
|
333
|
-
deadline = @socket.now + @socket.timeout
|
|
334
|
-
loop do
|
|
335
|
-
message = @socket.read(deadline)
|
|
336
|
-
raise Error.new("Terminal ended before ready.", code: "terminal_refused") unless message
|
|
337
|
-
next unless message[0] == 1
|
|
338
|
-
reply = JSON.parse(message[1])
|
|
339
|
-
raise Error.from(0, reply, nil) if reply["type"] == "error"
|
|
340
|
-
if reply["type"] == "ready"
|
|
341
|
-
@process_id = reply["processId"]
|
|
342
|
-
break
|
|
343
|
-
end
|
|
344
|
-
end
|
|
345
|
-
@reader = Thread.new do
|
|
346
|
-
begin
|
|
347
|
-
while (message = @socket.read)
|
|
348
|
-
if message[0] == 2
|
|
349
|
-
raise Error.new("Read terminal output while writing input; its unread buffer is full.", code: "terminal_receive_overflow") unless @buffer.push(message[1])
|
|
350
|
-
else
|
|
351
|
-
reply = JSON.parse(message[1])
|
|
352
|
-
if reply["type"] == "exit"
|
|
353
|
-
@exit_code = reply["exitCode"]
|
|
354
|
-
break
|
|
355
|
-
end
|
|
356
|
-
raise Error.from(0, reply, nil) if reply["type"] == "error"
|
|
357
|
-
end
|
|
358
|
-
end
|
|
359
|
-
@buffer.finish
|
|
360
|
-
rescue StandardError => error
|
|
361
|
-
@buffer.finish(@closed ? nil : error)
|
|
362
|
-
ensure
|
|
363
|
-
@socket.close
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
rescue StandardError
|
|
367
|
-
@socket&.close
|
|
368
|
-
raise
|
|
369
|
-
end
|
|
370
|
-
def read(length = 65536) = @buffer.read(length)
|
|
371
|
-
def write(bytes)
|
|
372
|
-
bytes = bytes.to_s.b
|
|
373
|
-
(0...bytes.bytesize).step(65536) { |at| @socket.send_frame(2, bytes.byteslice(at, 65536)) }
|
|
374
|
-
bytes.bytesize
|
|
375
|
-
end
|
|
376
|
-
def resize(cols:, rows:) = @socket.send_frame(1, JSON.generate(type: "resize", cols: cols, rows: rows))
|
|
377
|
-
def close
|
|
378
|
-
@closed = true
|
|
379
|
-
@socket.close
|
|
380
|
-
@buffer.finish
|
|
381
|
-
nil
|
|
382
|
-
end
|
|
383
|
-
end
|
|
384
|
-
end
|