Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Net/src/SocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ int SocketImpl::available()
{
std::vector<char> buf(result);
result = recvfrom(sockfd(), &buf[0], result, MSG_PEEK, nullptr, nullptr);

if (result < 0) error();
}
#endif
return result;
Expand Down
28 changes: 28 additions & 0 deletions Net/testsuite/src/DatagramSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,32 @@ void DatagramSocketTest::testGatherScatterVariableUNIX()
}


void DatagramSocketTest::testLocalUDPConnectionResetWin()
{
#if defined(POCO_OS_FAMILY_WINDOWS)
// create a local UDP socket and connect to another local port which doesn't have a UDP socket
DatagramSocket socket(SocketAddress("127.0.0.1", 0), true, true);

socket.connect(SocketAddress("127.0.0.1", 2345));

// send some data to the socket
unsigned char values[5]{};
socket.sendBytes(values, 5);

try
{
// available calls recvfrom which can cause a "Connection Reset by Peer" error for UDP sockets in Windows due to ICMP packets for remote destination not existing
socket.available();

fail();
}
catch (const Poco::Net::ConnectionResetException&)
{
}
#endif
}


void DatagramSocketTest::setUp()
{
}
Expand Down Expand Up @@ -832,5 +858,7 @@ CppUnit::Test* DatagramSocketTest::suite()
CppUnit_addTest(pSuite, DatagramSocketTest, testGatherScatterFixed);
CppUnit_addTest(pSuite, DatagramSocketTest, testGatherScatterVariable);

CppUnit_addTest(pSuite, DatagramSocketTest, testLocalUDPConnectionResetWin);

return pSuite;
}
2 changes: 2 additions & 0 deletions Net/testsuite/src/DatagramSocketTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class DatagramSocketTest: public CppUnit::TestCase
void testGatherScatterSTRFFixedUNIX();
void testGatherScatterVariableUNIX();
void testGatherScatterSTRFVariableUNIX();

void testLocalUDPConnectionResetWin();
};


Expand Down