summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-09-13 11:04:01 +0200
committerGitHub <noreply@github.com>2018-09-13 11:04:01 +0200
commit3d0638b8e97a56e7c2bc74501781f21f35d43552 (patch)
tree7de2b72d523e41f443b57a06b0f0cf9a36f5f0f6 /core
parentc8f761ae2d71ffb70c4ee59fd0f951440804f055 (diff)
parent3d12eb6ca2bfc66c9d7e43a7bea42ba603a9547a (diff)
Merge pull request #22020 from Faless/tcp_fix
Fix TCP connecting state not set correctly
Diffstat (limited to 'core')
-rw-r--r--core/io/stream_peer_tcp.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 484e160f0e..f4bf8a13ae 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -44,6 +44,7 @@ Error StreamPeerTCP::_poll_connection() {
return OK;
}
+ disconnect_from_host();
status = STATUS_ERROR;
return ERR_CONNECTION_ERROR;
}
@@ -75,17 +76,16 @@ Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port)
err = _sock->connect_to_host(p_host, p_port);
- if (err != OK) {
- if (err == ERR_BUSY) {
- status = STATUS_CONNECTING;
- } else {
- ERR_PRINT("Connection to remote host failed!");
- disconnect_from_host();
- return FAILED;
- }
+ if (err == OK) {
+ status = STATUS_CONNECTED;
+ } else if (err == ERR_BUSY) {
+ status = STATUS_CONNECTING;
+ } else {
+ ERR_PRINT("Connection to remote host failed!");
+ disconnect_from_host();
+ return FAILED;
}
- status = STATUS_CONNECTED;
peer_host = p_host;
peer_port = p_port;
@@ -163,20 +163,20 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
if (!is_connected_to_host()) {
return FAILED;
- };
+ }
if (status == STATUS_CONNECTING) {
if (_poll_connection() != OK) {
return FAILED;
- };
+ }
if (status != STATUS_CONNECTED) {
r_received = 0;
return OK;
- };
- };
+ }
+ }
Error err;
int to_read = p_bytes;
@@ -209,10 +209,7 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
} else if (read == 0) {
- _sock->close();
- status = STATUS_NONE;
- peer_port = 0;
- peer_host = IP_Address();
+ disconnect_from_host();
r_received = total_read;
return ERR_FILE_EOF;