mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 00:07:59 +02:00
code cleanup; fixed some issues reported by Klocwork
This commit is contained in:
@@ -27,10 +27,7 @@ namespace Net {
|
||||
|
||||
|
||||
ICMPSocket::ICMPSocket(IPAddress::Family family, int dataSize, int ttl, int timeout):
|
||||
Socket(new ICMPSocketImpl(family, dataSize, ttl, timeout)),
|
||||
_dataSize(dataSize),
|
||||
_ttl(ttl),
|
||||
_timeout(timeout)
|
||||
Socket(new ICMPSocketImpl(family, dataSize, ttl, timeout))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,4 +75,22 @@ int ICMPSocket::receiveFrom(SocketAddress& address, int flags)
|
||||
}
|
||||
|
||||
|
||||
int ICMPSocket::dataSize() const
|
||||
{
|
||||
return static_cast<ICMPSocketImpl*>(impl())->dataSize();
|
||||
}
|
||||
|
||||
|
||||
int ICMPSocket::ttl() const
|
||||
{
|
||||
return static_cast<ICMPSocketImpl*>(impl())->ttl();
|
||||
}
|
||||
|
||||
|
||||
int ICMPSocket::timeout() const
|
||||
{
|
||||
return static_cast<ICMPSocketImpl*>(impl())->timeout();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Buffer.h"
|
||||
|
||||
|
||||
using Poco::TimeoutException;
|
||||
@@ -33,6 +34,7 @@ namespace Net {
|
||||
ICMPSocketImpl::ICMPSocketImpl(IPAddress::Family family, int dataSize, int ttl, int timeout):
|
||||
RawSocketImpl(family, IPPROTO_ICMP),
|
||||
_icmpPacket(family, dataSize),
|
||||
_ttl(ttl),
|
||||
_timeout(timeout)
|
||||
{
|
||||
setOption(IPPROTO_IP, IP_TTL, ttl);
|
||||
@@ -55,7 +57,7 @@ int ICMPSocketImpl::sendTo(const void*, int, const SocketAddress& address, int f
|
||||
int ICMPSocketImpl::receiveFrom(void*, int, SocketAddress& address, int flags)
|
||||
{
|
||||
int maxPacketSize = _icmpPacket.maxPacketSize();
|
||||
unsigned char* buffer = new unsigned char[maxPacketSize];
|
||||
Poco::Buffer<unsigned char> buffer(maxPacketSize);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -68,31 +70,24 @@ int ICMPSocketImpl::receiveFrom(void*, int, SocketAddress& address, int flags)
|
||||
// fake ping responses will cause an endless loop.
|
||||
throw TimeoutException();
|
||||
}
|
||||
SocketImpl::receiveFrom(buffer, maxPacketSize, address, flags);
|
||||
SocketImpl::receiveFrom(buffer.begin(), maxPacketSize, address, flags);
|
||||
}
|
||||
while (!_icmpPacket.validReplyID(buffer, maxPacketSize));
|
||||
}
|
||||
catch (TimeoutException&)
|
||||
{
|
||||
delete [] buffer;
|
||||
throw;
|
||||
while (!_icmpPacket.validReplyID(buffer.begin(), maxPacketSize));
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
std::string err = _icmpPacket.errorDescription(buffer, maxPacketSize);
|
||||
delete [] buffer;
|
||||
std::string err = _icmpPacket.errorDescription(buffer.begin(), maxPacketSize);
|
||||
if (!err.empty())
|
||||
throw ICMPException(err);
|
||||
else
|
||||
throw;
|
||||
}
|
||||
|
||||
struct timeval then = _icmpPacket.time(buffer, maxPacketSize);
|
||||
struct timeval then = _icmpPacket.time(buffer.begin(), maxPacketSize);
|
||||
struct timeval now = _icmpPacket.time();
|
||||
|
||||
int elapsed = (((now.tv_sec * 1000000) + now.tv_usec) - ((then.tv_sec * 1000000) + then.tv_usec))/1000;
|
||||
|
||||
delete[] buffer;
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user