diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-11-19 19:33:04 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-11-19 19:33:04 -0300 |
commit | 6127f17368d6fe6256848ee86de223fa26e53ffb (patch) | |
tree | b805c43da71bd40574b6e4c6c5d32376a5921d45 /platform/windows | |
parent | 2b1a482612e594e472c12d4dec171f124d45a621 (diff) | |
parent | a8a2458f0b490ee323632c95543106232efd8042 (diff) |
Merge pull request #2756 from trond/bugfix_udp
UDP fixes
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/packet_peer_udp_winsock.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp index aff92b8fc8..0ca2d358af 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/platform/windows/packet_peer_udp_winsock.cpp @@ -121,7 +121,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) { struct sockaddr_in from = {0}; int len = sizeof(struct sockaddr_in); int ret; - while ( (ret = recvfrom(sockfd, (char*)recv_buffer, MIN(sizeof(recv_buffer),rb.data_left()-12), 0, (struct sockaddr*)&from, &len)) > 0) { + while ( (ret = recvfrom(sockfd, (char*)recv_buffer, MIN((int)sizeof(recv_buffer),MAX(rb.space_left()-12, 0)), 0, (struct sockaddr*)&from, &len)) > 0) { rb.write((uint8_t*)&from.sin_addr, 4); uint32_t port = ntohs(from.sin_port); rb.write((uint8_t*)&port, 4); @@ -132,8 +132,25 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) { ++queue_count; }; + if (ret == SOCKET_ERROR){ + int error = WSAGetLastError(); + + if (error == WSAEWOULDBLOCK){ + // Expected when doing non-blocking sockets, retry later. + } + else if (error == WSAECONNRESET){ + // If the remote target does not accept messages, this error may occur, but is harmless. + // Once the remote target gets available, this message will disappear for new messages. + } + else + { + close(); + return FAILED; + } + } + - if (ret == 0 || (ret == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) ) { + if (ret == 0) { close(); return FAILED; }; |