You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
[WebSocket] Fix WSLClient connection status.
Note, this keeps the old behaviour of reporting CONNECTION_CONNECTED while disconnecting. We should change this before 4.0, but needs further refactoring of the WebSocket classes.
This commit is contained in:
@@ -91,6 +91,7 @@ void WSLClient::_do_handshake() {
|
|||||||
data->id = 1;
|
data->id = 1;
|
||||||
_peer->make_context(data, _in_buf_size, _in_pkt_size, _out_buf_size, _out_pkt_size);
|
_peer->make_context(data, _in_buf_size, _in_pkt_size, _out_buf_size, _out_pkt_size);
|
||||||
_peer->set_no_delay(true);
|
_peer->set_no_delay(true);
|
||||||
|
_status = CONNECTION_CONNECTED;
|
||||||
_on_connect(protocol);
|
_on_connect(protocol);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -231,6 +232,7 @@ Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
|
|||||||
}
|
}
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
_request = request.utf8();
|
_request = request.utf8();
|
||||||
|
_status = CONNECTION_CONNECTING;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -337,21 +339,19 @@ Ref<WebSocketPeer> WSLClient::get_peer(int p_peer_id) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const {
|
MultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const {
|
||||||
|
// This is surprising, but keeps the current behaviour to allow clean close requests.
|
||||||
|
// TODO Refactor WebSocket and split Client/Server/Multiplayer like done in other peers.
|
||||||
if (_peer->is_connected_to_host()) {
|
if (_peer->is_connected_to_host()) {
|
||||||
return CONNECTION_CONNECTED;
|
return CONNECTION_CONNECTED;
|
||||||
}
|
}
|
||||||
|
return _status;
|
||||||
if (_tcp->get_status() == StreamPeerTCP::STATUS_CONNECTING || _resolver_id != IP::RESOLVER_INVALID_ID) {
|
|
||||||
return CONNECTION_CONNECTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CONNECTION_DISCONNECTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSLClient::disconnect_from_host(int p_code, String p_reason) {
|
void WSLClient::disconnect_from_host(int p_code, String p_reason) {
|
||||||
_peer->close(p_code, p_reason);
|
_peer->close(p_code, p_reason);
|
||||||
_connection = Ref<StreamPeer>(nullptr);
|
_connection = Ref<StreamPeer>(nullptr);
|
||||||
_tcp = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
|
_tcp = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
|
||||||
|
_status = CONNECTION_DISCONNECTED;
|
||||||
|
|
||||||
_key = "";
|
_key = "";
|
||||||
_host = "";
|
_host = "";
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ private:
|
|||||||
Ref<WSLPeer> _peer;
|
Ref<WSLPeer> _peer;
|
||||||
Ref<StreamPeerTCP> _tcp;
|
Ref<StreamPeerTCP> _tcp;
|
||||||
Ref<StreamPeer> _connection;
|
Ref<StreamPeer> _connection;
|
||||||
|
ConnectionStatus _status = CONNECTION_DISCONNECTED;
|
||||||
|
|
||||||
CharString _request;
|
CharString _request;
|
||||||
int _requested = 0;
|
int _requested = 0;
|
||||||
@@ -59,8 +60,6 @@ private:
|
|||||||
uint8_t _resp_buf[WSL_MAX_HEADER_SIZE];
|
uint8_t _resp_buf[WSL_MAX_HEADER_SIZE];
|
||||||
int _resp_pos = 0;
|
int _resp_pos = 0;
|
||||||
|
|
||||||
String _response;
|
|
||||||
|
|
||||||
String _key;
|
String _key;
|
||||||
String _host;
|
String _host;
|
||||||
uint16_t _port = 0;
|
uint16_t _port = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user