aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2026-01-30 23:20:31 +0100
committerLaytan <laytanlaats@hotmail.com>2026-01-30 23:37:31 +0100
commit0a05ff05a391673b7f9d095d76485706ba50e0bb (patch)
tree0d81311befb0f01fa1c78b43b23b90dc35e74f93 /tests
parent2142d0796460a32f6342038be01d2fb69c1b785f (diff)
nbio: fix send/recv buffer logic
Diffstat (limited to 'tests')
-rw-r--r--tests/core/nbio/net.odin72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/core/nbio/net.odin b/tests/core/nbio/net.odin
index 688ee0b45..77e44f73b 100644
--- a/tests/core/nbio/net.odin
+++ b/tests/core/nbio/net.odin
@@ -398,3 +398,75 @@ sendfile :: proc(t: ^testing.T) {
ev(t, nbio.run(), nil)
}
}
+
+@(test)
+vectored :: proc(t: ^testing.T) {
+ if event_loop_guard(t) {
+ testing.set_fail_timeout(t, time.Minute)
+
+ sock, ep := open_next_available_local_port(t)
+
+ to_send := [?][]byte{
+ {'H', 'e', 'l', 'l'},
+ {'o', 'p', 'e'},
+ {'!'},
+ }
+
+ to_recv := [?][]byte{
+ {0, 0, 0, 0},
+ {0, 0, 0},
+ {0},
+ }
+
+ // Server
+ {
+ nbio.accept_poly2(sock, t, &to_send, on_accept)
+
+ on_accept :: proc(op: ^nbio.Operation, t: ^testing.T, to_send: ^[3][]byte) {
+ ev(t, op.accept.err, nil)
+ e(t, op.accept.client != 0)
+ to_send_copy := to_send^[:]
+ nbio.send_poly3(op.accept.client, to_send_copy, t, op.accept.socket, to_send, on_send)
+ }
+
+ on_send :: proc(op: ^nbio.Operation, t: ^testing.T, server: net.TCP_Socket, to_send: ^[3][]byte) {
+ ev(t, op.send.err, nil)
+ ev(t, op.send.sent, 8)
+
+ expected := to_send^
+ for buf, i in expected {
+ ev(t, string(op.send.bufs[i]), string(buf))
+ }
+
+ nbio.close(op.send.socket.(net.TCP_Socket))
+ nbio.close(server)
+ }
+ }
+
+ // Client
+ {
+ nbio.dial_poly3(ep, t, &to_recv, &to_send, on_dial)
+
+ on_dial :: proc(op: ^nbio.Operation, t: ^testing.T, to_recv: ^[3][]byte, expected: ^[3][]byte) {
+ ev(t, op.dial.err, nil)
+
+ to_recv_copy := to_recv^[:]
+ nbio.recv_poly2(op.dial.socket, to_recv_copy, t, expected, on_recv, all=true)
+ }
+
+ on_recv :: proc(op: ^nbio.Operation, t: ^testing.T, expected: ^[3][]byte) {
+ ev(t, op.recv.err, nil)
+ ev(t, op.recv.received, 8)
+
+ expected := expected^[:]
+ for buf, i in expected {
+ ev(t, string(op.recv.bufs[i]), string(buf))
+ }
+
+ nbio.close(op.recv.socket.(net.TCP_Socket))
+ }
+ }
+
+ ev(t, nbio.run(), nil)
+ }
+}