ludic.net: a message's record, bytes and lists kept - queued ones back to a pool once sent or taken, the inbox's two drains on, a read text interned
np_queue made a NetMsg and a buffer per message, every flush a new keep list, and every message that came in a NetMessage and a buffer; nr_text a new string per text read. A party plays at dozens a second, so all of it is kept now: a pool of MTU-sized records for the queue (a peer's two lists swapped by the flush), the inbox's records in two halves swapped when a message finds the inbox empty, net_written's one record, a relay hello's and a STUN request's bytes in one scratch buffer, and the texts read out interned. Tests: 6000 messages with the heap flat (Os.heap_bytes), and an inbox record that holds still across a drain and comes back two drains on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e6729b3123
commit
ca69a3f9ae
11 changed files with 134 additions and 20 deletions
|
|
@ -14,11 +14,16 @@ export function np_flush(net_st: mut NetState, slot: int) -> void {
|
|||
function net__flush_one(net_st: mut NetState, p: NetPeer) -> bool {
|
||||
var o = 20
|
||||
var count = 0
|
||||
let keep = new []NetMsg
|
||||
let keep = p.back
|
||||
List.clear(keep)
|
||||
for i in 0 .. len(p.queue) {
|
||||
let m = p.queue[i]
|
||||
if m.rel and m.id <= p.acked { continue } # taken: drop it
|
||||
if not m.rel and net_st.net__time - m.made > 0.5 { continue } # stale
|
||||
let taken = m.rel and m.id <= p.acked
|
||||
let stale = not m.rel and net_st.net__time - m.made > 0.5
|
||||
if taken or stale {
|
||||
push(net_st.net__free, m) # back to the pool
|
||||
continue
|
||||
}
|
||||
var due = true
|
||||
if m.rel and not (m.sent < 0.0) and net_st.net__time - m.sent < 0.25 { due = false }
|
||||
var size = 4 + m.len
|
||||
|
|
@ -28,11 +33,12 @@ function net__flush_one(net_st: mut NetState, p: NetPeer) -> bool {
|
|||
count += 1
|
||||
m.sent = net_st.net__time
|
||||
if net_st.net__kind_out != null and m.kind < 64 { net_st.net__kind_out[m.kind] += size }
|
||||
if m.rel { push(keep, m) } # kept until acknowledged
|
||||
if m.rel { push(keep, m) } else { push(net_st.net__free, m) } # a reliable one kept until acknowledged
|
||||
} else {
|
||||
push(keep, m) # not due, or waits for the next packet
|
||||
}
|
||||
}
|
||||
p.back = p.queue
|
||||
p.queue = keep
|
||||
if count == 0 and not p.ack_due { return false }
|
||||
nb_put8(net_st.net__out, 0, 'M')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue