Merge pull request #22020 from Faless/tcp_fix

Fix TCP connecting state not set correctly
This commit is contained in:
Rémi Verschelde 2018-09-13 11:04:01 +02:00 committed by GitHub
commit 3d0638b8e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,6 +44,7 @@ Error StreamPeerTCP::_poll_connection() {
return OK; return OK;
} }
disconnect_from_host();
status = STATUS_ERROR; status = STATUS_ERROR;
return ERR_CONNECTION_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); err = _sock->connect_to_host(p_host, p_port);
if (err != OK) { if (err == OK) {
if (err == ERR_BUSY) { status = STATUS_CONNECTED;
status = STATUS_CONNECTING; } else if (err == ERR_BUSY) {
} else { status = STATUS_CONNECTING;
ERR_PRINT("Connection to remote host failed!"); } else {
disconnect_from_host(); ERR_PRINT("Connection to remote host failed!");
return FAILED; disconnect_from_host();
} return FAILED;
} }
status = STATUS_CONNECTED;
peer_host = p_host; peer_host = p_host;
peer_port = p_port; 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()) { if (!is_connected_to_host()) {
return FAILED; return FAILED;
}; }
if (status == STATUS_CONNECTING) { if (status == STATUS_CONNECTING) {
if (_poll_connection() != OK) { if (_poll_connection() != OK) {
return FAILED; return FAILED;
}; }
if (status != STATUS_CONNECTED) { if (status != STATUS_CONNECTED) {
r_received = 0; r_received = 0;
return OK; return OK;
}; }
}; }
Error err; Error err;
int to_read = p_bytes; 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) { } else if (read == 0) {
_sock->close(); disconnect_from_host();
status = STATUS_NONE;
peer_port = 0;
peer_host = IP_Address();
r_received = total_read; r_received = total_read;
return ERR_FILE_EOF; return ERR_FILE_EOF;