mt-lang 0.4.24 → 0.4.25
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/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -8
- data/lib/milk_tea/base.rb +1 -1
- data/lib/milk_tea/core/control_flow/builder.rb +12 -0
- data/lib/milk_tea/tooling/cli/commands/std.rb +84 -0
- data/lib/milk_tea/tooling/cli.rb +25 -0
- data/lib/milk_tea/tooling/linter/fix_engine.rb +100 -0
- data/lib/milk_tea/tooling/linter/release_rules.rb +69 -11
- data/lib/milk_tea/tooling/linter/visitors.rb +58 -31
- data/lib/milk_tea/tooling/linter.rb +8 -1
- data/lib/milk_tea/tooling/std_catalog.rb +277 -0
- data/lib/milk_tea/tooling.rb +1 -0
- data/std/async/libuv_runtime.mt +20 -23
- data/std/async/mailbox.mt +2 -2
- data/std/base64.mt +3 -6
- data/std/behavior_tree.mt +1 -6
- data/std/binary.mt +2 -5
- data/std/color.mt +20 -20
- data/std/cookie.mt +1 -4
- data/std/deque.mt +2 -8
- data/std/encoding.mt +1 -4
- data/std/fmt.mt +1 -4
- data/std/graph.mt +5 -1
- data/std/htn.mt +9 -1
- data/std/http/server.mt +1 -4
- data/std/http.mt +14 -17
- data/std/jobs.mt +9 -10
- data/std/json.mt +17 -28
- data/std/linked_map.mt +3 -9
- data/std/map.mt +1 -4
- data/std/net/channel.mt +6 -6
- data/std/net/lobby.mt +3 -3
- data/std/net/manager.mt +0 -1
- data/std/net/mux.mt +1 -1
- data/std/net/packet.mt +4 -1
- data/std/net/punch.mt +3 -2
- data/std/net/rpc.mt +1 -3
- data/std/net/session.mt +12 -25
- data/std/net/sync.mt +3 -3
- data/std/net/turn.mt +7 -3
- data/std/net.mt +145 -159
- data/std/noise.mt +11 -7
- data/std/ordered_map.mt +2 -8
- data/std/ordered_set.mt +3 -5
- data/std/path.mt +1 -4
- data/std/process.mt +7 -18
- data/std/random.mt +2 -2
- data/std/sdl3/runtime.mt +1 -1
- data/std/steering.mt +27 -4
- data/std/string.mt +1 -4
- data/std/tar.mt +8 -10
- data/std/terminal.mt +21 -40
- data/std/thread.mt +3 -4
- data/std/tls.mt +22 -29
- data/std/toml.mt +23 -31
- data/std/uri.mt +2 -1
- data/std/utility.mt +2 -2
- data/std/vec.mt +7 -17
- metadata +5 -3
data/std/http.mt
CHANGED
|
@@ -530,12 +530,10 @@ function discard_buffer_prefix(buffer: ref[vec.Vec[ubyte]], count: ptr_uint) ->
|
|
|
530
530
|
fatal(c"http.discard_buffer_prefix missing storage")
|
|
531
531
|
|
|
532
532
|
let remaining = buffer.len - count
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
read(data_ptr + index) = read(data_ptr + count + index)
|
|
538
|
-
index += 1
|
|
533
|
+
var index: ptr_uint = 0
|
|
534
|
+
while index < remaining:
|
|
535
|
+
read(data + index) = read(data + count + index)
|
|
536
|
+
index += 1
|
|
539
537
|
|
|
540
538
|
buffer.len = remaining
|
|
541
539
|
|
|
@@ -572,14 +570,14 @@ function parse_response_head(header_text: str) -> Result[ResponseHead, Error]:
|
|
|
572
570
|
Option.some as payload:
|
|
573
571
|
status_code = int<-payload.value
|
|
574
572
|
|
|
573
|
+
if first_space + 4 < status_line.len and status_line.byte_at(first_space + 4) != 32:
|
|
574
|
+
return Result[
|
|
575
|
+
ResponseHead,
|
|
576
|
+
Error
|
|
577
|
+
].failure(error = response_error("status line must separate code and reason with a space"))
|
|
578
|
+
|
|
575
579
|
var reason = string.String.create()
|
|
576
580
|
if first_space + 4 < status_line.len:
|
|
577
|
-
if status_line.byte_at(first_space + 4) != 32:
|
|
578
|
-
return Result[
|
|
579
|
-
ResponseHead,
|
|
580
|
-
Error
|
|
581
|
-
].failure(error = response_error("status line must separate code and reason with a space"))
|
|
582
|
-
|
|
583
581
|
let reason_start = first_space + 5
|
|
584
582
|
reason = string.String.from_str(status_line.slice(reason_start, status_line.len - reason_start))
|
|
585
583
|
|
|
@@ -641,10 +639,7 @@ function parse_response_head(header_text: str) -> Result[ResponseHead, Error]:
|
|
|
641
639
|
head.release()
|
|
642
640
|
return Result[ResponseHead, Error].failure(error = response_error("unsupported Transfer-Encoding"))
|
|
643
641
|
|
|
644
|
-
if next_line_end == header_text.len:
|
|
645
|
-
index = header_text.len
|
|
646
|
-
else:
|
|
647
|
-
index = next_line_end + 2
|
|
642
|
+
if next_line_end == header_text.len: index = header_text.len else: index = next_line_end + 2
|
|
648
643
|
|
|
649
644
|
if head.chunked:
|
|
650
645
|
head.content_length = Option[ptr_uint].none
|
|
@@ -844,7 +839,9 @@ async function read_chunked_body(stream: net.TcpStream, prefix: span[ubyte]) ->
|
|
|
844
839
|
return Result[
|
|
845
840
|
bytes.Bytes,
|
|
846
841
|
Error
|
|
847
|
-
].failure(error = response_error(
|
|
842
|
+
].failure(error = response_error(
|
|
843
|
+
"chunked response ended before trailers were complete"
|
|
844
|
+
))
|
|
848
845
|
|
|
849
846
|
buffer.append_span(chunk.as_span())
|
|
850
847
|
chunk.release()
|
data/std/jobs.mt
CHANGED
|
@@ -46,8 +46,8 @@ function error_from_mailbox(source: aio_mailbox.Error) -> Error:
|
|
|
46
46
|
return Error(code = source.code, message = source.message)
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
function noop_completion(
|
|
50
|
-
|
|
49
|
+
function noop_completion(_arg: ptr[void]) -> void:
|
|
50
|
+
pass
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
function stop_pool_state(state: ptr[PoolState]) -> void:
|
|
@@ -163,14 +163,13 @@ public function create_on(runtime: aio.Runtime, worker_count: ptr_uint) -> Resul
|
|
|
163
163
|
return Result[Pool, Error].failure(error = error_from_mailbox(payload.error))
|
|
164
164
|
Result.success as mailbox_payload:
|
|
165
165
|
let state = heap.must_alloc_zeroed[PoolState](1)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
state.completions = mailbox_payload.value
|
|
166
|
+
state.mutex = mutex_payload.value
|
|
167
|
+
state.condition = condition_payload.value
|
|
168
|
+
state.queue = deque.Deque[WorkItem].create()
|
|
169
|
+
state.queued_jobs = 0
|
|
170
|
+
state.running_jobs = 0
|
|
171
|
+
state.stopping = false
|
|
172
|
+
state.completions = mailbox_payload.value
|
|
174
173
|
|
|
175
174
|
var workers = vec.Vec[thread.Thread].with_capacity(worker_count)
|
|
176
175
|
var index: ptr_uint = 0
|
data/std/json.mt
CHANGED
|
@@ -112,15 +112,13 @@ public function object_value(value: ptr[Object]?) -> Value:
|
|
|
112
112
|
|
|
113
113
|
public function create_array_value() -> Value:
|
|
114
114
|
let array_ptr = heap.must_alloc[Array](1)
|
|
115
|
-
|
|
116
|
-
read(array_ptr) = Array.create()
|
|
115
|
+
read(array_ptr) = Array.create()
|
|
117
116
|
return array_value(array_ptr)
|
|
118
117
|
|
|
119
118
|
|
|
120
119
|
public function create_object_value() -> Value:
|
|
121
120
|
let object_ptr = heap.must_alloc[Object](1)
|
|
122
|
-
|
|
123
|
-
read(object_ptr) = Object.create()
|
|
121
|
+
read(object_ptr) = Object.create()
|
|
124
122
|
return object_value(object_ptr)
|
|
125
123
|
|
|
126
124
|
|
|
@@ -178,33 +176,28 @@ function value_as_object(value: Value) -> ptr[Object]?:
|
|
|
178
176
|
|
|
179
177
|
function convert_raw_array(item: ptr[cjson.JSON]) -> Result[Value, Error]:
|
|
180
178
|
let array_ptr = heap.must_alloc[Array](1)
|
|
181
|
-
|
|
182
|
-
read(array_ptr) = Array.create()
|
|
179
|
+
read(array_ptr) = Array.create()
|
|
183
180
|
|
|
184
181
|
let count = cjson.get_array_size(item)
|
|
185
182
|
if count < 0:
|
|
186
|
-
|
|
187
|
-
read(array_ptr).release()
|
|
183
|
+
read(array_ptr).release()
|
|
188
184
|
heap.release(array_ptr)
|
|
189
185
|
return Result[Value, Error].failure(error = error_message("json array size failed"))
|
|
190
186
|
|
|
191
187
|
var index: int = 0
|
|
192
188
|
while index < count:
|
|
193
189
|
let child = cjson.get_array_item(item, index) else:
|
|
194
|
-
|
|
195
|
-
read(array_ptr).release()
|
|
190
|
+
read(array_ptr).release()
|
|
196
191
|
heap.release(array_ptr)
|
|
197
192
|
return Result[Value, Error].failure(error = error_message("json array item missing"))
|
|
198
193
|
|
|
199
194
|
match convert_raw_value(child):
|
|
200
195
|
Result.failure as payload:
|
|
201
|
-
|
|
202
|
-
read(array_ptr).release()
|
|
196
|
+
read(array_ptr).release()
|
|
203
197
|
heap.release(array_ptr)
|
|
204
198
|
return Result[Value, Error].failure(error = payload.error)
|
|
205
199
|
Result.success as payload:
|
|
206
|
-
|
|
207
|
-
read(array_ptr).values.push(payload.value)
|
|
200
|
+
read(array_ptr).values.push(payload.value)
|
|
208
201
|
|
|
209
202
|
index += 1
|
|
210
203
|
|
|
@@ -213,30 +206,26 @@ function convert_raw_array(item: ptr[cjson.JSON]) -> Result[Value, Error]:
|
|
|
213
206
|
|
|
214
207
|
function convert_raw_object(item: ptr[cjson.JSON]) -> Result[Value, Error]:
|
|
215
208
|
let object_ptr = heap.must_alloc[Object](1)
|
|
216
|
-
|
|
217
|
-
read(object_ptr) = Object.create()
|
|
209
|
+
read(object_ptr) = Object.create()
|
|
218
210
|
|
|
219
211
|
var child = unsafe: ptr[cjson.JSON]?<-read(item).child
|
|
220
212
|
while child != null:
|
|
221
|
-
let current =
|
|
213
|
+
let current = child
|
|
222
214
|
let key_ptr = unsafe: ptr[char]?<-read(current).string else:
|
|
223
|
-
|
|
224
|
-
read(object_ptr).release()
|
|
215
|
+
read(object_ptr).release()
|
|
225
216
|
heap.release(object_ptr)
|
|
226
217
|
return Result[Value, Error].failure(error = error_message("json object key missing"))
|
|
227
218
|
|
|
228
219
|
match convert_raw_value(current):
|
|
229
220
|
Result.failure as payload:
|
|
230
|
-
|
|
231
|
-
read(object_ptr).release()
|
|
221
|
+
read(object_ptr).release()
|
|
232
222
|
heap.release(object_ptr)
|
|
233
223
|
return Result[Value, Error].failure(error = payload.error)
|
|
234
224
|
Result.success as payload:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
))
|
|
225
|
+
read(object_ptr).entries.push(Entry(
|
|
226
|
+
key = string.String.from_str(text.chars_as_str(key_ptr)),
|
|
227
|
+
value = payload.value
|
|
228
|
+
))
|
|
240
229
|
|
|
241
230
|
child = unsafe: ptr[cjson.JSON]?<-read(current).next
|
|
242
231
|
|
|
@@ -380,7 +369,7 @@ function render_with_mode(value: Value, pretty: bool) -> Result[string.String, E
|
|
|
380
369
|
if pretty:
|
|
381
370
|
let rendered_ptr = cjson.print(raw_value) else:
|
|
382
371
|
return Result[string.String, Error].failure(error = error_message("json print failed"))
|
|
383
|
-
defer: raw.cJSON_free(
|
|
372
|
+
defer: raw.cJSON_free(rendered_ptr)
|
|
384
373
|
return Result[
|
|
385
374
|
string.String,
|
|
386
375
|
Error
|
|
@@ -388,7 +377,7 @@ function render_with_mode(value: Value, pretty: bool) -> Result[string.String, E
|
|
|
388
377
|
|
|
389
378
|
let rendered_ptr = cjson.print_unformatted(raw_value) else:
|
|
390
379
|
return Result[string.String, Error].failure(error = error_message("json print failed"))
|
|
391
|
-
defer: raw.cJSON_free(
|
|
380
|
+
defer: raw.cJSON_free(rendered_ptr)
|
|
392
381
|
return Result[string.String, Error].success(value = string.String.from_str(text.chars_as_str(rendered_ptr)))
|
|
393
382
|
|
|
394
383
|
|
data/std/linked_map.mt
CHANGED
|
@@ -188,10 +188,7 @@ extending LinkedMap[K, V]:
|
|
|
188
188
|
new_capacity = 8
|
|
189
189
|
|
|
190
190
|
while new_capacity < min_capacity:
|
|
191
|
-
if new_capacity > heap.ptr_uint_max / 2:
|
|
192
|
-
new_capacity = min_capacity
|
|
193
|
-
else:
|
|
194
|
-
new_capacity *= 2
|
|
191
|
+
if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
|
|
195
192
|
|
|
196
193
|
let new_buckets = heap.must_alloc_zeroed[ptr[Node[K, V]]?](new_capacity)
|
|
197
194
|
let old_buckets = this.buckets
|
|
@@ -243,10 +240,7 @@ extending LinkedMap[K, V]:
|
|
|
243
240
|
)
|
|
244
241
|
read(bucket_ptr + index) = node
|
|
245
242
|
|
|
246
|
-
if tail == null:
|
|
247
|
-
this.head = node
|
|
248
|
-
else:
|
|
249
|
-
read(ptr[Node[K, V]]<-tail).order_next = node
|
|
243
|
+
if tail == null: this.head = node else: read(ptr[Node[K, V]]<-tail).order_next = node
|
|
250
244
|
this.tail = node
|
|
251
245
|
|
|
252
246
|
this.len += 1
|
|
@@ -267,7 +261,7 @@ extending LinkedMap[K, V]:
|
|
|
267
261
|
fatal(c"linked_map.LinkedMap.get_or_insert missing inserted value")
|
|
268
262
|
unsafe:
|
|
269
263
|
return ptr_of(read(ptr[Node[K, V]]<-current).value)
|
|
270
|
-
Option.some
|
|
264
|
+
Option.some:
|
|
271
265
|
fatal(c"linked_map.LinkedMap.get_or_insert replaced unexpectedly")
|
|
272
266
|
|
|
273
267
|
|
data/std/map.mt
CHANGED
|
@@ -181,10 +181,7 @@ extending Map[K, V]:
|
|
|
181
181
|
new_capacity = 8
|
|
182
182
|
|
|
183
183
|
while new_capacity < min_capacity:
|
|
184
|
-
if new_capacity > heap.ptr_uint_max / 2:
|
|
185
|
-
new_capacity = min_capacity
|
|
186
|
-
else:
|
|
187
|
-
new_capacity *= 2
|
|
184
|
+
if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
|
|
188
185
|
|
|
189
186
|
let new_buckets = heap.must_alloc_zeroed[ptr[Node[K, V]]?](new_capacity)
|
|
190
187
|
let old_buckets = this.buckets
|
data/std/net/channel.mt
CHANGED
|
@@ -418,7 +418,7 @@ extending HostMessage:
|
|
|
418
418
|
|
|
419
419
|
extending Channel:
|
|
420
420
|
public editable function release() -> void:
|
|
421
|
-
let protocol =
|
|
421
|
+
let protocol = ptr_of(this.protocol)
|
|
422
422
|
release_protocol_state(protocol)
|
|
423
423
|
this.socket.release()
|
|
424
424
|
|
|
@@ -442,7 +442,7 @@ extending Channel:
|
|
|
442
442
|
message = string.String.from_str("udp channel payload exceeds configured maximum")
|
|
443
443
|
))
|
|
444
444
|
|
|
445
|
-
let protocol =
|
|
445
|
+
let protocol = ptr_of(this.protocol)
|
|
446
446
|
let sequence = allocate_sequence(protocol)
|
|
447
447
|
(await send_connected_packet(this.socket, protocol, sequence, 0, content))?
|
|
448
448
|
return Result[uint, net.Error].success(value = sequence)
|
|
@@ -455,7 +455,7 @@ extending Channel:
|
|
|
455
455
|
message = string.String.from_str("udp channel payload exceeds configured maximum")
|
|
456
456
|
))
|
|
457
457
|
|
|
458
|
-
let protocol =
|
|
458
|
+
let protocol = ptr_of(this.protocol)
|
|
459
459
|
let pending_len = unsafe: read(protocol).pending_reliable.len()
|
|
460
460
|
if pending_len >= pending_window_limit(this.config):
|
|
461
461
|
return Result[uint, net.Error].failure(error = net.Error(
|
|
@@ -478,7 +478,7 @@ extending Channel:
|
|
|
478
478
|
defer: packet.release()
|
|
479
479
|
|
|
480
480
|
let header = decode_header(packet)?
|
|
481
|
-
let protocol =
|
|
481
|
+
let protocol = ptr_of(this.protocol)
|
|
482
482
|
remove_acked_pending(protocol, header.ack, header.ack_bits)
|
|
483
483
|
let is_new = mark_received(protocol, header.sequence)
|
|
484
484
|
let is_reliable = (header.packet_flags & reliable_flag) != 0
|
|
@@ -499,7 +499,7 @@ extending Channel:
|
|
|
499
499
|
|
|
500
500
|
|
|
501
501
|
public async editable function tick(frame: uint) -> Result[ptr_uint, net.Error]:
|
|
502
|
-
let protocol =
|
|
502
|
+
let protocol = ptr_of(this.protocol)
|
|
503
503
|
var resent: ptr_uint = 0
|
|
504
504
|
var index: ptr_uint = 0
|
|
505
505
|
while true:
|
|
@@ -537,7 +537,7 @@ extending Host:
|
|
|
537
537
|
if removed.is_none():
|
|
538
538
|
break
|
|
539
539
|
var peer = removed.unwrap()
|
|
540
|
-
let peer_ptr =
|
|
540
|
+
let peer_ptr = ptr_of(peer)
|
|
541
541
|
release_peer_state(peer_ptr)
|
|
542
542
|
|
|
543
543
|
this.peers.release()
|
data/std/net/lobby.mt
CHANGED
|
@@ -263,8 +263,7 @@ public async function discover_lobbies_on(
|
|
|
263
263
|
Result.success:
|
|
264
264
|
pass
|
|
265
265
|
|
|
266
|
-
let
|
|
267
|
-
let _ = await conn.mux_send(lobby_channel, type_discover_request, empty.as_span(), mux.flag_reliable)
|
|
266
|
+
let _ = await conn.mux_send(lobby_channel, type_discover_request, zero[span[ubyte]], mux.flag_reliable)
|
|
268
267
|
|
|
269
268
|
var frame: uint = 0
|
|
270
269
|
var result = vec.Vec[LobbyInfo].create()
|
|
@@ -714,7 +713,8 @@ public function build_beacon_probe() -> bytes.Bytes:
|
|
|
714
713
|
public function is_beacon_probe(data: span[ubyte]) -> bool:
|
|
715
714
|
if data.len < beacon_probe_len:
|
|
716
715
|
return false
|
|
717
|
-
return data[0] == beacon_magic[0] and data[1] == beacon_magic[1] and
|
|
716
|
+
return data[0] == beacon_magic[0] and data[1] == beacon_magic[1] and
|
|
717
|
+
data[2] == beacon_magic[2] and data[3] == beacon_magic[3]
|
|
718
718
|
|
|
719
719
|
|
|
720
720
|
public function build_beacon_response(info: ref[LobbyInfo]) -> bytes.Bytes:
|
data/std/net/manager.mt
CHANGED
data/std/net/mux.mt
CHANGED
|
@@ -728,7 +728,7 @@ function assemble_fragment(
|
|
|
728
728
|
let buf_data = heap.must_alloc[ubyte](full_size)
|
|
729
729
|
var fill: ptr_uint = 0
|
|
730
730
|
while fill < full_size:
|
|
731
|
-
|
|
731
|
+
read(buf_data + fill) = 0
|
|
732
732
|
fill += 1
|
|
733
733
|
buf = bytes.Bytes(data = buf_data, len = full_size)
|
|
734
734
|
buffers.push(FragBuffer(
|
data/std/net/packet.mt
CHANGED
|
@@ -44,7 +44,10 @@ function decode_packet_length(header: bytes.Bytes) -> ptr_uint:
|
|
|
44
44
|
fatal(c"packet frame header length mismatch")
|
|
45
45
|
|
|
46
46
|
let header_span = header.as_span()
|
|
47
|
-
let length = ((uint<-header_span[0]) << 24) |
|
|
47
|
+
let length = ((uint<-header_span[0]) << 24) |
|
|
48
|
+
((uint<-header_span[1]) << 16) |
|
|
49
|
+
((uint<-header_span[2]) << 8) |
|
|
50
|
+
(uint<-header_span[3])
|
|
48
51
|
return length
|
|
49
52
|
|
|
50
53
|
|
data/std/net/punch.mt
CHANGED
|
@@ -72,7 +72,8 @@ public function build_punch_probe() -> bytes.Bytes:
|
|
|
72
72
|
public function is_punch_probe(data: span[ubyte]) -> bool:
|
|
73
73
|
if data.len < 4z:
|
|
74
74
|
return false
|
|
75
|
-
return data[0] == punch_magic[0] and data[1] == punch_magic[1] and
|
|
75
|
+
return data[0] == punch_magic[0] and data[1] == punch_magic[1] and
|
|
76
|
+
data[2] == punch_magic[2] and data[3] == punch_magic[3]
|
|
76
77
|
|
|
77
78
|
|
|
78
79
|
function result_from_datagram(
|
|
@@ -125,7 +126,7 @@ public async function punch(
|
|
|
125
126
|
break
|
|
126
127
|
let send_result = await socket.send_to(probe.as_span(), unsafe: read(cand_ptr).address)
|
|
127
128
|
match send_result:
|
|
128
|
-
Result.failure
|
|
129
|
+
Result.failure:
|
|
129
130
|
return Result[PunchResult, Error].failure(
|
|
130
131
|
error = punch_error(err_send_failed, "burst send failed")
|
|
131
132
|
)
|
data/std/net/rpc.mt
CHANGED
|
@@ -47,9 +47,7 @@ public function parse_request_id(data: span[ubyte]) -> Result[uint, Error]:
|
|
|
47
47
|
|
|
48
48
|
public function payload_after_header(data: span[ubyte]) -> span[ubyte]:
|
|
49
49
|
if data.len <= header_bytes:
|
|
50
|
-
|
|
51
|
-
let result = empty.as_span()
|
|
52
|
-
return result
|
|
50
|
+
return zero[span[ubyte]]
|
|
53
51
|
unsafe:
|
|
54
52
|
return span[ubyte](data = data.data + header_bytes, len = data.len - header_bytes)
|
|
55
53
|
|
data/std/net/session.mt
CHANGED
|
@@ -169,7 +169,10 @@ function generate_handshake_key() -> Result[ulong, net.Error]:
|
|
|
169
169
|
|
|
170
170
|
function decode_uint_at(data: span[ubyte], offset: ptr_uint) -> uint:
|
|
171
171
|
unsafe:
|
|
172
|
-
return uint<-read(data.data + offset) |
|
|
172
|
+
return uint<-read(data.data + offset) |
|
|
173
|
+
(uint<-read(data.data + offset + 1) << 8) |
|
|
174
|
+
(uint<-read(data.data + offset + 2) << 16) |
|
|
175
|
+
(uint<-read(data.data + offset + 3) << 24)
|
|
173
176
|
|
|
174
177
|
|
|
175
178
|
function channel_config_for(config: Config) -> chan.Config:
|
|
@@ -315,9 +318,7 @@ extending Connection:
|
|
|
315
318
|
defer: hb.release()
|
|
316
319
|
let send_result = await this.channel.send(hb.as_span())
|
|
317
320
|
match send_result:
|
|
318
|
-
Result.failure:
|
|
319
|
-
pass
|
|
320
|
-
Result.success:
|
|
321
|
+
Result.failure | Result.success:
|
|
321
322
|
pass
|
|
322
323
|
this.last_heartbeat_sent = frame
|
|
323
324
|
|
|
@@ -327,9 +328,7 @@ extending Connection:
|
|
|
327
328
|
|
|
328
329
|
let channel_tick_result = await this.channel.tick(frame)
|
|
329
330
|
match channel_tick_result:
|
|
330
|
-
Result.failure:
|
|
331
|
-
pass
|
|
332
|
-
Result.success:
|
|
331
|
+
Result.failure | Result.success:
|
|
333
332
|
pass
|
|
334
333
|
|
|
335
334
|
await aio.sleep(1)
|
|
@@ -467,9 +466,7 @@ extending Connection:
|
|
|
467
466
|
let send_result = await this.channel.send_reliable(d.as_span(), 0)
|
|
468
467
|
this.state = ConnectionState.disconnected
|
|
469
468
|
match send_result:
|
|
470
|
-
Result.failure:
|
|
471
|
-
return Result[bool, net.Error].success(value = true)
|
|
472
|
-
Result.success:
|
|
469
|
+
Result.failure | Result.success:
|
|
473
470
|
return Result[bool, net.Error].success(value = true)
|
|
474
471
|
|
|
475
472
|
|
|
@@ -657,9 +654,7 @@ extending Session:
|
|
|
657
654
|
defer: addr.release()
|
|
658
655
|
let send_result = await this.host.send(addr, hb.as_span())
|
|
659
656
|
match send_result:
|
|
660
|
-
Result.failure:
|
|
661
|
-
pass
|
|
662
|
-
Result.success:
|
|
657
|
+
Result.failure | Result.success:
|
|
663
658
|
pass
|
|
664
659
|
Result.failure:
|
|
665
660
|
pass
|
|
@@ -680,9 +675,7 @@ extending Session:
|
|
|
680
675
|
|
|
681
676
|
let host_tick_result = await this.host.tick(frame)
|
|
682
677
|
match host_tick_result:
|
|
683
|
-
Result.failure:
|
|
684
|
-
pass
|
|
685
|
-
Result.success:
|
|
678
|
+
Result.failure | Result.success:
|
|
686
679
|
pass
|
|
687
680
|
|
|
688
681
|
await aio.sleep(1)
|
|
@@ -799,9 +792,7 @@ extending Session:
|
|
|
799
792
|
defer: d.release()
|
|
800
793
|
let send_result = await this.host.send_reliable(address, d.as_span(), 0)
|
|
801
794
|
match send_result:
|
|
802
|
-
Result.failure:
|
|
803
|
-
pass
|
|
804
|
-
Result.success:
|
|
795
|
+
Result.failure | Result.success:
|
|
805
796
|
pass
|
|
806
797
|
mark_peer_disconnected(ref_of(this), peer_id)
|
|
807
798
|
this.event_queue.push_back(PeerEvent(
|
|
@@ -1062,9 +1053,7 @@ async function drain_outgoing_session(session: ref[Session]) -> Result[bool, net
|
|
|
1062
1053
|
0
|
|
1063
1054
|
)
|
|
1064
1055
|
match send_result:
|
|
1065
|
-
Result.failure:
|
|
1066
|
-
pass
|
|
1067
|
-
Result.success:
|
|
1056
|
+
Result.failure | Result.success:
|
|
1068
1057
|
pass
|
|
1069
1058
|
else:
|
|
1070
1059
|
let send_result = await session.host.send(
|
|
@@ -1072,9 +1061,7 @@ async function drain_outgoing_session(session: ref[Session]) -> Result[bool, net
|
|
|
1072
1061
|
outgoing.payload.as_span()
|
|
1073
1062
|
)
|
|
1074
1063
|
match send_result:
|
|
1075
|
-
Result.failure:
|
|
1076
|
-
pass
|
|
1077
|
-
Result.success:
|
|
1064
|
+
Result.failure | Result.success:
|
|
1078
1065
|
pass
|
|
1079
1066
|
|
|
1080
1067
|
|
data/std/net/sync.mt
CHANGED
|
@@ -107,7 +107,7 @@ extending CompressedUshort:
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
public function decode(encoded: ushort) -> float:
|
|
110
|
-
let ratio =
|
|
110
|
+
let ratio = encoded / 65535.0
|
|
111
111
|
return this.min + ratio * (this.max - this.min)
|
|
112
112
|
|
|
113
113
|
public struct CompressedUbyte:
|
|
@@ -127,7 +127,7 @@ extending CompressedUbyte:
|
|
|
127
127
|
|
|
128
128
|
|
|
129
129
|
public function decode(encoded: ubyte) -> float:
|
|
130
|
-
let ratio =
|
|
130
|
+
let ratio = encoded / 255.0
|
|
131
131
|
return this.min + ratio * (this.max - this.min)
|
|
132
132
|
|
|
133
133
|
public struct TickBuffer[T]:
|
|
@@ -138,7 +138,7 @@ public struct TickBuffer[T]:
|
|
|
138
138
|
extending TickBuffer[T]:
|
|
139
139
|
public editable function push(tick: uint, value: T) -> void:
|
|
140
140
|
let offset: ptr_uint = ptr_uint<-(tick - this.base_tick)
|
|
141
|
-
|
|
141
|
+
if offset >= this.entries.len():
|
|
142
142
|
this.entries.push(value)
|
|
143
143
|
return
|
|
144
144
|
let ptr = this.entries.get(offset) else:
|
data/std/net/turn.mt
CHANGED
|
@@ -342,9 +342,11 @@ public function parse_data_indication(
|
|
|
342
342
|
var attr_len: ptr_uint = read_ushort_be(data, 2z)
|
|
343
343
|
var offset: ptr_uint = turn_header_len
|
|
344
344
|
var found_peer: bool = false
|
|
345
|
-
|
|
345
|
+
# Ownership is tracked manually here: both bindings are released on the
|
|
346
|
+
# failure path below and moved into TurnDatagram on success.
|
|
347
|
+
var peer_addr: net.SocketAddress = zero[net.SocketAddress] # lint: ignore(owning-release-leak)
|
|
346
348
|
var found_data: bool = false
|
|
347
|
-
var payload: bytes.Bytes = bytes.Bytes.empty()
|
|
349
|
+
var payload: bytes.Bytes = bytes.Bytes.empty() # lint: ignore(owning-release-leak)
|
|
348
350
|
|
|
349
351
|
while attr_len >= 4z:
|
|
350
352
|
if offset + 4z > data.len:
|
|
@@ -387,6 +389,8 @@ public function parse_data_indication(
|
|
|
387
389
|
if not found_peer or not found_data:
|
|
388
390
|
if found_data:
|
|
389
391
|
payload.release()
|
|
392
|
+
if found_peer:
|
|
393
|
+
peer_addr.release()
|
|
390
394
|
return Result[TurnDatagram, Error].failure(
|
|
391
395
|
error = turn_error(err_no_data_attribute, "data indication missing attributes")
|
|
392
396
|
)
|
|
@@ -420,7 +424,7 @@ public async function send_data(
|
|
|
420
424
|
defer: packet.release()
|
|
421
425
|
let send_result = await socket.send_to(packet.as_span(), turn_server)
|
|
422
426
|
match send_result:
|
|
423
|
-
Result.failure
|
|
427
|
+
Result.failure:
|
|
424
428
|
return Result[ptr_uint, Error].failure(
|
|
425
429
|
error = turn_error(err_send_failed, "send indication failed")
|
|
426
430
|
)
|