Skip to content

Commit acba901

Browse files
committed
[WebSocket] Allow reusing closing and closed peers
1 parent 26d1577 commit acba901

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

modules/websocket/emws_peer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ void EMWSPeer::_esws_on_close(void *p_obj, int p_code, const char *p_reason, int
5959
}
6060

6161
Error EMWSPeer::connect_to_url(const String &p_url, Ref<TLSOptions> p_tls_options) {
62+
ERR_FAIL_COND_V(p_url.is_empty(), ERR_INVALID_PARAMETER);
6263
ERR_FAIL_COND_V(p_tls_options.is_valid() && p_tls_options->is_server(), ERR_INVALID_PARAMETER);
63-
ERR_FAIL_COND_V(ready_state != STATE_CLOSED, ERR_ALREADY_IN_USE);
64+
ERR_FAIL_COND_V(ready_state != STATE_CLOSED && ready_state != STATE_CLOSING, ERR_ALREADY_IN_USE);
65+
6466
_clear();
6567

6668
String host;

modules/websocket/wsl_peer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void WSLPeer::Resolver::try_next_candidate(Ref<StreamPeerTCP> &p_tcp) {
124124
/// Server functions
125125
///
126126
Error WSLPeer::accept_stream(Ref<StreamPeer> p_stream) {
127-
ERR_FAIL_COND_V(wsl_ctx || tcp.is_valid(), ERR_ALREADY_IN_USE);
128127
ERR_FAIL_COND_V(p_stream.is_null(), ERR_INVALID_PARAMETER);
128+
ERR_FAIL_COND_V(ready_state != STATE_CLOSED && ready_state != STATE_CLOSING, ERR_ALREADY_IN_USE);
129129

130130
_clear();
131131

@@ -471,9 +471,9 @@ bool WSLPeer::_verify_server_response() {
471471
}
472472

473473
Error WSLPeer::connect_to_url(const String &p_url, Ref<TLSOptions> p_options) {
474-
ERR_FAIL_COND_V(wsl_ctx || tcp.is_valid(), ERR_ALREADY_IN_USE);
475474
ERR_FAIL_COND_V(p_url.is_empty(), ERR_INVALID_PARAMETER);
476475
ERR_FAIL_COND_V(p_options.is_valid() && p_options->is_server(), ERR_INVALID_PARAMETER);
476+
ERR_FAIL_COND_V(ready_state != STATE_CLOSED && ready_state != STATE_CLOSING, ERR_ALREADY_IN_USE);
477477

478478
_clear();
479479

0 commit comments

Comments
 (0)