commit
6127f17368
2 changed files with 22 additions and 3 deletions
|
@ -121,7 +121,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
|
||||||
struct sockaddr_in from = {0};
|
struct sockaddr_in from = {0};
|
||||||
socklen_t len = sizeof(struct sockaddr_in);
|
socklen_t len = sizeof(struct sockaddr_in);
|
||||||
int ret;
|
int ret;
|
||||||
while ( (ret = recvfrom(sockfd, recv_buffer, MIN(sizeof(recv_buffer),rb.data_left()-12), p_wait?0:MSG_DONTWAIT, (struct sockaddr*)&from, &len)) > 0) {
|
while ( (ret = recvfrom(sockfd, recv_buffer, MIN((int)sizeof(recv_buffer),MAX(rb.space_left()-12, 0)), p_wait?0:MSG_DONTWAIT, (struct sockaddr*)&from, &len)) > 0) {
|
||||||
rb.write((uint8_t*)&from.sin_addr, 4);
|
rb.write((uint8_t*)&from.sin_addr, 4);
|
||||||
uint32_t port = ntohs(from.sin_port);
|
uint32_t port = ntohs(from.sin_port);
|
||||||
rb.write((uint8_t*)&port, 4);
|
rb.write((uint8_t*)&port, 4);
|
||||||
|
@ -131,6 +131,8 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
|
||||||
++queue_count;
|
++queue_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Should ECONNRESET be handled here?
|
||||||
if (ret == 0 || (ret == -1 && errno != EAGAIN) ) {
|
if (ret == 0 || (ret == -1 && errno != EAGAIN) ) {
|
||||||
close();
|
close();
|
||||||
return FAILED;
|
return FAILED;
|
||||||
|
|
|
@ -121,7 +121,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
|
||||||
struct sockaddr_in from = {0};
|
struct sockaddr_in from = {0};
|
||||||
int len = sizeof(struct sockaddr_in);
|
int len = sizeof(struct sockaddr_in);
|
||||||
int ret;
|
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);
|
rb.write((uint8_t*)&from.sin_addr, 4);
|
||||||
uint32_t port = ntohs(from.sin_port);
|
uint32_t port = ntohs(from.sin_port);
|
||||||
rb.write((uint8_t*)&port, 4);
|
rb.write((uint8_t*)&port, 4);
|
||||||
|
@ -132,8 +132,25 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
|
||||||
++queue_count;
|
++queue_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (ret == SOCKET_ERROR){
|
||||||
|
int error = WSAGetLastError();
|
||||||
|
|
||||||
if (ret == 0 || (ret == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) ) {
|
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) {
|
||||||
close();
|
close();
|
||||||
return FAILED;
|
return FAILED;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue