nbio(tests): fill the socket until sending blocks

This commit is contained in:
kalsprite
2026-08-21 21:58:40 -07:00
parent 7bb55ba45b
commit d29b2cadbd

View File

@@ -302,13 +302,25 @@ poll :: proc(t: ^testing.T) {
on_poll1 :: proc(op: ^nbio.Operation, t: ^testing.T, can_recv: ^bool) {
ev(t, op.poll.result, nil)
// Send 4 GB of data, which in my experience causes a Would_Block error because we filled up the internal buffer.
// Fill the socket until sending actually blocks. How much that takes depends
// on the machine's socket buffers, so keep sending rather than assuming a
// fixed amount does it. Nothing is reading yet, so this terminates.
buf, mem_err := make([]byte, mem.Gigabyte*4, context.temp_allocator)
ev(t, mem_err, nil)
// Use `core:net` as example external code that doesn't care about the event loop.
net.set_blocking(op.poll.socket, false)
n, send_err := net.send(op.poll.socket, buf)
n: int
send_err: net.Network_Error
for _ in 0..<16 {
sent: int
sent, send_err = net.send(op.poll.socket, buf)
n += sent
if send_err != nil {
break
}
}
ev(t, send_err, net.TCP_Send_Error.Would_Block)
log.debugf("blocking after %M", n)