From f7b1357ec6ace6f581987168b1a183453b6a052a Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Wed, 13 Jun 2007 15:14:53 +0000 Subject: [PATCH] latest sources from main repository --- Net/include/Poco/Net/SocketDefs.h | 4 ++-- Net/include/Poco/Net/SocketImpl.h | 3 ++- Net/src/IPAddress.cpp | 19 ++++++++++++++++++- Net/src/MultipartReader.cpp | 3 ++- Net/src/Socket.cpp | 4 ++-- Net/src/SocketImpl.cpp | 21 +++++++++++++++++---- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Net/include/Poco/Net/SocketDefs.h b/Net/include/Poco/Net/SocketDefs.h index 4e7cb4749..002ea32d9 100644 --- a/Net/include/Poco/Net/SocketDefs.h +++ b/Net/include/Poco/Net/SocketDefs.h @@ -1,7 +1,7 @@ // // SocketDefs.h // -// $Id: //poco/Main/Net/include/Poco/Net/SocketDefs.h#3 $ +// $Id: //poco/Main/Net/include/Poco/Net/SocketDefs.h#4 $ // // Library: Net // Package: NetCore @@ -176,7 +176,7 @@ #endif -#if (POCO_OS == POCO_OS_HPUX) +#if (POCO_OS == POCO_OS_HPUX) || (POCO_OS == POCO_OS_SOLARIS) #define POCO_BROKEN_TIMEOUTS 1 #endif diff --git a/Net/include/Poco/Net/SocketImpl.h b/Net/include/Poco/Net/SocketImpl.h index 1a6c18bfc..184623942 100644 --- a/Net/include/Poco/Net/SocketImpl.h +++ b/Net/include/Poco/Net/SocketImpl.h @@ -1,7 +1,7 @@ // // SocketImpl.h // -// $Id: //poco/Main/Net/include/Poco/Net/SocketImpl.h#2 $ +// $Id: //poco/Main/Net/include/Poco/Net/SocketImpl.h#3 $ // // Library: Net // Package: Sockets @@ -407,6 +407,7 @@ private: poco_socket_t _sockfd; #if defined(POCO_BROKEN_TIMEOUTS) Poco::Timespan _recvTimeout; + Poco::Timespan _sndTimeout; #endif friend class Socket; diff --git a/Net/src/IPAddress.cpp b/Net/src/IPAddress.cpp index faa87f887..eba9d7f09 100644 --- a/Net/src/IPAddress.cpp +++ b/Net/src/IPAddress.cpp @@ -1,7 +1,7 @@ // // IPAddress.cpp // -// $Id: //poco/Main/Net/src/IPAddress.cpp#16 $ +// $Id: //poco/Main/Net/src/IPAddress.cpp#17 $ // // Library: Net // Package: NetCore @@ -82,6 +82,7 @@ public: virtual bool isOrgLocalMC() const = 0; virtual bool isGlobalMC() const = 0; virtual void mask(const IPAddressImpl* pMask, const IPAddressImpl* pSet) = 0; + virtual IPAddressImpl* clone() const = 0; protected: IPAddressImpl() @@ -246,6 +247,11 @@ public: _addr.s_addr &= static_cast(pMask)->_addr.s_addr; _addr.s_addr |= static_cast(pSet)->_addr.s_addr & ~static_cast(pMask)->_addr.s_addr; } + + IPAddressImpl* clone() const + { + return new IPv4AddressImpl(&_addr); + } private: struct in_addr _addr; @@ -450,6 +456,11 @@ public: throw Poco::NotImplementedException("mask() is only supported for IPv4 addresses"); } + IPAddressImpl* clone() const + { + return new IPv6AddressImpl(&_addr); + } + private: struct in6_addr _addr; }; @@ -760,6 +771,9 @@ bool IPAddress::tryParse(const std::string& addr, IPAddress& result) void IPAddress::mask(const IPAddress& mask) { + IPAddressImpl* pClone = _pImpl->clone(); + _pImpl->release(); + _pImpl = pClone; IPAddress null; _pImpl->mask(mask._pImpl, null._pImpl); } @@ -767,6 +781,9 @@ void IPAddress::mask(const IPAddress& mask) void IPAddress::mask(const IPAddress& mask, const IPAddress& set) { + IPAddressImpl* pClone = _pImpl->clone(); + _pImpl->release(); + _pImpl = pClone; _pImpl->mask(mask._pImpl, set._pImpl); } diff --git a/Net/src/MultipartReader.cpp b/Net/src/MultipartReader.cpp index 310ac6f22..8cc1a2a48 100644 --- a/Net/src/MultipartReader.cpp +++ b/Net/src/MultipartReader.cpp @@ -1,7 +1,7 @@ // // MultipartReader.cpp // -// $Id: //poco/Main/Net/src/MultipartReader.cpp#11 $ +// $Id: //poco/Main/Net/src/MultipartReader.cpp#12 $ // // Library: Net // Package: Messages @@ -74,6 +74,7 @@ int MultipartStreamBuf::readFromDevice(char* buffer, std::streamsize length) static const int eof = std::char_traits::eof(); int n = 0; int ch = _istr.get(); + if (ch == eof) return -1; *buffer++ = (char) ch; ++n; if (ch == '\n' || ch == '\r' && _istr.peek() == '\n') { diff --git a/Net/src/Socket.cpp b/Net/src/Socket.cpp index 7f68a0367..5fd56cf17 100644 --- a/Net/src/Socket.cpp +++ b/Net/src/Socket.cpp @@ -1,7 +1,7 @@ // // Socket.cpp // -// $Id: //poco/Main/Net/src/Socket.cpp#13 $ +// $Id: //poco/Main/Net/src/Socket.cpp#14 $ // // Library: Net // Package: Sockets @@ -125,7 +125,7 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce { Poco::Timestamp end; Poco::Timespan waited = end - start; - if (waited > remainingTime) + if (waited < remainingTime) remainingTime -= waited; else remainingTime = 0; diff --git a/Net/src/SocketImpl.cpp b/Net/src/SocketImpl.cpp index 40650175b..cfebec52e 100644 --- a/Net/src/SocketImpl.cpp +++ b/Net/src/SocketImpl.cpp @@ -1,7 +1,7 @@ // // SocketImpl.cpp // -// $Id: //poco/Main/Net/src/SocketImpl.cpp#22 $ +// $Id: //poco/Main/Net/src/SocketImpl.cpp#23 $ // // Library: Net // Package: Sockets @@ -220,6 +220,14 @@ int SocketImpl::sendBytes(const void* buffer, int length, int flags) { poco_assert (_sockfd != POCO_INVALID_SOCKET); +#if defined(POCO_BROKEN_TIMEOUTS) + if (_sndTimeout.totalMicroseconds() != 0) + { + if (!poll(_sndTimeout, SELECT_WRITE)) + throw TimeoutException(); + } +#endif + int rc; do { @@ -359,7 +367,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode) { Poco::Timestamp end; Poco::Timespan waited = end - start; - if (waited > remainingTime) + if (waited < remainingTime) remainingTime -= waited; else remainingTime = 0; @@ -404,6 +412,8 @@ void SocketImpl::setSendTimeout(const Poco::Timespan& timeout) #if defined(_WIN32) int value = (int) timeout.totalMilliseconds(); setOption(SOL_SOCKET, SO_SNDTIMEO, value); +#elif defined(POCO_BROKEN_TIMEOUTS) + _sndTimeout = timeout; #else setOption(SOL_SOCKET, SO_SNDTIMEO, timeout); #endif @@ -417,6 +427,8 @@ Poco::Timespan SocketImpl::getSendTimeout() int value; getOption(SOL_SOCKET, SO_SNDTIMEO, value); result = Timespan::TimeDiff(value)*1000; +#elif defined(POCO_BROKEN_TIMEOUTS) + result = _sndTimeout; #else getOption(SOL_SOCKET, SO_SNDTIMEO, result); #endif @@ -426,13 +438,14 @@ Poco::Timespan SocketImpl::getSendTimeout() void SocketImpl::setReceiveTimeout(const Poco::Timespan& timeout) { +#ifndef POCO_BROKEN_TIMEOUTS #if defined(_WIN32) int value = (int) timeout.totalMilliseconds(); setOption(SOL_SOCKET, SO_RCVTIMEO, value); #else - setOption(SOL_SOCKET, SO_RCVTIMEO, timeout); + setOption(SOL_SOCKET, SO_RCVTIMEO, timeout); #endif -#if defined(POCO_BROKEN_TIMEOUTS) +#else _recvTimeout = timeout; #endif }