diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2015-03-03 13:05:19 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2015-03-03 13:05:19 -0330 |
commit | 2fe064b44b5d56c87b65e889bfe898ce2ee737fc (patch) | |
tree | d7cfb49f989a5fffa61791859b260f4048be4efe /cpp/src | |
parent | Fixed (ICE-5835) - Scope of operation parameters (diff) | |
download | ice-2fe064b44b5d56c87b65e889bfe898ce2ee737fc.tar.bz2 ice-2fe064b44b5d56c87b65e889bfe898ce2ee737fc.tar.xz ice-2fe064b44b5d56c87b65e889bfe898ce2ee737fc.zip |
ICE-6116 reduce verbose warnings about socket buffer size
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 51 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.h | 28 | ||||
-rw-r--r-- | cpp/src/Ice/Network.cpp | 37 | ||||
-rw-r--r-- | cpp/src/Ice/Network.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/ProtocolInstance.h | 15 | ||||
-rw-r--r-- | cpp/src/Ice/StreamSocket.cpp | 36 | ||||
-rw-r--r-- | cpp/src/Ice/TcpAcceptor.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/UdpTransceiver.cpp | 34 | ||||
-rw-r--r-- | cpp/src/Ice/UdpTransceiver.h | 2 | ||||
-rw-r--r-- | cpp/src/IceSSL/AcceptorI.cpp | 2 |
10 files changed, 166 insertions, 43 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index b39bd0d7fe8..59d2287ac1f 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -1890,6 +1890,57 @@ IceInternal::Instance::updateThreadObservers() } } + +BufSizeWarnInfo +IceInternal::Instance::getBufSizeWarn(Short type) +{ + IceUtil::Mutex::Lock lock(_setBufSizeWarnMutex); + + return getBufSizeWarnInternal(type); +} + +BufSizeWarnInfo +IceInternal::Instance::getBufSizeWarnInternal(Short type) +{ + BufSizeWarnInfo info; + map<Short, BufSizeWarnInfo>::iterator p = _setBufSizeWarn.find(type); + if(p == _setBufSizeWarn.end()) + { + info.sndWarn = false; + info.sndSize = -1; + info.rcvWarn = false; + info.rcvSize = -1; + _setBufSizeWarn.insert(make_pair(type, info)); + } + else + { + info = p->second; + } + return info; +} + +void +IceInternal::Instance::setSndBufSizeWarn(Short type, int size) +{ + IceUtil::Mutex::Lock lock(_setBufSizeWarnMutex); + + BufSizeWarnInfo info = getBufSizeWarnInternal(type); + info.sndWarn = true; + info.sndSize = size; + _setBufSizeWarn[type] = info; +} + +void +IceInternal::Instance::setRcvBufSizeWarn(Short type, int size) +{ + IceUtil::Mutex::Lock lock(_setBufSizeWarnMutex); + + BufSizeWarnInfo info = getBufSizeWarnInternal(type); + info.rcvWarn = true; + info.rcvSize = size; + _setBufSizeWarn[type] = info; +} + IceInternal::ProcessI::ProcessI(const CommunicatorPtr& communicator) : _communicator(communicator) { diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h index 176e5d731fc..a6e9182b136 100644 --- a/cpp/src/Ice/Instance.h +++ b/cpp/src/Ice/Instance.h @@ -63,6 +63,24 @@ typedef IceUtil::Handle<MetricsAdminI> MetricsAdminIPtr; class RequestHandlerFactory; typedef IceUtil::Handle<RequestHandlerFactory> RequestHandlerFactoryPtr; +// +// Structure to track warnings for attempts to set socket buffer sizes +// +struct BufSizeWarnInfo +{ + // Whether send size warning has been emitted + bool sndWarn; + + // The send size for which the warning wwas emitted + int sndSize; + + // Whether receive size warning has been emitted + bool rcvWarn; + + // The receive size for which the warning wwas emitted + int rcvSize; +}; + class Instance : public IceUtil::Shared, public IceUtil::Monitor<IceUtil::RecMutex> { public: @@ -118,7 +136,11 @@ public: IceUtil::StringConverterPtr getStringConverter() const { return _stringConverter; } IceUtil::WstringConverterPtr getWstringConverter() const { return _wstringConverter; } - + + BufSizeWarnInfo getBufSizeWarn(Ice::Short type); + void setSndBufSizeWarn(Ice::Short type, int size); + void setRcvBufSizeWarn(Ice::Short type, int size); + private: Instance(const Ice::CommunicatorPtr&, const Ice::InitializationData&); @@ -134,6 +156,8 @@ private: void addAllAdminFacets(); void setServerProcessProxy(const Ice::ObjectAdapterPtr&, const Ice::Identity&); + BufSizeWarnInfo getBufSizeWarnInternal(Ice::Short type); + enum State { StateActive, @@ -177,6 +201,8 @@ private: Ice::Identity _adminIdentity; std::set<std::string> _adminFacetFilter; IceInternal::MetricsAdminIPtr _metricsAdmin; + std::map<Ice::Short, BufSizeWarnInfo> _setBufSizeWarn; + IceUtil::Mutex _setBufSizeWarnMutex; }; class ProcessI : public Ice::Process diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index 2271916f2ac..584f31561f3 100644 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -23,6 +23,7 @@ #include <IceUtil/StringUtil.h> #include <IceUtil/StringConverter.h> #include <Ice/LocalException.h> +#include <Ice/ProtocolInstance.h> // For setTcpBufSize #include <Ice/Properties.h> // For setTcpBufSize #include <Ice/LoggerUtil.h> // For setTcpBufSize #include <Ice/Buffer.h> @@ -1461,7 +1462,7 @@ IceInternal::getHostsForEndpointExpand(const string& host, ProtocolSupport proto HostName^ h = it->Current; if(h->IPInformation != nullptr && h->IPInformation->NetworkAdapter != nullptr) { - hosts.push_back(IceUtil::wstringToString(h->CanonicalName->Data(), + hosts.push_back(IceUtil::wstringToString(h->CanonicalName->Data(), IceUtil::getProcessStringConverter())); } } @@ -1633,7 +1634,7 @@ IceInternal::isMulticast(const Address& addr) } void -IceInternal::setTcpBufSize(SOCKET fd, const Ice::PropertiesPtr& properties, const Ice::LoggerPtr& logger) +IceInternal::setTcpBufSize(SOCKET fd, const ProtocolInstancePtr& instance) { assert(fd != INVALID_SOCKET); @@ -1646,9 +1647,7 @@ IceInternal::setTcpBufSize(SOCKET fd, const Ice::PropertiesPtr& properties, cons #else const int dfltBufSize = 0; #endif - Int sizeRequested; - - sizeRequested = properties->getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); + Int sizeRequested = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1658,14 +1657,21 @@ IceInternal::setTcpBufSize(SOCKET fd, const Ice::PropertiesPtr& properties, cons // setRecvBufferSize(fd, sizeRequested); int size = getRecvBufferSize(fd); - if(size > 0 && size < sizeRequested) // Warn if the size that was set is less than the requested size. + if(size > 0 && size < sizeRequested) { - Ice::Warning out(logger); - out << "TCP receive buffer size: requested size of " << sizeRequested << " adjusted to " << size; + // Warn if the size that was set is less than the requested size and + // we have not already warned. + BufSizeWarnInfo winfo = instance->getBufSizeWarn(TCPEndpointType); + if(!winfo.rcvWarn || sizeRequested != winfo.rcvSize) + { + Ice::Warning out(instance->logger()); + out << "TCP receive buffer size: requested size of " << sizeRequested << " adjusted to " << size; + instance->setRcvBufSizeWarn(TCPEndpointType, sizeRequested); + } } } - sizeRequested = properties->getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize); + sizeRequested = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1675,10 +1681,17 @@ IceInternal::setTcpBufSize(SOCKET fd, const Ice::PropertiesPtr& properties, cons // setSendBufferSize(fd, sizeRequested); int size = getSendBufferSize(fd); - if(size > 0 && size < sizeRequested) // Warn if the size that was set is less than the requested size. + if(size > 0 && size < sizeRequested) { - Ice::Warning out(logger); - out << "TCP send buffer size: requested size of " << sizeRequested << " adjusted to " << size; + // Warn if the size that was set is less than the requested size and + // we have not already warned. + BufSizeWarnInfo winfo = instance->getBufSizeWarn(TCPEndpointType); + if(!winfo.sndWarn || sizeRequested != winfo.sndSize) + { + Ice::Warning out(instance->logger()); + out << "TCP send buffer size: requested size of " << sizeRequested << " adjusted to " << size; + instance->setSndBufSizeWarn(TCPEndpointType, sizeRequested); + } } } } diff --git a/cpp/src/Ice/Network.h b/cpp/src/Ice/Network.h index cff790dfef6..eb15092fe51 100644 --- a/cpp/src/Ice/Network.h +++ b/cpp/src/Ice/Network.h @@ -239,7 +239,7 @@ ICE_API int getPort(const Address&); ICE_API void setPort(Address&, int); ICE_API bool isMulticast(const Address&); -ICE_API void setTcpBufSize(SOCKET, const Ice::PropertiesPtr&, const Ice::LoggerPtr&); +ICE_API void setTcpBufSize(SOCKET, const ProtocolInstancePtr&); ICE_API void setBlock(SOCKET, bool); ICE_API void setSendBufferSize(SOCKET, int); diff --git a/cpp/src/Ice/ProtocolInstance.h b/cpp/src/Ice/ProtocolInstance.h index ebe860016a1..fc757d788e2 100644 --- a/cpp/src/Ice/ProtocolInstance.h +++ b/cpp/src/Ice/ProtocolInstance.h @@ -64,6 +64,21 @@ public: return _secure; } + BufSizeWarnInfo getBufSizeWarn(Ice::Short type) + { + return _instance->getBufSizeWarn(type); + } + + void setSndBufSizeWarn(Ice::Short type, int size) + { + _instance->setSndBufSizeWarn(type, size); + } + + void setRcvBufSizeWarn(Ice::Short type, int size) + { + _instance->setRcvBufSizeWarn(type, size); + } + bool preferIPv6() const; ProtocolSupport protocolSupport() const; const std::string& defaultHost() const; diff --git a/cpp/src/Ice/StreamSocket.cpp b/cpp/src/Ice/StreamSocket.cpp index 1d2650e25a0..3c9bbf1afcc 100644 --- a/cpp/src/Ice/StreamSocket.cpp +++ b/cpp/src/Ice/StreamSocket.cpp @@ -16,11 +16,11 @@ using namespace IceInternal; StreamSocket::StreamSocket(const ProtocolInstancePtr& instance, const NetworkProxyPtr& proxy, const Address& addr, - const Address& sourceAddr) : + const Address& sourceAddr) : NativeInfo(createSocket(false, proxy ? proxy->getAddress() : addr)), - _proxy(proxy), - _addr(addr), - _sourceAddr(sourceAddr), + _proxy(proxy), + _addr(addr), + _sourceAddr(sourceAddr), _state(StateNeedConnect) #ifdef ICE_USE_IOCP , _read(SocketOperationRead), @@ -37,7 +37,7 @@ StreamSocket::StreamSocket(const ProtocolInstancePtr& instance, _desc = fdToString(_fd, _proxy, _addr); } -StreamSocket::StreamSocket(const ProtocolInstancePtr& instance, SOCKET fd) : +StreamSocket::StreamSocket(const ProtocolInstancePtr& instance, SOCKET fd) : NativeInfo(fd), _state(StateConnected) #ifdef ICE_USE_IOCP @@ -54,7 +54,7 @@ StreamSocket::~StreamSocket() assert(_fd == INVALID_SOCKET); } -SocketOperation +SocketOperation StreamSocket::connect(Buffer& readBuffer, Buffer& writeBuffer) { if(_state == StateNeedConnect) @@ -100,7 +100,7 @@ StreamSocket::connect(Buffer& readBuffer, Buffer& writeBuffer) return IceInternal::SocketOperationNone; } -bool +bool StreamSocket::isConnected() { return _state == StateConnected; @@ -116,7 +116,7 @@ StreamSocket::getSendPacketSize(size_t length) #endif } -size_t +size_t StreamSocket::getRecvPacketSize(size_t length) { #ifdef ICE_USE_IOCP @@ -145,7 +145,7 @@ StreamSocket::read(Buffer& buf) return SocketOperationNone; } } - } + } buf.i += read(reinterpret_cast<char*>(&*buf.i), buf.b.end() - buf.i); return buf.i != buf.b.end() ? SocketOperationRead : SocketOperationNone; } @@ -173,7 +173,7 @@ StreamSocket::write(Buffer& buf) buf.i += write(reinterpret_cast<const char*>(&*buf.i), buf.b.end() - buf.i); return buf.i != buf.b.end() ? SocketOperationWrite : SocketOperationNone; } - + ssize_t StreamSocket::read(char* buf, size_t length) { @@ -230,7 +230,7 @@ StreamSocket::read(char* buf, size_t length) buf += ret; read += ret; length -= ret; - + if(packetSize > length) { packetSize = length; @@ -239,11 +239,11 @@ StreamSocket::read(char* buf, size_t length) return read; } -ssize_t +ssize_t StreamSocket::write(const char* buf, size_t length) { assert(_fd != INVALID_SOCKET); - + #ifdef ICE_USE_IOCP // // On Windows, limiting the buffer size is important to prevent @@ -314,7 +314,7 @@ StreamSocket::write(const char* buf, size_t length) } #ifdef ICE_USE_IOCP -AsyncInfo* +AsyncInfo* StreamSocket::getAsyncInfo(SocketOperation op) { switch(op) @@ -463,7 +463,7 @@ StreamSocket::finishRead(Buffer& buf) } #endif -void +void StreamSocket::close() { assert(_fd != INVALID_SOCKET); @@ -479,17 +479,17 @@ StreamSocket::close() } } -const std::string& +const std::string& StreamSocket::toString() const { return _desc; } -void +void StreamSocket::init(const ProtocolInstancePtr& instance) { setBlock(_fd, false); - setTcpBufSize(_fd, instance->properties(), instance->logger()); + setTcpBufSize(_fd, instance); #ifdef ICE_USE_IOCP // diff --git a/cpp/src/Ice/TcpAcceptor.cpp b/cpp/src/Ice/TcpAcceptor.cpp index 210b3f8351d..3c11c448d25 100644 --- a/cpp/src/Ice/TcpAcceptor.cpp +++ b/cpp/src/Ice/TcpAcceptor.cpp @@ -207,7 +207,7 @@ IceInternal::TcpAcceptor::TcpAcceptor(const TcpEndpointIPtr& endpoint, #endif setBlock(_fd, false); - setTcpBufSize(_fd, _instance->properties(), _instance->logger()); + setTcpBufSize(_fd, _instance); #ifndef _WIN32 // // Enable SO_REUSEADDR on Unix platforms to allow re-using the diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 1d2fcf47bbf..7458567aceb 100644 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -909,7 +909,7 @@ IceInternal::UdpTransceiver::UdpTransceiver(const ProtocolInstancePtr& instance, #endif { _fd = createSocket(true, _addr); - setBufSize(_instance->properties()); + setBufSize(); setBlock(_fd, false); #ifndef ICE_OS_WINRT @@ -982,7 +982,7 @@ IceInternal::UdpTransceiver::UdpTransceiver(const UdpEndpointIPtr& endpoint, con #endif { _fd = createServerSocket(true, _addr, instance->protocolSupport()); - setBufSize(instance->properties()); + setBufSize(); setBlock(_fd, false); #ifndef ICE_OS_WINRT @@ -1009,18 +1009,20 @@ IceInternal::UdpTransceiver::~UdpTransceiver() // Set UDP receive and send buffer sizes. // void -IceInternal::UdpTransceiver::setBufSize(const Ice::PropertiesPtr& properties) +IceInternal::UdpTransceiver::setBufSize() { assert(_fd != INVALID_SOCKET); for(int i = 0; i < 2; ++i) { + bool isSnd; string direction; string prop; int* addr; int dfltSize; if(i == 0) { + isSnd = false; direction = "receive"; prop = "Ice.UDP.RcvSize"; addr = &_rcvSize; @@ -1028,6 +1030,7 @@ IceInternal::UdpTransceiver::setBufSize(const Ice::PropertiesPtr& properties) } else { + isSnd = true; direction = "send"; prop = "Ice.UDP.SndSize"; addr = &_sndSize; @@ -1043,7 +1046,7 @@ IceInternal::UdpTransceiver::setBufSize(const Ice::PropertiesPtr& properties) // // Get property for buffer size and check for sanity. // - Int sizeRequested = properties->getPropertyAsIntWithDefault(prop, dfltSize); + Int sizeRequested = _instance->properties()->getPropertyAsIntWithDefault(prop, dfltSize); if(sizeRequested < (_udpOverhead + headerSize)) { Warning out(_instance->logger()); @@ -1070,7 +1073,8 @@ IceInternal::UdpTransceiver::setBufSize(const Ice::PropertiesPtr& properties) } // - // Warn if the size that was set is less than the requested size. + // Warn if the size that was set is less than the requested size and + // we have not already warned. // if(*addr == 0) // set buffer size not supported. { @@ -1078,9 +1082,23 @@ IceInternal::UdpTransceiver::setBufSize(const Ice::PropertiesPtr& properties) } else if(*addr < sizeRequested) { - Warning out(_instance->logger()); - out << "UDP " << direction << " buffer size: requested size of " - << sizeRequested << " adjusted to " << *addr; + BufSizeWarnInfo winfo = _instance->getBufSizeWarn(UDPEndpointType); + if((isSnd && (!winfo.sndWarn || winfo.sndSize != sizeRequested)) || + (!isSnd && (!winfo.rcvWarn || winfo.rcvSize != sizeRequested))) + { + Warning out(_instance->logger()); + out << "UDP " << direction << " buffer size: requested size of " + << sizeRequested << " adjusted to " << *addr; + + if(isSnd) + { + _instance->setSndBufSizeWarn(UDPEndpointType, sizeRequested); + } + else + { + _instance->setRcvBufSizeWarn(UDPEndpointType, sizeRequested); + } + } } } } diff --git a/cpp/src/Ice/UdpTransceiver.h b/cpp/src/Ice/UdpTransceiver.h index b09c9ce327e..a6faac20bb4 100644 --- a/cpp/src/Ice/UdpTransceiver.h +++ b/cpp/src/Ice/UdpTransceiver.h @@ -72,7 +72,7 @@ private: virtual ~UdpTransceiver(); - void setBufSize(const Ice::PropertiesPtr&); + void setBufSize(); #ifdef ICE_OS_WINRT bool checkIfErrorOrCompleted(SocketOperation, Windows::Foundation::IAsyncInfo^); diff --git a/cpp/src/IceSSL/AcceptorI.cpp b/cpp/src/IceSSL/AcceptorI.cpp index 08a11b42644..5e58cf23497 100644 --- a/cpp/src/IceSSL/AcceptorI.cpp +++ b/cpp/src/IceSSL/AcceptorI.cpp @@ -231,7 +231,7 @@ IceSSL::AcceptorI::AcceptorI(const EndpointIPtr& endpoint, const InstancePtr& in _acceptBuf.resize((sizeof(sockaddr_storage) + 16) * 2); #endif IceInternal::setBlock(_fd, false); - IceInternal::setTcpBufSize(_fd, _instance->properties(), _instance->logger()); + IceInternal::setTcpBufSize(_fd, _instance); #ifndef _WIN32 // // Enable SO_REUSEADDR on Unix platforms to allow re-using the |