Skip to content

Commit

Permalink
fix: Fixes removing disconnected clients
Browse files Browse the repository at this point in the history
Thanks to inkusgames

Fixes deep-entertainment/issues#52
  • Loading branch information
dploeger committed Dec 20, 2024
1 parent e3abab0 commit 871dab6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions addons/godottpd/http_server.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ func register_router(path: String, router: HttpRouter):
})


# Handle possibly incoming requests
## Handle possibly incoming requests
func _process(_delta: float) -> void:
if _server:
var new_client = _server.take_connection()
if new_client:
self._clients.append(new_client)
while _server.is_connection_available():
var new_client = _server.take_connection()
if new_client:
self._clients.append(new_client)
for client in self._clients:
client.poll()
if client.get_status() == StreamPeerTCP.STATUS_CONNECTED:
var bytes = client.get_available_bytes()
if bytes > 0:
Expand All @@ -104,7 +106,10 @@ func _process(_delta: float) -> void:


func _remove_disconnected_clients():
self._clients = self._clients.filter(func(c: StreamPeerTCP): c.get_status() == StreamPeerTCP.STATUS_CONNECTED)
var valid_statuses = [StreamPeerTCP.STATUS_CONNECTED, StreamPeerTCP.STATUS_CONNECTING]
self._clients = self._clients.filter(
func(c: StreamPeerTCP): return valid_statuses.has(c.get_status())
)


## Start the server
Expand Down

0 comments on commit 871dab6

Please sign in to comment.