1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Add checks for clean disconnect in HTTP/TCP/SSL.

Half-open TCP connection can, of course, only be detected by
writing the socket, or waiting for TCP timeout.
This commit is contained in:
Fabio Alessandrelli
2018-09-14 14:13:11 +02:00
parent 561a7772c6
commit 92de6df113
4 changed files with 66 additions and 3 deletions

View File

@@ -249,6 +249,23 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() {
if (status == STATUS_CONNECTING) {
_poll_connection();
} else if (status == STATUS_CONNECTED) {
Error err;
err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
if (err == OK) {
// FIN received
if (_sock->get_available_bytes() == 0) {
disconnect_from_host();
return status;
}
}
// Also poll write
err = _sock->poll(NetSocket::POLL_TYPE_IN_OUT, 0);
if (err != OK && err != ERR_BUSY) {
// Got an error
disconnect_from_host();
status = STATUS_ERROR;
}
}
return status;