mt-lang 0.4.23 → 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/core/types/layout.rb +90 -19
- 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 +8 -17
- metadata +5 -3
data/std/net.mt
CHANGED
|
@@ -193,8 +193,8 @@ struct UdpReceiveState:
|
|
|
193
193
|
released: bool
|
|
194
194
|
|
|
195
195
|
|
|
196
|
-
function noop_waiter(
|
|
197
|
-
|
|
196
|
+
function noop_waiter(_frame: ptr[void]) -> void:
|
|
197
|
+
pass
|
|
198
198
|
|
|
199
199
|
|
|
200
200
|
function resolve_state(frame: ptr[void]) -> ptr[ResolveState]:
|
|
@@ -476,14 +476,14 @@ function tcp_socket_address_from_getsockname(handle: ptr[NativeTcpHandle]?) -> R
|
|
|
476
476
|
var name_length = int<-size_of(NativeSocketStorage)
|
|
477
477
|
let status_code = libuv_c.uv_tcp_getsockname(
|
|
478
478
|
live_handle,
|
|
479
|
-
sockaddr_storage_as_sockaddr(
|
|
479
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
480
480
|
ptr_of(name_length)
|
|
481
481
|
)
|
|
482
482
|
if status_code != 0:
|
|
483
483
|
return Result[SocketAddress, Error].failure(error= libuv_error(status_code))
|
|
484
484
|
|
|
485
485
|
return socket_address_from_sockaddr(
|
|
486
|
-
sockaddr_storage_as_sockaddr(
|
|
486
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
487
487
|
ptr_uint<-name_length
|
|
488
488
|
)
|
|
489
489
|
|
|
@@ -496,14 +496,14 @@ function tcp_socket_address_from_getpeername(handle: ptr[NativeTcpHandle]?) -> R
|
|
|
496
496
|
var name_length = int<-size_of(NativeSocketStorage)
|
|
497
497
|
let status_code = libuv_c.uv_tcp_getpeername(
|
|
498
498
|
live_handle,
|
|
499
|
-
sockaddr_storage_as_sockaddr(
|
|
499
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
500
500
|
ptr_of(name_length)
|
|
501
501
|
)
|
|
502
502
|
if status_code != 0:
|
|
503
503
|
return Result[SocketAddress, Error].failure(error= libuv_error(status_code))
|
|
504
504
|
|
|
505
505
|
return socket_address_from_sockaddr(
|
|
506
|
-
sockaddr_storage_as_sockaddr(
|
|
506
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
507
507
|
ptr_uint<-name_length
|
|
508
508
|
)
|
|
509
509
|
|
|
@@ -528,14 +528,14 @@ function udp_socket_address_from_getsockname(handle: ptr[NativeUdpHandle]?) -> R
|
|
|
528
528
|
var name_length = int<-size_of(NativeSocketStorage)
|
|
529
529
|
let status_code = libuv_c.uv_udp_getsockname(
|
|
530
530
|
live_handle,
|
|
531
|
-
sockaddr_storage_as_sockaddr(
|
|
531
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
532
532
|
ptr_of(name_length)
|
|
533
533
|
)
|
|
534
534
|
if status_code != 0:
|
|
535
535
|
return Result[SocketAddress, Error].failure(error= libuv_error(status_code))
|
|
536
536
|
|
|
537
537
|
return socket_address_from_sockaddr(
|
|
538
|
-
sockaddr_storage_as_sockaddr(
|
|
538
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
539
539
|
ptr_uint<-name_length
|
|
540
540
|
)
|
|
541
541
|
|
|
@@ -548,14 +548,14 @@ function udp_socket_address_from_getpeername(handle: ptr[NativeUdpHandle]?) -> R
|
|
|
548
548
|
var name_length = int<-size_of(NativeSocketStorage)
|
|
549
549
|
let status_code = libuv_c.uv_udp_getpeername(
|
|
550
550
|
live_handle,
|
|
551
|
-
sockaddr_storage_as_sockaddr(
|
|
551
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
552
552
|
ptr_of(name_length)
|
|
553
553
|
)
|
|
554
554
|
if status_code != 0:
|
|
555
555
|
return Result[SocketAddress, Error].failure(error= libuv_error(status_code))
|
|
556
556
|
|
|
557
557
|
return socket_address_from_sockaddr(
|
|
558
|
-
sockaddr_storage_as_sockaddr(
|
|
558
|
+
sockaddr_storage_as_sockaddr(ptr_of(raw)),
|
|
559
559
|
ptr_uint<-name_length
|
|
560
560
|
)
|
|
561
561
|
|
|
@@ -785,7 +785,7 @@ function finish_connect(state: ptr[ConnectState], result_value: Result[TcpStream
|
|
|
785
785
|
notify = true
|
|
786
786
|
|
|
787
787
|
if notify and waiter_frame != null[ptr[void]]:
|
|
788
|
-
waiter(
|
|
788
|
+
waiter(waiter_frame)
|
|
789
789
|
return
|
|
790
790
|
|
|
791
791
|
if unsafe: read(state).released:
|
|
@@ -805,7 +805,7 @@ function connect_callback(req: ptr[NativeConnectRequest], status_code: int) -> v
|
|
|
805
805
|
if status_code != 0:
|
|
806
806
|
let handle = unsafe: read(state).handle
|
|
807
807
|
if handle != null[ptr[NativeTcpHandle]]:
|
|
808
|
-
close_tcp_handle(
|
|
808
|
+
close_tcp_handle(handle)
|
|
809
809
|
unsafe: read(state).handle = null
|
|
810
810
|
|
|
811
811
|
finish_connect(state, Result[TcpStream, Error].failure(error= libuv_error(status_code)), status_code)
|
|
@@ -861,7 +861,7 @@ function accept_release(frame: ptr[void]) -> void:
|
|
|
861
861
|
|
|
862
862
|
let listener = unsafe: read(state).listener
|
|
863
863
|
if listener != null[ptr[ListenerState]]:
|
|
864
|
-
let live_listener =
|
|
864
|
+
let live_listener = listener
|
|
865
865
|
if unsafe: read(live_listener).accept_state == state:
|
|
866
866
|
unsafe: read(live_listener).accept_state = null
|
|
867
867
|
|
|
@@ -904,7 +904,7 @@ function finish_accept(state: ptr[AcceptState], result_value: Result[TcpStream,
|
|
|
904
904
|
notify = true
|
|
905
905
|
|
|
906
906
|
if notify and waiter_frame != null[ptr[void]]:
|
|
907
|
-
waiter(
|
|
907
|
+
waiter(waiter_frame)
|
|
908
908
|
|
|
909
909
|
|
|
910
910
|
function listener_close_callback(handle: ptr[NativeHandle]) -> void:
|
|
@@ -917,7 +917,7 @@ function listener_close_callback(handle: ptr[NativeHandle]) -> void:
|
|
|
917
917
|
if pending_accept != null[ptr[AcceptState]]:
|
|
918
918
|
unsafe: read(listener).accept_state = null
|
|
919
919
|
finish_accept(
|
|
920
|
-
|
|
920
|
+
pending_accept,
|
|
921
921
|
Result[TcpStream, Error].failure(error= net_error("listener closed")),
|
|
922
922
|
-1
|
|
923
923
|
)
|
|
@@ -959,7 +959,7 @@ function listener_connection_callback(server: ptr[NativeStreamHandle], status_co
|
|
|
959
959
|
if pending_accept != null[ptr[AcceptState]]:
|
|
960
960
|
unsafe: read(listener).accept_state = null
|
|
961
961
|
finish_accept(
|
|
962
|
-
|
|
962
|
+
pending_accept,
|
|
963
963
|
Result[TcpStream, Error].failure(error= libuv_error(status_code)),
|
|
964
964
|
status_code
|
|
965
965
|
)
|
|
@@ -969,7 +969,7 @@ function listener_connection_callback(server: ptr[NativeStreamHandle], status_co
|
|
|
969
969
|
|
|
970
970
|
if pending_accept != null[ptr[AcceptState]]:
|
|
971
971
|
unsafe: read(listener).accept_state = null
|
|
972
|
-
perform_listener_accept(listener,
|
|
972
|
+
perform_listener_accept(listener, pending_accept)
|
|
973
973
|
return
|
|
974
974
|
|
|
975
975
|
unsafe: read(listener).pending_connections += 1
|
|
@@ -977,15 +977,14 @@ function listener_connection_callback(server: ptr[NativeStreamHandle], status_co
|
|
|
977
977
|
|
|
978
978
|
function accept_impl(handle: ptr[NativeTcpHandle]?) -> Task[Result[TcpStream, Error]]:
|
|
979
979
|
let state = heap.must_alloc_zeroed[AcceptState](1)
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
read(state).listener = null
|
|
980
|
+
read(state).ready = false
|
|
981
|
+
read(state).status_code = 0
|
|
982
|
+
read(state).result = Result[TcpStream, Error].success(value= zero[TcpStream])
|
|
983
|
+
read(state).result_owned = false
|
|
984
|
+
read(state).waiter_frame = null
|
|
985
|
+
read(state).waiter = noop_waiter
|
|
986
|
+
read(state).waiter_registered = false
|
|
987
|
+
read(state).listener = null
|
|
989
988
|
|
|
990
989
|
let live_handle = handle else:
|
|
991
990
|
finish_accept(state, Result[TcpStream, Error].failure(error= net_error("listener is released")), -1)
|
|
@@ -1000,7 +999,7 @@ function accept_impl(handle: ptr[NativeTcpHandle]?) -> Task[Result[TcpStream, Er
|
|
|
1000
999
|
return accept_task(state)
|
|
1001
1000
|
|
|
1002
1001
|
let listener = unsafe: ptr[ListenerState]<-state_raw
|
|
1003
|
-
|
|
1002
|
+
read(state).listener = listener
|
|
1004
1003
|
|
|
1005
1004
|
let pending_error_code = unsafe: read(listener).pending_error_code
|
|
1006
1005
|
if pending_error_code != 0:
|
|
@@ -1015,7 +1014,7 @@ function accept_impl(handle: ptr[NativeTcpHandle]?) -> Task[Result[TcpStream, Er
|
|
|
1015
1014
|
return accept_task(state)
|
|
1016
1015
|
|
|
1017
1016
|
if unsafe: read(listener).accept_state != null[ptr[AcceptState]]:
|
|
1018
|
-
|
|
1017
|
+
read(state).listener = null
|
|
1019
1018
|
finish_accept(
|
|
1020
1019
|
state,
|
|
1021
1020
|
Result[TcpStream, Error].failure(error= net_error("listener already has a pending accept")),
|
|
@@ -1044,7 +1043,7 @@ function tcp_stream_close_callback(handle: ptr[NativeHandle]) -> void:
|
|
|
1044
1043
|
read(stream).read_state = null
|
|
1045
1044
|
read(pending_read).stream = null
|
|
1046
1045
|
finish_stream_read(
|
|
1047
|
-
|
|
1046
|
+
pending_read,
|
|
1048
1047
|
Result[bytes.Bytes, Error].failure(error= net_error("tcp stream closed")),
|
|
1049
1048
|
-1
|
|
1050
1049
|
)
|
|
@@ -1059,8 +1058,7 @@ function close_tcp_stream_handle(handle: ptr[NativeTcpHandle]) -> void:
|
|
|
1059
1058
|
if libuv.is_closing(tcp_as_handle(handle)) != 0:
|
|
1060
1059
|
return
|
|
1061
1060
|
|
|
1062
|
-
let
|
|
1063
|
-
if state_raw == null[ptr[void]]:
|
|
1061
|
+
let _ = libuv.handle_get_data(tcp_as_handle(handle)) else:
|
|
1064
1062
|
close_tcp_handle(handle)
|
|
1065
1063
|
return
|
|
1066
1064
|
|
|
@@ -1157,7 +1155,7 @@ function finish_write(
|
|
|
1157
1155
|
notify = true
|
|
1158
1156
|
|
|
1159
1157
|
if notify and waiter_frame != null[ptr[void]]:
|
|
1160
|
-
waiter(
|
|
1158
|
+
waiter(waiter_frame)
|
|
1161
1159
|
return
|
|
1162
1160
|
|
|
1163
1161
|
if unsafe: read(state).released:
|
|
@@ -1192,18 +1190,17 @@ function write_callback(req: ptr[NativeWriteRequest], status_code: int) -> void:
|
|
|
1192
1190
|
|
|
1193
1191
|
function write_on_impl(handle: ptr[NativeTcpHandle]?, content: span[ubyte]) -> Task[Result[ptr_uint, Error]]:
|
|
1194
1192
|
let state = heap.must_alloc_zeroed[WriteState](1)
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
read(state).released = false
|
|
1193
|
+
read(state).ready = false
|
|
1194
|
+
read(state).status_code = 0
|
|
1195
|
+
read(state).result = Result[ptr_uint, Error].success(value= 0)
|
|
1196
|
+
read(state).result_owned = false
|
|
1197
|
+
read(state).waiter_frame = null
|
|
1198
|
+
read(state).waiter = noop_waiter
|
|
1199
|
+
read(state).waiter_registered = false
|
|
1200
|
+
read(state).req = null
|
|
1201
|
+
read(state).buffers = null
|
|
1202
|
+
read(state).data = bytes.Bytes.empty()
|
|
1203
|
+
read(state).released = false
|
|
1207
1204
|
|
|
1208
1205
|
let live_handle = handle else:
|
|
1209
1206
|
finish_write(state, Result[ptr_uint, Error].failure(error= net_error("tcp stream is released")), -1, true)
|
|
@@ -1334,7 +1331,7 @@ function stream_read_release(frame: ptr[void]) -> void:
|
|
|
1334
1331
|
|
|
1335
1332
|
let stream = unsafe: read(state).stream
|
|
1336
1333
|
if stream != null[ptr[TcpStreamState]]:
|
|
1337
|
-
let live_stream =
|
|
1334
|
+
let live_stream = stream
|
|
1338
1335
|
let handle = unsafe: read(live_stream).handle
|
|
1339
1336
|
unsafe:
|
|
1340
1337
|
if read(live_stream).read_state == state:
|
|
@@ -1342,7 +1339,7 @@ function stream_read_release(frame: ptr[void]) -> void:
|
|
|
1342
1339
|
read(state).stream = null
|
|
1343
1340
|
|
|
1344
1341
|
if handle != null[ptr[NativeTcpHandle]]:
|
|
1345
|
-
libuv.read_stop(tcp_as_stream(
|
|
1342
|
+
libuv.read_stop(tcp_as_stream(handle))
|
|
1346
1343
|
|
|
1347
1344
|
finish_stream_read(state, Result[bytes.Bytes, Error].failure(error= net_error("tcp read released")), -1)
|
|
1348
1345
|
|
|
@@ -1381,7 +1378,7 @@ function finish_stream_read(state: ptr[ReadState], result_value: Result[bytes.By
|
|
|
1381
1378
|
notify = true
|
|
1382
1379
|
|
|
1383
1380
|
if notify and waiter_frame != null[ptr[void]]:
|
|
1384
|
-
waiter(
|
|
1381
|
+
waiter(waiter_frame)
|
|
1385
1382
|
return
|
|
1386
1383
|
|
|
1387
1384
|
if unsafe: read(state).released:
|
|
@@ -1399,13 +1396,12 @@ function stream_read_alloc_callback(
|
|
|
1399
1396
|
return
|
|
1400
1397
|
|
|
1401
1398
|
let stream = unsafe: ptr[TcpStreamState]<-state_raw
|
|
1402
|
-
let pending_read = unsafe: read(stream).read_state
|
|
1403
|
-
if pending_read == null[ptr[ReadState]]:
|
|
1399
|
+
let pending_read = unsafe: read(stream).read_state else:
|
|
1404
1400
|
let storage = unsafe: ptr[char]<-heap.must_alloc_zeroed_bytes(1, 1)
|
|
1405
1401
|
unsafe: read(buf) = libuv.buf_init(storage, 0)
|
|
1406
1402
|
return
|
|
1407
1403
|
|
|
1408
|
-
let state =
|
|
1404
|
+
let state = pending_read
|
|
1409
1405
|
var capacity = suggested_size
|
|
1410
1406
|
let remaining = unsafe: read(state).max_bytes - read(state).received_bytes
|
|
1411
1407
|
if remaining < capacity:
|
|
@@ -1430,12 +1426,11 @@ function stream_read_callback(
|
|
|
1430
1426
|
return
|
|
1431
1427
|
|
|
1432
1428
|
let stream = unsafe: ptr[TcpStreamState]<-state_raw
|
|
1433
|
-
let pending_read = unsafe: read(stream).read_state
|
|
1434
|
-
if pending_read == null[ptr[ReadState]]:
|
|
1429
|
+
let pending_read = unsafe: read(stream).read_state else:
|
|
1435
1430
|
release_uv_buffer(raw_buffer)
|
|
1436
1431
|
return
|
|
1437
1432
|
|
|
1438
|
-
let state =
|
|
1433
|
+
let state = pending_read
|
|
1439
1434
|
if nread == 0:
|
|
1440
1435
|
release_uv_buffer(raw_buffer)
|
|
1441
1436
|
return
|
|
@@ -1494,20 +1489,19 @@ function stream_read_callback(
|
|
|
1494
1489
|
|
|
1495
1490
|
function read_impl(handle: ptr[NativeTcpHandle]?, max_bytes: ptr_uint, exact: bool) -> Task[Result[bytes.Bytes, Error]]:
|
|
1496
1491
|
let state = heap.must_alloc_zeroed[ReadState](1)
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
read(state).released = false
|
|
1492
|
+
read(state).ready = false
|
|
1493
|
+
read(state).status_code = 0
|
|
1494
|
+
read(state).result = Result[bytes.Bytes, Error].success(value= bytes.Bytes.empty())
|
|
1495
|
+
read(state).result_owned = false
|
|
1496
|
+
read(state).waiter_frame = null
|
|
1497
|
+
read(state).waiter = noop_waiter
|
|
1498
|
+
read(state).waiter_registered = false
|
|
1499
|
+
read(state).stream = null
|
|
1500
|
+
read(state).max_bytes = max_bytes
|
|
1501
|
+
read(state).buffer = null
|
|
1502
|
+
read(state).received_bytes = 0
|
|
1503
|
+
read(state).exact = exact
|
|
1504
|
+
read(state).released = false
|
|
1511
1505
|
|
|
1512
1506
|
if max_bytes == 0:
|
|
1513
1507
|
finish_stream_read(
|
|
@@ -1649,7 +1643,7 @@ function finish_shutdown(
|
|
|
1649
1643
|
notify = true
|
|
1650
1644
|
|
|
1651
1645
|
if notify and waiter_frame != null[ptr[void]]:
|
|
1652
|
-
waiter(
|
|
1646
|
+
waiter(waiter_frame)
|
|
1653
1647
|
return
|
|
1654
1648
|
|
|
1655
1649
|
if unsafe: read(state).released:
|
|
@@ -1675,16 +1669,15 @@ function shutdown_callback(req: ptr[NativeShutdownRequest], status_code: int) ->
|
|
|
1675
1669
|
|
|
1676
1670
|
function shutdown_impl(handle: ptr[NativeTcpHandle]?) -> Task[Result[bool, Error]]:
|
|
1677
1671
|
let state = heap.must_alloc_zeroed[ShutdownState](1)
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
read(state).released = false
|
|
1672
|
+
read(state).ready = false
|
|
1673
|
+
read(state).status_code = 0
|
|
1674
|
+
read(state).result = Result[bool, Error].success(value= false)
|
|
1675
|
+
read(state).result_owned = false
|
|
1676
|
+
read(state).waiter_frame = null
|
|
1677
|
+
read(state).waiter = noop_waiter
|
|
1678
|
+
read(state).waiter_registered = false
|
|
1679
|
+
read(state).req = null
|
|
1680
|
+
read(state).released = false
|
|
1688
1681
|
|
|
1689
1682
|
let live_handle = handle else:
|
|
1690
1683
|
finish_shutdown(state, Result[bool, Error].failure(error= net_error("tcp stream is released")), -1, true)
|
|
@@ -1722,7 +1715,7 @@ function udp_socket_close_callback(handle: ptr[NativeHandle]) -> void:
|
|
|
1722
1715
|
read(socket).receive_state = null
|
|
1723
1716
|
read(pending_receive).socket = null
|
|
1724
1717
|
finish_udp_receive(
|
|
1725
|
-
|
|
1718
|
+
pending_receive,
|
|
1726
1719
|
Result[UdpDatagram, Error].failure(error= net_error("udp socket closed")),
|
|
1727
1720
|
-1
|
|
1728
1721
|
)
|
|
@@ -1737,8 +1730,7 @@ function close_udp_socket_handle(handle: ptr[NativeUdpHandle]) -> void:
|
|
|
1737
1730
|
if libuv.is_closing(udp_as_handle(handle)) != 0:
|
|
1738
1731
|
return
|
|
1739
1732
|
|
|
1740
|
-
let
|
|
1741
|
-
if state_raw == null[ptr[void]]:
|
|
1733
|
+
let _ = libuv.handle_get_data(udp_as_handle(handle)) else:
|
|
1742
1734
|
close_raw_udp_handle(handle)
|
|
1743
1735
|
return
|
|
1744
1736
|
|
|
@@ -1850,7 +1842,7 @@ function finish_udp_send(
|
|
|
1850
1842
|
close_udp_socket_handle(h)
|
|
1851
1843
|
|
|
1852
1844
|
if notify and waiter_frame != null[ptr[void]]:
|
|
1853
|
-
waiter(
|
|
1845
|
+
waiter(waiter_frame)
|
|
1854
1846
|
return
|
|
1855
1847
|
|
|
1856
1848
|
if unsafe: read(state).released:
|
|
@@ -1895,21 +1887,20 @@ function udp_send_impl(
|
|
|
1895
1887
|
use_destination: bool
|
|
1896
1888
|
) -> Task[Result[ptr_uint, Error]]:
|
|
1897
1889
|
let state = heap.must_alloc_zeroed[UdpSendState](1)
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
read(state).socket = null
|
|
1890
|
+
read(state).ready = false
|
|
1891
|
+
read(state).status_code = 0
|
|
1892
|
+
read(state).result = Result[ptr_uint, Error].success(value= 0)
|
|
1893
|
+
read(state).result_owned = false
|
|
1894
|
+
read(state).waiter_frame = null
|
|
1895
|
+
read(state).waiter = noop_waiter
|
|
1896
|
+
read(state).waiter_registered = false
|
|
1897
|
+
read(state).req = null
|
|
1898
|
+
read(state).buffers = null
|
|
1899
|
+
read(state).data = bytes.Bytes.empty()
|
|
1900
|
+
read(state).destination = zero[SocketAddress]
|
|
1901
|
+
read(state).destination_owned = false
|
|
1902
|
+
read(state).released = false
|
|
1903
|
+
read(state).socket = null
|
|
1913
1904
|
|
|
1914
1905
|
let live_handle = handle else:
|
|
1915
1906
|
finish_udp_send(state, Result[ptr_uint, Error].failure(error= net_error("udp socket is released")), -1, true)
|
|
@@ -1930,9 +1921,8 @@ function udp_send_impl(
|
|
|
1930
1921
|
finish_udp_send(state, Result[ptr_uint, Error].failure(error= error), error.code, true)
|
|
1931
1922
|
return udp_send_task(state)
|
|
1932
1923
|
Result.success as payload:
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
read(state).destination_owned = true
|
|
1924
|
+
read(state).destination = payload.value
|
|
1925
|
+
read(state).destination_owned = true
|
|
1936
1926
|
|
|
1937
1927
|
let copied = bytes.Bytes.copy(content)
|
|
1938
1928
|
let copied_data = copied.data else:
|
|
@@ -1941,7 +1931,7 @@ function udp_send_impl(
|
|
|
1941
1931
|
|
|
1942
1932
|
var remote_address: const_ptr[NativeSockAddr]? = null[const_ptr[NativeSockAddr]]
|
|
1943
1933
|
if use_destination:
|
|
1944
|
-
let destination_storage =
|
|
1934
|
+
let destination_storage = read(state).destination.storage else:
|
|
1945
1935
|
var payload = copied
|
|
1946
1936
|
payload.release()
|
|
1947
1937
|
finish_udp_send(
|
|
@@ -1963,8 +1953,7 @@ function udp_send_impl(
|
|
|
1963
1953
|
read(buffers) = libuv.buf_init(ptr[char]<-copied_data, uint<-copied.len)
|
|
1964
1954
|
libuv.req_set_data(udp_send_req_as_base(req), ptr[void]<-state)
|
|
1965
1955
|
|
|
1966
|
-
let socket_raw = libuv.handle_get_data(udp_as_handle(live_handle))
|
|
1967
|
-
if socket_raw == null[ptr[void]]:
|
|
1956
|
+
let socket_raw = libuv.handle_get_data(udp_as_handle(live_handle)) else:
|
|
1968
1957
|
unsafe:
|
|
1969
1958
|
heap.release_bytes(ptr[void]<-req)
|
|
1970
1959
|
read(state).req = null
|
|
@@ -1977,7 +1966,12 @@ function udp_send_impl(
|
|
|
1977
1966
|
var target = read(state).destination
|
|
1978
1967
|
target.release()
|
|
1979
1968
|
read(state).destination_owned = false
|
|
1980
|
-
finish_udp_send(
|
|
1969
|
+
finish_udp_send(
|
|
1970
|
+
state,
|
|
1971
|
+
Result[ptr_uint, Error].failure(error= net_error("udp socket state is missing")),
|
|
1972
|
+
-1,
|
|
1973
|
+
true
|
|
1974
|
+
)
|
|
1981
1975
|
return udp_send_task(state)
|
|
1982
1976
|
|
|
1983
1977
|
let socket_state = unsafe: ptr[UdpSocketState]<-socket_raw
|
|
@@ -2083,7 +2077,7 @@ function udp_receive_release(frame: ptr[void]) -> void:
|
|
|
2083
2077
|
if unsafe: read(state).ready:
|
|
2084
2078
|
let socket = unsafe: read(state).socket
|
|
2085
2079
|
if socket != null[ptr[UdpSocketState]]:
|
|
2086
|
-
let live_socket =
|
|
2080
|
+
let live_socket = socket
|
|
2087
2081
|
if unsafe: read(live_socket).receive_state == state:
|
|
2088
2082
|
unsafe: read(live_socket).receive_state = null
|
|
2089
2083
|
udp_receive_cleanup_and_release(state)
|
|
@@ -2093,7 +2087,7 @@ function udp_receive_release(frame: ptr[void]) -> void:
|
|
|
2093
2087
|
|
|
2094
2088
|
let socket = unsafe: read(state).socket
|
|
2095
2089
|
if socket != null[ptr[UdpSocketState]]:
|
|
2096
|
-
let live_socket =
|
|
2090
|
+
let live_socket = socket
|
|
2097
2091
|
let handle = unsafe: read(live_socket).handle
|
|
2098
2092
|
unsafe:
|
|
2099
2093
|
if read(live_socket).receive_state == state:
|
|
@@ -2101,7 +2095,7 @@ function udp_receive_release(frame: ptr[void]) -> void:
|
|
|
2101
2095
|
read(state).socket = null
|
|
2102
2096
|
|
|
2103
2097
|
if handle != null[ptr[NativeUdpHandle]]:
|
|
2104
|
-
libuv.udp_recv_stop(
|
|
2098
|
+
libuv.udp_recv_stop(handle)
|
|
2105
2099
|
|
|
2106
2100
|
finish_udp_receive(state, Result[UdpDatagram, Error].failure(error= net_error("udp receive released")), -1)
|
|
2107
2101
|
|
|
@@ -2144,7 +2138,7 @@ function finish_udp_receive(
|
|
|
2144
2138
|
notify = true
|
|
2145
2139
|
|
|
2146
2140
|
if notify and waiter_frame != null[ptr[void]]:
|
|
2147
|
-
waiter(
|
|
2141
|
+
waiter(waiter_frame)
|
|
2148
2142
|
return
|
|
2149
2143
|
|
|
2150
2144
|
if unsafe: read(state).released:
|
|
@@ -2162,13 +2156,12 @@ function udp_receive_alloc_callback(
|
|
|
2162
2156
|
return
|
|
2163
2157
|
|
|
2164
2158
|
let socket = unsafe: ptr[UdpSocketState]<-state_raw
|
|
2165
|
-
let pending_receive = unsafe: read(socket).receive_state
|
|
2166
|
-
if pending_receive == null[ptr[UdpReceiveState]]:
|
|
2159
|
+
let pending_receive = unsafe: read(socket).receive_state else:
|
|
2167
2160
|
let storage = unsafe: ptr[char]<-heap.must_alloc_zeroed_bytes(1, 1)
|
|
2168
2161
|
unsafe: read(buf) = libuv.buf_init(storage, 0)
|
|
2169
2162
|
return
|
|
2170
2163
|
|
|
2171
|
-
let state =
|
|
2164
|
+
let state = pending_receive
|
|
2172
2165
|
var capacity = suggested_size
|
|
2173
2166
|
let max_bytes = unsafe: read(state).max_bytes
|
|
2174
2167
|
if max_bytes < capacity:
|
|
@@ -2195,12 +2188,11 @@ function udp_receive_callback(
|
|
|
2195
2188
|
return
|
|
2196
2189
|
|
|
2197
2190
|
let socket = unsafe: ptr[UdpSocketState]<-state_raw
|
|
2198
|
-
let pending_receive = unsafe: read(socket).receive_state
|
|
2199
|
-
if pending_receive == null[ptr[UdpReceiveState]]:
|
|
2191
|
+
let pending_receive = unsafe: read(socket).receive_state else:
|
|
2200
2192
|
release_uv_buffer(raw_buffer)
|
|
2201
2193
|
return
|
|
2202
2194
|
|
|
2203
|
-
let state =
|
|
2195
|
+
let state = pending_receive
|
|
2204
2196
|
if nread == 0:
|
|
2205
2197
|
release_uv_buffer(raw_buffer)
|
|
2206
2198
|
return
|
|
@@ -2242,17 +2234,16 @@ function udp_receive_callback(
|
|
|
2242
2234
|
|
|
2243
2235
|
function recv_from_impl(handle: ptr[NativeUdpHandle]?, max_bytes: ptr_uint) -> Task[Result[UdpDatagram, Error]]:
|
|
2244
2236
|
let state = heap.must_alloc_zeroed[UdpReceiveState](1)
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
read(state).released = false
|
|
2237
|
+
read(state).ready = false
|
|
2238
|
+
read(state).status_code = 0
|
|
2239
|
+
read(state).result = Result[UdpDatagram, Error].success(value= zero[UdpDatagram])
|
|
2240
|
+
read(state).result_owned = false
|
|
2241
|
+
read(state).waiter_frame = null
|
|
2242
|
+
read(state).waiter = noop_waiter
|
|
2243
|
+
read(state).waiter_registered = false
|
|
2244
|
+
read(state).socket = null
|
|
2245
|
+
read(state).max_bytes = max_bytes
|
|
2246
|
+
read(state).released = false
|
|
2256
2247
|
|
|
2257
2248
|
if max_bytes == 0:
|
|
2258
2249
|
finish_udp_receive(
|
|
@@ -2350,7 +2341,7 @@ function finish_resolve(state: ptr[ResolveState], result_value: Result[SocketAdd
|
|
|
2350
2341
|
notify = true
|
|
2351
2342
|
|
|
2352
2343
|
if notify and waiter_frame != null[ptr[void]]:
|
|
2353
|
-
waiter(
|
|
2344
|
+
waiter(waiter_frame)
|
|
2354
2345
|
|
|
2355
2346
|
|
|
2356
2347
|
function finish_resolve_all(
|
|
@@ -2374,7 +2365,7 @@ function finish_resolve_all(
|
|
|
2374
2365
|
notify = true
|
|
2375
2366
|
|
|
2376
2367
|
if notify and waiter_frame != null[ptr[void]]:
|
|
2377
|
-
waiter(
|
|
2368
|
+
waiter(waiter_frame)
|
|
2378
2369
|
|
|
2379
2370
|
|
|
2380
2371
|
function resolve_callback(
|
|
@@ -2454,7 +2445,7 @@ function resolve_all_callback(
|
|
|
2454
2445
|
if current == null:
|
|
2455
2446
|
break
|
|
2456
2447
|
|
|
2457
|
-
let live_current =
|
|
2448
|
+
let live_current = current
|
|
2458
2449
|
let ai = unsafe: read(live_current)
|
|
2459
2450
|
let address_result = socket_address_from_sockaddr(ai.ai_addr, ptr_uint<-ai.ai_addrlen)
|
|
2460
2451
|
match address_result:
|
|
@@ -2514,14 +2505,13 @@ function resolve_on_impl(runtime: aio.Runtime, node: str, service: str) -> Task[
|
|
|
2514
2505
|
loop,
|
|
2515
2506
|
req,
|
|
2516
2507
|
resolve_callback,
|
|
2517
|
-
|
|
2518
|
-
|
|
2508
|
+
read(state).node,
|
|
2509
|
+
read(state).service,
|
|
2519
2510
|
null[const_ptr[NativeAddrInfo]]
|
|
2520
2511
|
)
|
|
2521
2512
|
if queue_status != 0:
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
read(state).req = null
|
|
2513
|
+
heap.release(req)
|
|
2514
|
+
read(state).req = null
|
|
2525
2515
|
finish_resolve(state, Result[SocketAddress, Error].failure(error= libuv_error(queue_status)), queue_status)
|
|
2526
2516
|
|
|
2527
2517
|
return resolve_task(state)
|
|
@@ -2560,14 +2550,13 @@ function resolve_all_on_impl(
|
|
|
2560
2550
|
loop,
|
|
2561
2551
|
req,
|
|
2562
2552
|
resolve_all_callback,
|
|
2563
|
-
|
|
2564
|
-
|
|
2553
|
+
read(state).node,
|
|
2554
|
+
read(state).service,
|
|
2565
2555
|
null[const_ptr[NativeAddrInfo]]
|
|
2566
2556
|
)
|
|
2567
2557
|
if queue_status != 0:
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
read(state).req = null
|
|
2558
|
+
heap.release(req)
|
|
2559
|
+
read(state).req = null
|
|
2571
2560
|
finish_resolve_all(
|
|
2572
2561
|
state,
|
|
2573
2562
|
Result[vec.Vec[SocketAddress], Error].failure(error= libuv_error(queue_status)),
|
|
@@ -2579,19 +2568,18 @@ function resolve_all_on_impl(
|
|
|
2579
2568
|
|
|
2580
2569
|
function connect_on_impl(runtime: aio.Runtime, address: SocketAddress) -> Task[Result[TcpStream, Error]]:
|
|
2581
2570
|
let state = heap.must_alloc_zeroed[ConnectState](1)
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
read(state).released = false
|
|
2571
|
+
read(state).ready = false
|
|
2572
|
+
read(state).status_code = 0
|
|
2573
|
+
read(state).result = Result[TcpStream, Error].success(value= zero[TcpStream])
|
|
2574
|
+
read(state).result_owned = false
|
|
2575
|
+
read(state).waiter_frame = null
|
|
2576
|
+
read(state).waiter = noop_waiter
|
|
2577
|
+
read(state).waiter_registered = false
|
|
2578
|
+
read(state).req = null
|
|
2579
|
+
read(state).handle = null
|
|
2580
|
+
read(state).destination = zero[SocketAddress]
|
|
2581
|
+
read(state).destination_owned = false
|
|
2582
|
+
read(state).released = false
|
|
2595
2583
|
|
|
2596
2584
|
match duplicate_socket_address(address):
|
|
2597
2585
|
Result.failure as payload:
|
|
@@ -2599,9 +2587,8 @@ function connect_on_impl(runtime: aio.Runtime, address: SocketAddress) -> Task[R
|
|
|
2599
2587
|
finish_connect(state, Result[TcpStream, Error].failure(error= error), error.code)
|
|
2600
2588
|
return connect_task(state)
|
|
2601
2589
|
Result.success as payload:
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
read(state).destination_owned = true
|
|
2590
|
+
read(state).destination = payload.value
|
|
2591
|
+
read(state).destination_owned = true
|
|
2605
2592
|
|
|
2606
2593
|
let handle = alloc_tcp_handle()
|
|
2607
2594
|
let init_status = libuv.tcp_init(aio_backend.runtime_loop(runtime), handle)
|
|
@@ -2616,7 +2603,7 @@ function connect_on_impl(runtime: aio.Runtime, address: SocketAddress) -> Task[R
|
|
|
2616
2603
|
read(state).handle = handle
|
|
2617
2604
|
libuv.req_set_data(connect_req_as_base(req), ptr[void]<-state)
|
|
2618
2605
|
|
|
2619
|
-
let destination_storage =
|
|
2606
|
+
let destination_storage = read(state).destination.storage else:
|
|
2620
2607
|
unsafe:
|
|
2621
2608
|
heap.release_bytes(ptr[void]<-req)
|
|
2622
2609
|
read(state).req = null
|
|
@@ -2723,7 +2710,7 @@ extending SocketAddress:
|
|
|
2723
2710
|
error = invalid_address_error("socket address is released")
|
|
2724
2711
|
)
|
|
2725
2712
|
|
|
2726
|
-
let ss_ptr =
|
|
2713
|
+
let ss_ptr = storage
|
|
2727
2714
|
let family = (unsafe: read(ss_ptr)).ss_family
|
|
2728
2715
|
|
|
2729
2716
|
let v4_family = ipv4_socket_family()
|
|
@@ -2800,7 +2787,7 @@ extending TcpListener:
|
|
|
2800
2787
|
if pending_accept != null[ptr[AcceptState]]:
|
|
2801
2788
|
unsafe: read(listener).accept_state = null
|
|
2802
2789
|
finish_accept(
|
|
2803
|
-
|
|
2790
|
+
pending_accept,
|
|
2804
2791
|
Result[TcpStream, Error].failure(error= net_error("listener released")),
|
|
2805
2792
|
-1
|
|
2806
2793
|
)
|
|
@@ -2823,8 +2810,7 @@ extending UdpSocket:
|
|
|
2823
2810
|
let handle = this.handle else:
|
|
2824
2811
|
return
|
|
2825
2812
|
|
|
2826
|
-
let state_raw = libuv.handle_get_data(udp_as_handle(handle))
|
|
2827
|
-
if state_raw == null[ptr[void]]:
|
|
2813
|
+
let state_raw = libuv.handle_get_data(udp_as_handle(handle)) else:
|
|
2828
2814
|
this.handle = null
|
|
2829
2815
|
close_raw_udp_handle(handle)
|
|
2830
2816
|
return
|