@shd101wyy/yo 0.1.29 → 0.1.31
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.
- package/.github/skills/yo-async-effects/SKILL.md +3 -3
- package/.github/skills/yo-async-effects/async-effects-recipes.md +19 -11
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +33 -13
- package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +1 -1
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +59 -21
- package/README.md +4 -3
- package/out/cjs/index.cjs +964 -710
- package/out/cjs/yo-cli.cjs +1119 -855
- package/out/cjs/yo-lsp.cjs +1003 -749
- package/out/esm/index.mjs +964 -710
- package/out/types/src/codegen/exprs/async.d.ts +2 -0
- package/out/types/src/codegen/exprs/await.d.ts +1 -0
- package/out/types/src/codegen/exprs/closures.d.ts +4 -0
- package/out/types/src/codegen/functions/context.d.ts +6 -0
- package/out/types/src/codegen/index.d.ts +1 -1
- package/out/types/src/compiler-utils.d.ts +1 -1
- package/out/types/src/env.d.ts +2 -0
- package/out/types/src/evaluator/builtins/pragma.d.ts +9 -0
- package/out/types/src/evaluator/builtins/unsafe.d.ts +8 -0
- package/out/types/src/evaluator/context.d.ts +2 -0
- package/out/types/src/evaluator/index.d.ts +1 -1
- package/out/types/src/evaluator/memory-safety.d.ts +14 -0
- package/out/types/src/evaluator/types/flowability.d.ts +6 -0
- package/out/types/src/evaluator/utils/closure.d.ts +2 -1
- package/out/types/src/evaluator/utils.d.ts +3 -0
- package/out/types/src/evaluator/values/impl.d.ts +14 -0
- package/out/types/src/expr-traversal.d.ts +1 -0
- package/out/types/src/expr.d.ts +4 -1
- package/out/types/src/public-safe-report.d.ts +19 -0
- package/out/types/src/tests/comptime-ref-gate.test.d.ts +1 -0
- package/out/types/src/tests/pragma-validation.test.d.ts +1 -0
- package/out/types/src/tests/public-safe-report.test.d.ts +1 -0
- package/out/types/src/tests/thread-safety-codegen.test.d.ts +1 -0
- package/out/types/src/tests/type-representation-pointer.test.d.ts +1 -0
- package/out/types/src/tests/unsafe-gate.test.d.ts +1 -0
- package/out/types/src/tests/unsafe-report-classify.test.d.ts +1 -0
- package/out/types/src/types/definitions.d.ts +2 -0
- package/out/types/src/types/utils.d.ts +4 -0
- package/out/types/src/unsafe-report.d.ts +29 -0
- package/out/types/src/value.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/scripts/add-pragma-for-pointer-decls.ts +134 -0
- package/scripts/add-pragma.ts +58 -0
- package/scripts/migrate-amp-method-calls.ts +186 -0
- package/scripts/migrate-clone-calls.ts +93 -0
- package/scripts/migrate-get-unwrap.ts +166 -0
- package/scripts/migrate-index-patterns.ts +210 -0
- package/scripts/migrate-index-trait.ts +142 -0
- package/scripts/migrate-iterator.ts +150 -0
- package/scripts/migrate-self-ptr.ts +220 -0
- package/scripts/migrate-skip-pragmas.ts +109 -0
- package/scripts/migrate-tostring.ts +134 -0
- package/scripts/trim-pragma.ts +130 -0
- package/scripts/wrap-extern-calls.ts +161 -0
- package/std/alg/hash.yo +3 -2
- package/std/allocator.yo +6 -5
- package/std/async.yo +2 -2
- package/std/build.yo +5 -2
- package/std/collections/array_list.yo +59 -40
- package/std/collections/btree_map.yo +19 -18
- package/std/collections/deque.yo +9 -8
- package/std/collections/hash_map.yo +101 -13
- package/std/collections/hash_set.yo +5 -4
- package/std/collections/linked_list.yo +39 -4
- package/std/collections/ordered_map.yo +3 -3
- package/std/collections/priority_queue.yo +14 -13
- package/std/crypto/md5.yo +2 -1
- package/std/crypto/random.yo +16 -15
- package/std/crypto/sha256.yo +2 -1
- package/std/encoding/base64.yo +14 -14
- package/std/encoding/hex.yo +3 -3
- package/std/encoding/json.yo +59 -10
- package/std/encoding/punycode.yo +24 -23
- package/std/encoding/toml.yo +4 -3
- package/std/encoding/utf16.yo +2 -2
- package/std/env.yo +43 -28
- package/std/error.yo +6 -6
- package/std/fmt/display.yo +2 -2
- package/std/fmt/index.yo +6 -5
- package/std/fmt/to_string.yo +39 -38
- package/std/fmt/writer.yo +9 -8
- package/std/fs/dir.yo +34 -33
- package/std/fs/file.yo +52 -51
- package/std/fs/metadata.yo +10 -9
- package/std/fs/temp.yo +24 -13
- package/std/fs/walker.yo +10 -9
- package/std/gc.yo +1 -0
- package/std/glob.yo +7 -7
- package/std/http/client.yo +15 -14
- package/std/http/http.yo +6 -6
- package/std/http/index.yo +1 -1
- package/std/imm/list.yo +34 -1
- package/std/imm/map.yo +2 -1
- package/std/imm/set.yo +1 -0
- package/std/imm/sorted_map.yo +2 -1
- package/std/imm/sorted_set.yo +1 -0
- package/std/imm/string.yo +27 -23
- package/std/imm/vec.yo +18 -2
- package/std/io/reader.yo +2 -1
- package/std/io/writer.yo +3 -2
- package/std/libc/assert.yo +1 -0
- package/std/libc/ctype.yo +1 -0
- package/std/libc/dirent.yo +1 -0
- package/std/libc/errno.yo +1 -0
- package/std/libc/fcntl.yo +1 -0
- package/std/libc/float.yo +1 -0
- package/std/libc/limits.yo +1 -0
- package/std/libc/math.yo +1 -0
- package/std/libc/signal.yo +1 -0
- package/std/libc/stdatomic.yo +251 -1
- package/std/libc/stdint.yo +1 -0
- package/std/libc/stdio.yo +1 -0
- package/std/libc/stdlib.yo +1 -0
- package/std/libc/string.yo +1 -0
- package/std/libc/sys/stat.yo +1 -0
- package/std/libc/time.yo +1 -0
- package/std/libc/unistd.yo +1 -0
- package/std/libc/wctype.yo +1 -0
- package/std/libc/windows.yo +2 -0
- package/std/log.yo +7 -6
- package/std/net/addr.yo +5 -4
- package/std/net/dns.yo +7 -6
- package/std/net/errors.yo +8 -8
- package/std/net/tcp.yo +19 -18
- package/std/net/udp.yo +13 -12
- package/std/os/signal.yo +3 -3
- package/std/path.yo +1 -0
- package/std/prelude.yo +398 -184
- package/std/process/command.yo +40 -23
- package/std/process/index.yo +2 -1
- package/std/regex/compiler.yo +10 -9
- package/std/regex/index.yo +41 -41
- package/std/regex/match.yo +2 -2
- package/std/regex/parser.yo +21 -21
- package/std/regex/vm.yo +42 -41
- package/std/string/rune.yo +4 -0
- package/std/string/string.yo +95 -40
- package/std/string/string_builder.yo +9 -9
- package/std/string/unicode.yo +50 -49
- package/std/sync/atomic.yo +557 -0
- package/std/sync/channel.yo +59 -43
- package/std/sync/cond.yo +12 -7
- package/std/sync/mutex.yo +79 -18
- package/std/sync/once.yo +25 -19
- package/std/sync/rwlock.yo +18 -15
- package/std/sync/waitgroup.yo +25 -16
- package/std/sys/advise.yo +1 -0
- package/std/sys/bufio/buf_reader.yo +17 -16
- package/std/sys/bufio/buf_writer.yo +10 -9
- package/std/sys/clock.yo +1 -0
- package/std/sys/copy.yo +1 -0
- package/std/sys/dir.yo +10 -9
- package/std/sys/dns.yo +6 -5
- package/std/sys/errors.yo +11 -11
- package/std/sys/events.yo +1 -0
- package/std/sys/externs.yo +38 -37
- package/std/sys/file.yo +17 -16
- package/std/sys/future.yo +4 -3
- package/std/sys/iov.yo +1 -0
- package/std/sys/mmap.yo +1 -0
- package/std/sys/path.yo +1 -0
- package/std/sys/perm.yo +2 -1
- package/std/sys/pipe.yo +1 -0
- package/std/sys/process.yo +5 -4
- package/std/sys/signal.yo +1 -0
- package/std/sys/socketpair.yo +1 -0
- package/std/sys/sockinfo.yo +1 -0
- package/std/sys/statfs.yo +2 -1
- package/std/sys/statx.yo +1 -0
- package/std/sys/sysinfo.yo +1 -0
- package/std/sys/tcp.yo +15 -14
- package/std/sys/temp.yo +1 -0
- package/std/sys/time.yo +2 -1
- package/std/sys/timer.yo +6 -6
- package/std/sys/tty.yo +2 -1
- package/std/sys/udp.yo +13 -12
- package/std/sys/unix.yo +12 -11
- package/std/testing/bench.yo +4 -3
- package/std/thread.yo +7 -6
- package/std/time/datetime.yo +18 -15
- package/std/time/duration.yo +11 -10
- package/std/time/instant.yo +4 -4
- package/std/time/sleep.yo +1 -0
- package/std/url/index.yo +3 -3
- package/std/worker.yo +4 -3
package/std/net/tcp.yo
CHANGED
|
@@ -9,21 +9,22 @@
|
|
|
9
9
|
// { SocketAddr, IpAddr } :: import "std/net/addr";
|
|
10
10
|
// { Exception } :: import "std/error";
|
|
11
11
|
//
|
|
12
|
-
// main :: (fn(io :
|
|
12
|
+
// main :: (fn(io : Io, exn : Exception) -> unit)({
|
|
13
13
|
// addr := SocketAddr.new(IpAddr.any_v4(), u16(8080));
|
|
14
14
|
// listener := io.await(TcpListener.bind(addr, io), { io, exn });
|
|
15
15
|
// stream := io.await(listener.accept(io), { io, exn });
|
|
16
16
|
// // ...
|
|
17
17
|
// });
|
|
18
|
+
pragma(Pragma.AllowUnsafe);
|
|
18
19
|
{ GlobalAllocator } :: import("../allocator");
|
|
19
20
|
{ malloc, free } :: GlobalAllocator;
|
|
20
21
|
{ ArrayList } :: import("../collections/array_list");
|
|
21
22
|
open(import("../string"));
|
|
22
23
|
open(import("../fmt"));
|
|
23
24
|
{ NetError } :: import("./errors");
|
|
24
|
-
{
|
|
25
|
+
{ IoError } :: import("../sys/errors");
|
|
25
26
|
{ IpAddr, SocketAddr } :: import("./addr");
|
|
26
|
-
{ Error, AnyError, Exception,
|
|
27
|
+
{ Error, AnyError, Exception, IoExn } :: import("../error");
|
|
27
28
|
IO_tcp :: import("../sys/tcp");
|
|
28
29
|
{ AF_INET, AF_INET6, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, IPPROTO_TCP, TCP_NODELAY, SO_KEEPALIVE } :: import("../sys/socket");
|
|
29
30
|
// ============================================================================
|
|
@@ -37,7 +38,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
|
|
|
37
38
|
// Build the IP string "a.b.c.d"
|
|
38
39
|
{ snprintf } :: import("../libc/stdio");
|
|
39
40
|
buf := Array(u8, usize(16)).fill(u8(0));
|
|
40
|
-
snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
|
|
41
|
+
unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
|
|
41
42
|
IO_tcp.make_sockaddr_in(&(buf(usize(0))), addr.port)
|
|
42
43
|
},
|
|
43
44
|
.V6(_) =>
|
|
@@ -46,7 +47,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
|
|
|
46
47
|
)
|
|
47
48
|
);
|
|
48
49
|
_throw_io :: (fn(errno_val : i32, exn : Exception) -> unit)(
|
|
49
|
-
exn.throw(dyn(NetError.from_io(
|
|
50
|
+
exn.throw(dyn(NetError.from_io(IoError.from_errno(errno_val))))
|
|
50
51
|
);
|
|
51
52
|
// ============================================================================
|
|
52
53
|
// TcpStream (declared before TcpListener so accept can reference it)
|
|
@@ -69,7 +70,7 @@ TcpListener :: object(
|
|
|
69
70
|
impl(
|
|
70
71
|
TcpListener,
|
|
71
72
|
/// Bind to a socket address and start listening.
|
|
72
|
-
bind : (fn(addr : SocketAddr, io :
|
|
73
|
+
bind : (fn(addr : SocketAddr, io : Io) -> Impl(Future(TcpListener, IoExn)))(
|
|
73
74
|
io.async((e) => {
|
|
74
75
|
domain := cond(
|
|
75
76
|
addr.ip.is_v4() => AF_INET,
|
|
@@ -106,7 +107,7 @@ impl(
|
|
|
106
107
|
})
|
|
107
108
|
),
|
|
108
109
|
/// Accept an incoming connection, returning a new `TcpStream`.
|
|
109
|
-
accept : (fn(self : Self, io :
|
|
110
|
+
accept : (fn(self : Self, io : Io) -> Impl(Future(TcpStream, IoExn)))({
|
|
110
111
|
fd := self._fd;
|
|
111
112
|
io.async((e) => {
|
|
112
113
|
// Allocate space for the peer address
|
|
@@ -141,7 +142,7 @@ impl(
|
|
|
141
142
|
self._local_addr
|
|
142
143
|
),
|
|
143
144
|
/// Close the listener socket.
|
|
144
|
-
close : (fn(self : Self, io :
|
|
145
|
+
close : (fn(self : Self, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
145
146
|
fd := self._fd;
|
|
146
147
|
io.async((e) => {
|
|
147
148
|
cond(
|
|
@@ -186,7 +187,7 @@ export(TcpListener);
|
|
|
186
187
|
impl(
|
|
187
188
|
TcpStream,
|
|
188
189
|
/// Connect to a remote address, returning a new `TcpStream`.
|
|
189
|
-
connect : (fn(addr : SocketAddr, io :
|
|
190
|
+
connect : (fn(addr : SocketAddr, io : Io) -> Impl(Future(TcpStream, IoExn)))(
|
|
190
191
|
io.async((e) => {
|
|
191
192
|
domain := cond(
|
|
192
193
|
addr.ip.is_v4() => AF_INET,
|
|
@@ -215,7 +216,7 @@ impl(
|
|
|
215
216
|
),
|
|
216
217
|
/// Read bytes from the stream into `buf`.
|
|
217
218
|
/// Returns the number of bytes read, or 0 if the peer closed the connection.
|
|
218
|
-
read : (fn(self : Self, buf : *(u8), size : usize, io :
|
|
219
|
+
read : (fn(self : Self, buf : *(u8), size : usize, io : Io) -> Impl(Future(i32, IoExn)))({
|
|
219
220
|
fd := self._fd;
|
|
220
221
|
io.async((e) => {
|
|
221
222
|
r := e.io.await(IO_tcp.recv(fd, buf, size, i32(0)), e.io);
|
|
@@ -224,7 +225,7 @@ impl(
|
|
|
224
225
|
}),
|
|
225
226
|
/// Write a `str` to the stream.
|
|
226
227
|
/// Returns the number of bytes written.
|
|
227
|
-
write_str : (fn(self : Self, data : str, io :
|
|
228
|
+
write_str : (fn(self : Self, data : str, io : Io) -> Impl(Future(i32, IoExn)))({
|
|
228
229
|
fd := self._fd;
|
|
229
230
|
s := String.from(data);
|
|
230
231
|
s_bytes := s.as_bytes();
|
|
@@ -235,7 +236,7 @@ impl(
|
|
|
235
236
|
}),
|
|
236
237
|
/// Write a `String` to the stream.
|
|
237
238
|
/// Returns the number of bytes written.
|
|
238
|
-
write_string : (fn(self : Self, data : String, io :
|
|
239
|
+
write_string : (fn(self : Self, data : String, io : Io) -> Impl(Future(i32, IoExn)))({
|
|
239
240
|
fd := self._fd;
|
|
240
241
|
data_bytes := data.as_bytes();
|
|
241
242
|
io.async((e) => {
|
|
@@ -245,7 +246,7 @@ impl(
|
|
|
245
246
|
}),
|
|
246
247
|
/// Write raw bytes from an `ArrayList(u8)` to the stream.
|
|
247
248
|
/// Returns the number of bytes written.
|
|
248
|
-
write_bytes : (fn(self : Self, data : ArrayList(u8), io :
|
|
249
|
+
write_bytes : (fn(self : Self, data : ArrayList(u8), io : Io) -> Impl(Future(i32, IoExn)))({
|
|
249
250
|
fd := self._fd;
|
|
250
251
|
io.async((e) => {
|
|
251
252
|
r := e.io.await(IO_tcp.send(fd, data.ptr().unwrap(), data.len(), i32(0)), e.io);
|
|
@@ -253,7 +254,7 @@ impl(
|
|
|
253
254
|
})
|
|
254
255
|
}),
|
|
255
256
|
/// Read all available data from the stream into a byte list.
|
|
256
|
-
read_bytes : (fn(self : Self, io :
|
|
257
|
+
read_bytes : (fn(self : Self, io : Io) -> Impl(Future(ArrayList(u8), IoExn)))({
|
|
257
258
|
fd := self._fd;
|
|
258
259
|
io.async((e) => {
|
|
259
260
|
buf_size := usize(4096);
|
|
@@ -286,7 +287,7 @@ impl(
|
|
|
286
287
|
}),
|
|
287
288
|
/// Shut down part or all of the connection.
|
|
288
289
|
/// `how`: 0 = read, 1 = write, 2 = both.
|
|
289
|
-
shutdown : (fn(self : Self, how : i32, io :
|
|
290
|
+
shutdown : (fn(self : Self, how : i32, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
290
291
|
fd := self._fd;
|
|
291
292
|
io.async((e) => {
|
|
292
293
|
r := e.io.await(IO_tcp.shutdown(fd, how), e.io);
|
|
@@ -299,7 +300,7 @@ impl(
|
|
|
299
300
|
})
|
|
300
301
|
}),
|
|
301
302
|
/// Close the stream.
|
|
302
|
-
close : (fn(self : Self, io :
|
|
303
|
+
close : (fn(self : Self, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
303
304
|
fd := self._fd;
|
|
304
305
|
io.async((e) => {
|
|
305
306
|
cond(
|
|
@@ -326,7 +327,7 @@ impl(
|
|
|
326
327
|
self._fd
|
|
327
328
|
),
|
|
328
329
|
/// Enable or disable TCP_NODELAY (disables Nagle's algorithm).
|
|
329
|
-
set_nodelay : (fn(self : Self, nodelay : bool, io :
|
|
330
|
+
set_nodelay : (fn(self : Self, nodelay : bool, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
330
331
|
sock_fd := self._fd;
|
|
331
332
|
io.async((e) => {
|
|
332
333
|
val := cond(nodelay => i32(1), true => i32(0));
|
|
@@ -341,7 +342,7 @@ impl(
|
|
|
341
342
|
})
|
|
342
343
|
}),
|
|
343
344
|
/// Enable or disable SO_KEEPALIVE on the socket.
|
|
344
|
-
set_keepalive : (fn(self : Self, enabled : bool, io :
|
|
345
|
+
set_keepalive : (fn(self : Self, enabled : bool, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
345
346
|
sock_fd := self._fd;
|
|
346
347
|
io.async((e) => {
|
|
347
348
|
val := cond(enabled => i32(1), true => i32(0));
|
package/std/net/udp.yo
CHANGED
|
@@ -9,20 +9,21 @@
|
|
|
9
9
|
// { SocketAddr, IpAddr } :: import "std/net/addr";
|
|
10
10
|
// { Exception } :: import "std/error";
|
|
11
11
|
//
|
|
12
|
-
// main :: (fn(io :
|
|
12
|
+
// main :: (fn(io : Io, exn : Exception) -> unit)({
|
|
13
13
|
// addr := SocketAddr.new(IpAddr.loopback_v4(), u16(9999));
|
|
14
14
|
// sock := io.await(UdpSocket.bind(addr, io), { io, exn });
|
|
15
15
|
// io.await(sock.close(io), { io, exn });
|
|
16
16
|
// });
|
|
17
|
+
pragma(Pragma.AllowUnsafe);
|
|
17
18
|
{ GlobalAllocator } :: import("../allocator");
|
|
18
19
|
{ malloc, free } :: GlobalAllocator;
|
|
19
20
|
{ ArrayList } :: import("../collections/array_list");
|
|
20
21
|
open(import("../string"));
|
|
21
22
|
open(import("../fmt"));
|
|
22
23
|
{ NetError } :: import("./errors");
|
|
23
|
-
{
|
|
24
|
+
{ IoError } :: import("../sys/errors");
|
|
24
25
|
{ IpAddr, SocketAddr } :: import("./addr");
|
|
25
|
-
{ Error, AnyError, Exception,
|
|
26
|
+
{ Error, AnyError, Exception, IoExn } :: import("../error");
|
|
26
27
|
IO_udp :: import("../sys/udp");
|
|
27
28
|
IO_tcp :: import("../sys/tcp");
|
|
28
29
|
{ AF_INET, AF_INET6, SOCK_DGRAM, SOL_SOCKET, SO_BROADCAST } :: import("../sys/socket");
|
|
@@ -35,7 +36,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
|
|
|
35
36
|
addr.ip,
|
|
36
37
|
.V4(a, b, c, d) => {
|
|
37
38
|
buf := Array(u8, usize(16)).fill(u8(0));
|
|
38
|
-
snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
|
|
39
|
+
unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
|
|
39
40
|
IO_tcp.make_sockaddr_in(&(buf(usize(0))), addr.port)
|
|
40
41
|
},
|
|
41
42
|
.V6(_) =>
|
|
@@ -43,7 +44,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
|
|
|
43
44
|
)
|
|
44
45
|
);
|
|
45
46
|
_throw_net_io :: (fn(errno_val : i32, exn : Exception) -> unit)(
|
|
46
|
-
exn.throw(dyn(NetError.from_io(
|
|
47
|
+
exn.throw(dyn(NetError.from_io(IoError.from_errno(errno_val))))
|
|
47
48
|
);
|
|
48
49
|
// ============================================================================
|
|
49
50
|
// UdpSocket
|
|
@@ -57,7 +58,7 @@ UdpSocket :: object(
|
|
|
57
58
|
impl(
|
|
58
59
|
UdpSocket,
|
|
59
60
|
/// Create and bind a UDP socket to the given address.
|
|
60
|
-
bind : (fn(addr : SocketAddr, io :
|
|
61
|
+
bind : (fn(addr : SocketAddr, io : Io) -> Impl(Future(UdpSocket, IoExn)))(
|
|
61
62
|
io.async((e) => {
|
|
62
63
|
domain := cond(
|
|
63
64
|
addr.ip.is_v4() => AF_INET,
|
|
@@ -80,7 +81,7 @@ impl(
|
|
|
80
81
|
),
|
|
81
82
|
/// Send a datagram to a specific address.
|
|
82
83
|
/// Returns the number of bytes sent.
|
|
83
|
-
send_to : (fn(self : Self, data : ArrayList(u8), addr : SocketAddr, io :
|
|
84
|
+
send_to : (fn(self : Self, data : ArrayList(u8), addr : SocketAddr, io : Io) -> Impl(Future(i32, IoExn)))({
|
|
84
85
|
fd := self._fd;
|
|
85
86
|
io.async((e) => {
|
|
86
87
|
saddr := _make_sockaddr(addr);
|
|
@@ -91,7 +92,7 @@ impl(
|
|
|
91
92
|
}),
|
|
92
93
|
/// Receive a datagram into the provided buffer.
|
|
93
94
|
/// Returns the number of bytes received.
|
|
94
|
-
recv : (fn(self : Self, buf : *(u8), size : usize, io :
|
|
95
|
+
recv : (fn(self : Self, buf : *(u8), size : usize, io : Io) -> Impl(Future(i32, IoExn)))({
|
|
95
96
|
fd := self._fd;
|
|
96
97
|
io.async((e) => {
|
|
97
98
|
r := e.io.await(IO_udp.recv(fd, buf, size, i32(0)), e.io);
|
|
@@ -100,7 +101,7 @@ impl(
|
|
|
100
101
|
}),
|
|
101
102
|
/// Receive a datagram and retrieve the sender's address.
|
|
102
103
|
/// Returns the number of bytes received.
|
|
103
|
-
recv_from : (fn(self : Self, buf : *(u8), size : usize, src_addr : *(u8), src_addr_len : *(u32), io :
|
|
104
|
+
recv_from : (fn(self : Self, buf : *(u8), size : usize, src_addr : *(u8), src_addr_len : *(u32), io : Io) -> Impl(Future(i32, IoExn)))({
|
|
104
105
|
fd := self._fd;
|
|
105
106
|
io.async((e) => {
|
|
106
107
|
r := e.io.await(IO_udp.recvfrom(fd, buf, size, i32(0), src_addr, src_addr_len), e.io);
|
|
@@ -108,7 +109,7 @@ impl(
|
|
|
108
109
|
})
|
|
109
110
|
}),
|
|
110
111
|
/// Send data on a connected socket (requires prior connect).
|
|
111
|
-
send : (fn(self : Self, data : ArrayList(u8), io :
|
|
112
|
+
send : (fn(self : Self, data : ArrayList(u8), io : Io) -> Impl(Future(i32, IoExn)))({
|
|
112
113
|
fd := self._fd;
|
|
113
114
|
io.async((e) => {
|
|
114
115
|
r := e.io.await(IO_udp.send(fd, data.ptr().unwrap(), data.len(), i32(0)), e.io);
|
|
@@ -116,7 +117,7 @@ impl(
|
|
|
116
117
|
})
|
|
117
118
|
}),
|
|
118
119
|
/// Close the socket.
|
|
119
|
-
close : (fn(self : Self, io :
|
|
120
|
+
close : (fn(self : Self, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
120
121
|
fd := self._fd;
|
|
121
122
|
io.async((e) => {
|
|
122
123
|
cond(
|
|
@@ -135,7 +136,7 @@ impl(
|
|
|
135
136
|
})
|
|
136
137
|
}),
|
|
137
138
|
/// Enable or disable SO_BROADCAST on the socket.
|
|
138
|
-
set_broadcast : (fn(self : Self, enabled : bool, io :
|
|
139
|
+
set_broadcast : (fn(self : Self, enabled : bool, io : Io) -> Impl(Future(unit, IoExn)))({
|
|
139
140
|
fd := self._fd;
|
|
140
141
|
io.async((e) => {
|
|
141
142
|
val := cond(enabled => i32(1), true => i32(0));
|
package/std/os/signal.yo
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
//! handler :: (fn(data: *(u8)) -> unit)({ println("Caught SIGINT"); });
|
|
11
11
|
//! on_signal(.Interrupt, handler);
|
|
12
12
|
//! ```
|
|
13
|
-
{
|
|
13
|
+
{ IoError } :: import("../sys/errors");
|
|
14
14
|
{ on_signal : _on_signal, off_signal : _off_signal, SignalHandler } :: import("../sys/signal");
|
|
15
15
|
{ platform, Platform } :: import("../process");
|
|
16
16
|
{ Error, AnyError, Exception } :: import("../error");
|
|
@@ -83,7 +83,7 @@ on_signal :: (fn(sig : Signal, handler : SignalHandler, exn : Exception) -> unit
|
|
|
83
83
|
r := _on_signal(num, handler);
|
|
84
84
|
cond(
|
|
85
85
|
(r < i32(0)) => {
|
|
86
|
-
exn.throw(dyn(
|
|
86
|
+
exn.throw(dyn(IoError.from_errno(i32(0) - r)));
|
|
87
87
|
},
|
|
88
88
|
true => ()
|
|
89
89
|
);
|
|
@@ -94,7 +94,7 @@ off_signal :: (fn(sig : Signal, exn : Exception) -> unit)({
|
|
|
94
94
|
r := _off_signal(num);
|
|
95
95
|
cond(
|
|
96
96
|
(r < i32(0)) => {
|
|
97
|
-
exn.throw(dyn(
|
|
97
|
+
exn.throw(dyn(IoError.from_errno(i32(0) - r)));
|
|
98
98
|
},
|
|
99
99
|
true => ()
|
|
100
100
|
);
|