summaryrefslogtreecommitdiff
path: root/platform/windows/stream_peer_winsock.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2017-01-18 19:04:37 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2017-01-23 20:18:23 +0100
commitfa0cb7da0e096e01476eabef37c225404c7f6f26 (patch)
tree0c55b8f4815aba34709867f1321d7082e40df084 /platform/windows/stream_peer_winsock.cpp
parente5e4e7b6a9be36bb9bf75da996c348ae2476010c (diff)
Avoid deadlock when writing/reading data on a connecting TCP socket
TCP status polling is always performed as non blocking. Trying to put a packet on a connecting socket will fail immediately.
Diffstat (limited to 'platform/windows/stream_peer_winsock.cpp')
-rw-r--r--platform/windows/stream_peer_winsock.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp
index 69a6fc177a..106eb6a5f5 100644
--- a/platform/windows/stream_peer_winsock.cpp
+++ b/platform/windows/stream_peer_winsock.cpp
@@ -78,15 +78,10 @@ Error StreamPeerWinsock::_block(int p_sockfd, bool p_read, bool p_write) const {
return ret < 0 ? FAILED : OK;
};
-Error StreamPeerWinsock::_poll_connection(bool p_block) const {
+Error StreamPeerWinsock::_poll_connection() const {
ERR_FAIL_COND_V(status != STATUS_CONNECTING || sockfd == INVALID_SOCKET, FAILED);
- if (p_block) {
-
- _block(sockfd, false, true);
- };
-
struct sockaddr_storage their_addr;
size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type);
@@ -122,7 +117,7 @@ Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, b
if (status != STATUS_CONNECTED) {
- if (_poll_connection(p_block) != OK) {
+ if (_poll_connection() != OK) {
return FAILED;
};
@@ -180,7 +175,7 @@ Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bo
if (status != STATUS_CONNECTED) {
- if (_poll_connection(p_block) != OK) {
+ if (_poll_connection() != OK) {
return FAILED;
};
@@ -254,7 +249,7 @@ Error StreamPeerWinsock::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_
StreamPeerTCP::Status StreamPeerWinsock::get_status() const {
if (status == STATUS_CONNECTING) {
- _poll_connection(false);
+ _poll_connection();
};
return status;