Nichts an schließende oder fehlende Verbindungen senden

NetLink merkt sich die Verbindungen, die es gerade schließt, und
schickt ihnen nichts mehr. Pakete an alle oder an alle außer einem gehen
einzeln an die offenen Verbindungen, statt Godot ein Ziel zu nennen, das
es nicht mehr gibt. Beides löste sonst Fehler in Godot aus, etwa wenn
der Host Figuren weiterreicht, während er einen abgelehnten Gast
hinauswirft. Ein neuer Test mit zwei Gästen deckt das ab.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Steven Wroblewski
2026-10-01 20:27:07 +02:00
parent 0917450014
commit a43ce66a89
2 changed files with 60 additions and 10 deletions
+32 -3
View File
@@ -100,14 +100,43 @@ func test_a_guest_that_quits_is_seen_leaving() -> void:
host.close()
func test_messages_to_a_connection_that_is_gone_are_dropped() -> void:
## Godot reports an error for every packet to a connection that is gone or
## being closed; the test runner turns each such error into a failure.
func test_nothing_is_sent_to_connections_that_are_gone_or_closing() -> void:
var host := NetLink.new()
check_eq(host.host(0, "127.0.0.1"), OK, "the host listens")
var first := NetLink.new()
var second := NetLink.new()
first.join("127.0.0.1", host.local_port())
second.join("127.0.0.1", host.local_port())
await _pump([host, first, second], 10)
var peers: Array = _events[host].map(func(event: Dictionary) -> int: return event["peer"])
check_eq(peers.size(), 2, "two guests connected")
var leaving: int = peers[0]
var staying: int = peers[1]
# Connections that never existed.
host.send(12345, PackedByteArray([1]))
host.send_figure(12345, PackedByteArray([1]))
host.send_figure(-12345, PackedByteArray([1]))
host.close_peer(12345)
check_eq(host.poll(0.0), [], "nothing happened")
host.close()
# A connection that is being closed, and everybody while it closes.
host.close_peer(leaving)
for frame in 10:
host.send(leaving, PackedByteArray([2]))
host.send_figure(leaving, PackedByteArray([2]))
host.send_figure(-staying, PackedByteArray([2]))
host.send_figure(0, PackedByteArray([2]))
await _pump([host, first, second], 1)
# The connection is gone now.
host.send(leaving, PackedByteArray([3]))
host.send_figure(-leaving, PackedByteArray([3]))
await _pump([host, first, second], 5)
check(_types(first).has("disconnected"), "the first guest was closed")
check(not _types(second).has("disconnected"), "the second guest stays")
for link in [host, first, second]:
link.close()
func test_a_guest_gives_up_when_nobody_answers() -> void: