mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 10:13:51 +01:00
Throw error exceptions if the recvfrom within SocketImpl::available causes an error.
This commit is contained in:
parent
6998c66539
commit
5dabc6515c
@ -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;
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ private:
|
||||
void testGatherScatterSTRFFixedUNIX();
|
||||
void testGatherScatterVariableUNIX();
|
||||
void testGatherScatterSTRFVariableUNIX();
|
||||
|
||||
void testLocalUDPConnectionResetWin();
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user