diff options
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/packet_peer_udp_posix.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 94b4c35923..2111619080 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -121,7 +121,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) { struct sockaddr_in from = {0}; socklen_t len = sizeof(struct sockaddr_in); 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); uint32_t port = ntohs(from.sin_port); rb.write((uint8_t*)&port, 4); @@ -131,6 +131,8 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) { ++queue_count; }; + + // TODO: Should ECONNRESET be handled here? if (ret == 0 || (ret == -1 && errno != EAGAIN) ) { close(); return FAILED; |