summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMax Hilbrunner <mhilbrunner@users.noreply.github.com>2018-09-21 15:03:55 +0200
committerGitHub <noreply@github.com>2018-09-21 15:03:55 +0200
commita384cffc44af8fb891c83d71ad133b60b6823726 (patch)
tree8e690f6abb99423eaca66be8d537222b83234643 /core
parent0279985a70ebc2d69aa3672238a8813bdb5db26c (diff)
parent92de6df113ddce8b85758541f2a23c38a45dc365 (diff)
Merge pull request #22316 from Faless/poll_more_checks_easy_squash
Add checks for clean disconnect in HTTP/TCP/SSL.
Diffstat (limited to 'core')
-rw-r--r--core/io/http_client.cpp12
-rw-r--r--core/io/stream_peer_ssl.cpp1
-rw-r--r--core/io/stream_peer_tcp.cpp17
3 files changed, 30 insertions, 0 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 80a281a21d..ac563df0c3 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -375,6 +375,18 @@ Error HTTPClient::poll() {
}
} break;
case STATUS_CONNECTED: {
+ // Check if we are still connected
+ if (ssl) {
+ Ref<StreamPeerSSL> tmp = connection;
+ tmp->poll();
+ if (tmp->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
+ status = STATUS_CONNECTION_ERROR;
+ return ERR_CONNECTION_ERROR;
+ }
+ } else if (tcp_connection->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
+ status = STATUS_CONNECTION_ERROR;
+ return ERR_CONNECTION_ERROR;
+ }
// Connection established, requests can now be made
return OK;
} break;
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index 8d8682686a..138f91301e 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -128,6 +128,7 @@ void StreamPeerSSL::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_handshake"), "set_blocking_handshake_enabled", "is_blocking_handshake_enabled");
BIND_ENUM_CONSTANT(STATUS_DISCONNECTED);
+ BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
BIND_ENUM_CONSTANT(STATUS_CONNECTED);
BIND_ENUM_CONSTANT(STATUS_ERROR);
BIND_ENUM_CONSTANT(STATUS_ERROR_HOSTNAME_MISMATCH);
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index f4bf8a13ae..28561e8cbc 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -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;