You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
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.
This commit is contained in:
@@ -88,15 +88,10 @@ Error StreamPeerTCPPosix::_block(int p_sockfd, bool p_read, bool p_write) const
|
|||||||
return ret < 0 ? FAILED : OK;
|
return ret < 0 ? FAILED : OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
Error StreamPeerTCPPosix::_poll_connection(bool p_block) const {
|
Error StreamPeerTCPPosix::_poll_connection() const {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(status != STATUS_CONNECTING || sockfd == -1, FAILED);
|
ERR_FAIL_COND_V(status != STATUS_CONNECTING || sockfd == -1, FAILED);
|
||||||
|
|
||||||
if (p_block) {
|
|
||||||
|
|
||||||
_block(sockfd, false, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sockaddr_storage their_addr;
|
struct sockaddr_storage their_addr;
|
||||||
size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type);
|
size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type);
|
||||||
|
|
||||||
@@ -191,7 +186,7 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent,
|
|||||||
|
|
||||||
if (status != STATUS_CONNECTED) {
|
if (status != STATUS_CONNECTED) {
|
||||||
|
|
||||||
if (_poll_connection(p_block) != OK) {
|
if (_poll_connection() != OK) {
|
||||||
|
|
||||||
return FAILED;
|
return FAILED;
|
||||||
};
|
};
|
||||||
@@ -251,7 +246,7 @@ Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, b
|
|||||||
|
|
||||||
if (status == STATUS_CONNECTING) {
|
if (status == STATUS_CONNECTING) {
|
||||||
|
|
||||||
if (_poll_connection(p_block) != OK) {
|
if (_poll_connection() != OK) {
|
||||||
|
|
||||||
return FAILED;
|
return FAILED;
|
||||||
};
|
};
|
||||||
@@ -330,7 +325,7 @@ bool StreamPeerTCPPosix::is_connected_to_host() const {
|
|||||||
StreamPeerTCP::Status StreamPeerTCPPosix::get_status() const {
|
StreamPeerTCP::Status StreamPeerTCPPosix::get_status() const {
|
||||||
|
|
||||||
if (status == STATUS_CONNECTING) {
|
if (status == STATUS_CONNECTING) {
|
||||||
_poll_connection(false);
|
_poll_connection();
|
||||||
};
|
};
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ protected:
|
|||||||
|
|
||||||
Error _block(int p_sockfd, bool p_read, bool p_write) const;
|
Error _block(int p_sockfd, bool p_read, bool p_write) const;
|
||||||
|
|
||||||
Error _poll_connection(bool p_block) const;
|
Error _poll_connection() const;
|
||||||
|
|
||||||
IP_Address peer_host;
|
IP_Address peer_host;
|
||||||
int peer_port;
|
int peer_port;
|
||||||
|
|||||||
@@ -78,15 +78,10 @@ Error StreamPeerWinsock::_block(int p_sockfd, bool p_read, bool p_write) const {
|
|||||||
return ret < 0 ? FAILED : OK;
|
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);
|
ERR_FAIL_COND_V(status != STATUS_CONNECTING || sockfd == INVALID_SOCKET, FAILED);
|
||||||
|
|
||||||
if (p_block) {
|
|
||||||
|
|
||||||
_block(sockfd, false, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sockaddr_storage their_addr;
|
struct sockaddr_storage their_addr;
|
||||||
size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type);
|
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 (status != STATUS_CONNECTED) {
|
||||||
|
|
||||||
if (_poll_connection(p_block) != OK) {
|
if (_poll_connection() != OK) {
|
||||||
|
|
||||||
return FAILED;
|
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 (status != STATUS_CONNECTED) {
|
||||||
|
|
||||||
if (_poll_connection(p_block) != OK) {
|
if (_poll_connection() != OK) {
|
||||||
|
|
||||||
return FAILED;
|
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 {
|
StreamPeerTCP::Status StreamPeerWinsock::get_status() const {
|
||||||
|
|
||||||
if (status == STATUS_CONNECTING) {
|
if (status == STATUS_CONNECTING) {
|
||||||
_poll_connection(false);
|
_poll_connection();
|
||||||
};
|
};
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ protected:
|
|||||||
|
|
||||||
Error _block(int p_sockfd, bool p_read, bool p_write) const;
|
Error _block(int p_sockfd, bool p_read, bool p_write) const;
|
||||||
|
|
||||||
Error _poll_connection(bool p_block) const;
|
Error _poll_connection() const;
|
||||||
|
|
||||||
IP_Address peer_host;
|
IP_Address peer_host;
|
||||||
int peer_port;
|
int peer_port;
|
||||||
|
|||||||
Reference in New Issue
Block a user