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 | |
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
25 files changed, 453 insertions, 91 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 diff --git a/cs/src/Ice/Instance.cs b/cs/src/Ice/Instance.cs index 882a0dcdabc..8dd99f3860f 100644 --- a/cs/src/Ice/Instance.cs +++ b/cs/src/Ice/Instance.cs @@ -16,6 +16,21 @@ namespace IceInternal using System.Threading; using System; + public sealed class BufSizeWarnInfo + { + // Whether send size warning has been emitted + public bool sndWarn; + + // The send size for which the warning wwas emitted + public int sndSize; + + // Whether receive size warning has been emitted + public bool rcvWarn; + + // The receive size for which the warning wwas emitted + public int rcvSize; + } + public sealed class Instance { private class ObserverUpdaterI : Ice.Instrumentation.ObserverUpdater @@ -1323,6 +1338,50 @@ namespace IceInternal } } + public BufSizeWarnInfo getBufSizeWarn(short type) + { + lock(_setBufSizeWarn) + { + BufSizeWarnInfo info; + if(!_setBufSizeWarn.ContainsKey(type)) + { + info = new BufSizeWarnInfo(); + info.sndWarn = false; + info.sndSize = -1; + info.rcvWarn = false; + info.rcvSize = -1; + _setBufSizeWarn.Add(type, info); + } + else + { + info = _setBufSizeWarn[type]; + } + return info; + } + } + + public void setSndBufSizeWarn(short type, int size) + { + lock(_setBufSizeWarn) + { + BufSizeWarnInfo info = getBufSizeWarn(type); + info.sndWarn = true; + info.sndSize = size; + _setBufSizeWarn[type] = info; + } + } + + public void setRcvBufSizeWarn(short type, int size) + { + lock(_setBufSizeWarn) + { + BufSizeWarnInfo info = getBufSizeWarn(type); + info.rcvWarn = true; + info.rcvSize = size; + _setBufSizeWarn[type] = info; + } + } + internal void updateConnectionObservers() { try @@ -1507,6 +1566,7 @@ namespace IceInternal private Dictionary<string, Ice.Object> _adminFacets = new Dictionary<string, Ice.Object>(); private HashSet<string> _adminFacetFilter = new HashSet<string>(); private Ice.Identity _adminIdentity; + private Dictionary<short, BufSizeWarnInfo> _setBufSizeWarn = new Dictionary<short, BufSizeWarnInfo>(); #if !SILVERLIGHT private static bool _printProcessIdDone = false; diff --git a/cs/src/Ice/Network.cs b/cs/src/Ice/Network.cs index 55f5c8131c5..f1e1580d7bb 100644 --- a/cs/src/Ice/Network.cs +++ b/cs/src/Ice/Network.cs @@ -1024,7 +1024,7 @@ namespace IceInternal } public static void - setTcpBufSize(Socket socket, Ice.Properties properties, Ice.Logger logger) + setTcpBufSize(Socket socket, ProtocolInstance instance) { // // By default, on Windows we use a 128KB buffer size. On Unix @@ -1036,7 +1036,7 @@ namespace IceInternal dfltBufSize = 128 * 1024; } - int sizeRequested = properties.getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); + int sizeRequested = instance.properties().getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1046,14 +1046,21 @@ namespace IceInternal // setRecvBufferSize(socket, sizeRequested); int size = getRecvBufferSize(socket); - if(size < sizeRequested) // Warn if the size that was set is less than the requested size. + if(size < sizeRequested) { - logger.warning("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(Ice.TCPEndpointType.value); + if(!winfo.rcvWarn || sizeRequested != winfo.rcvSize) + { + instance.logger().warning("TCP receive buffer size: requested size of " + sizeRequested + + " adjusted to " + size); + instance.setRcvBufSizeWarn(Ice.TCPEndpointType.value, sizeRequested); + } } } - sizeRequested = properties.getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize); + sizeRequested = instance.properties().getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1065,7 +1072,15 @@ namespace IceInternal int size = getSendBufferSize(socket); if(size < sizeRequested) // Warn if the size that was set is less than the requested size. { - logger.warning("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(Ice.TCPEndpointType.value); + if(!winfo.sndWarn || sizeRequested != winfo.sndSize) + { + instance.logger().warning("TCP send buffer size: requested size of " + sizeRequested + + " adjusted to " + size); + instance.setSndBufSizeWarn(Ice.TCPEndpointType.value, sizeRequested); + } } } } diff --git a/cs/src/Ice/ProtocolInstance.cs b/cs/src/Ice/ProtocolInstance.cs index ca7c3b4824a..68c8d33e13f 100644 --- a/cs/src/Ice/ProtocolInstance.cs +++ b/cs/src/Ice/ProtocolInstance.cs @@ -121,6 +121,21 @@ namespace IceInternal } #endif + public BufSizeWarnInfo getBufSizeWarn(short type) + { + return instance_.getBufSizeWarn(type); + } + + public void setSndBufSizeWarn(short type, int size) + { + instance_.setSndBufSizeWarn(type, size); + } + + public void setRcvBufSizeWarn(short type, int size) + { + instance_.setRcvBufSizeWarn(type, size); + } + protected Instance instance_; protected int traceLevel_; protected string traceCategory_; diff --git a/cs/src/Ice/StreamSocket.cs b/cs/src/Ice/StreamSocket.cs index c820f900d38..b6f75545222 100644 --- a/cs/src/Ice/StreamSocket.cs +++ b/cs/src/Ice/StreamSocket.cs @@ -558,7 +558,7 @@ namespace IceInternal #if !SILVERLIGHT Network.setBlock(_fd, false); #endif - Network.setTcpBufSize(_fd, instance.properties(), instance.logger()); + Network.setTcpBufSize(_fd, instance); #if ICE_SOCKET_ASYNC_API _readEventArgs = new SocketAsyncEventArgs(); diff --git a/cs/src/Ice/TcpAcceptor.cs b/cs/src/Ice/TcpAcceptor.cs index 062f89b21d5..d896d4367df 100644 --- a/cs/src/Ice/TcpAcceptor.cs +++ b/cs/src/Ice/TcpAcceptor.cs @@ -137,7 +137,7 @@ namespace IceInternal _fd = Network.createServerSocket(false, _addr.AddressFamily, protocol); Network.setBlock(_fd, false); # if !COMPACT - Network.setTcpBufSize(_fd, _instance.properties(), _instance.logger()); + Network.setTcpBufSize(_fd, _instance); # endif if(AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows) { diff --git a/cs/src/Ice/UdpTransceiver.cs b/cs/src/Ice/UdpTransceiver.cs index 68ff87944c5..167794ac963 100644 --- a/cs/src/Ice/UdpTransceiver.cs +++ b/cs/src/Ice/UdpTransceiver.cs @@ -856,7 +856,7 @@ namespace IceInternal try { _fd = Network.createSocket(true, _addr.AddressFamily); - setBufSize(instance.properties()); + setBufSize(); #if !SILVERLIGHT Network.setBlock(_fd, false); if(AssemblyUtil.osx_) @@ -912,7 +912,7 @@ namespace IceInternal #endif _fd = Network.createServerSocket(true, _addr.AddressFamily, instance.protocolSupport()); - setBufSize(instance.properties()); + setBufSize(); #if !SILVERLIGHT Network.setBlock(_fd, false); #endif @@ -934,17 +934,19 @@ namespace IceInternal } } - private void setBufSize(Ice.Properties properties) + private void setBufSize() { Debug.Assert(_fd != null); for (int i = 0; i < 2; ++i) { + bool isSnd; string direction; string prop; int dfltSize; if(i == 0) { + isSnd = false; direction = "receive"; prop = "Ice.UDP.RcvSize"; dfltSize = Network.getRecvBufferSize(_fd); @@ -952,6 +954,7 @@ namespace IceInternal } else { + isSnd = true; direction = "send"; prop = "Ice.UDP.SndSize"; dfltSize = Network.getSendBufferSize(_fd); @@ -961,7 +964,7 @@ namespace IceInternal // // 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 + IceInternal.Protocol.headerSize)) { _instance.logger().warning("Invalid " + prop + " value of " + sizeRequested + " adjusted to " + @@ -991,12 +994,27 @@ namespace IceInternal } // - // 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(sizeSet < sizeRequested) { - _instance.logger().warning("UDP " + direction + " buffer size: requested size of " + - sizeRequested + " adjusted to " + sizeSet); + BufSizeWarnInfo winfo = _instance.getBufSizeWarn(Ice.UDPEndpointType.value); + if((isSnd && (!winfo.sndWarn || winfo.sndSize != sizeRequested)) || + (!isSnd && (!winfo.rcvWarn || winfo.rcvSize != sizeRequested))) + { + _instance.logger().warning("UDP " + direction + " buffer size: requested size of " + + sizeRequested + " adjusted to " + sizeSet); + + if(isSnd) + { + _instance.setSndBufSizeWarn(Ice.UDPEndpointType.value, sizeRequested); + } + else + { + _instance.setRcvBufSizeWarn(Ice.UDPEndpointType.value, sizeRequested); + } + } } } } diff --git a/cs/src/IceSSL/AcceptorI.cs b/cs/src/IceSSL/AcceptorI.cs index 7391bf9f37e..5ddc84ff337 100644 --- a/cs/src/IceSSL/AcceptorI.cs +++ b/cs/src/IceSSL/AcceptorI.cs @@ -162,7 +162,7 @@ namespace IceSSL IPEndPoint; _fd = IceInternal.Network.createServerSocket(false, _addr.AddressFamily, protocol); IceInternal.Network.setBlock(_fd, false); - IceInternal.Network.setTcpBufSize(_fd, _instance.properties(), _instance.logger()); + IceInternal.Network.setTcpBufSize(_fd, _instance); if(IceInternal.AssemblyUtil.platform_ != IceInternal.AssemblyUtil.Platform.Windows) { // diff --git a/java/src/Ice/src/main/java/IceInternal/BufSizeWarnInfo.java b/java/src/Ice/src/main/java/IceInternal/BufSizeWarnInfo.java new file mode 100644 index 00000000000..4b85092a71c --- /dev/null +++ b/java/src/Ice/src/main/java/IceInternal/BufSizeWarnInfo.java @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceInternal; + +class BufSizeWarnInfo +{ + // Whether send size warning has been emitted + public boolean sndWarn; + + // The send size for which the warning wwas emitted + public int sndSize; + + // Whether receive size warning has been emitted + public boolean rcvWarn; + + // The receive size for which the warning wwas emitted + public int rcvSize; +} diff --git a/java/src/Ice/src/main/java/IceInternal/Instance.java b/java/src/Ice/src/main/java/IceInternal/Instance.java index a28e914844c..30698fc060d 100644 --- a/java/src/Ice/src/main/java/IceInternal/Instance.java +++ b/java/src/Ice/src/main/java/IceInternal/Instance.java @@ -1471,6 +1471,50 @@ public final class Instance } } + public BufSizeWarnInfo getBufSizeWarn(short type) + { + synchronized(_setBufSizeWarn) + { + BufSizeWarnInfo info; + if(!_setBufSizeWarn.containsKey(type)) + { + info = new BufSizeWarnInfo(); + info.sndWarn = false; + info.sndSize = -1; + info.rcvWarn = false; + info.rcvSize = -1; + _setBufSizeWarn.put(type, info); + } + else + { + info = _setBufSizeWarn.get(type); + } + return info; + } + } + + public void setSndBufSizeWarn(short type, int size) + { + synchronized(_setBufSizeWarn) + { + BufSizeWarnInfo info = getBufSizeWarn(type); + info.sndWarn = true; + info.sndSize = size; + _setBufSizeWarn.put(type, info); + } + } + + public void setRcvBufSizeWarn(short type, int size) + { + synchronized(_setBufSizeWarn) + { + BufSizeWarnInfo info = getBufSizeWarn(type); + info.rcvWarn = true; + info.rcvSize = size; + _setBufSizeWarn.put(type, info); + } + } + private void updateConnectionObservers() { @@ -1698,6 +1742,7 @@ public final class Instance private java.util.Map<String, Ice.Object> _adminFacets = new java.util.HashMap<String, Ice.Object>(); private java.util.Set<String> _adminFacetFilter = new java.util.HashSet<String>(); private Ice.Identity _adminIdentity; + private java.util.Map<Short, BufSizeWarnInfo> _setBufSizeWarn = new java.util.HashMap<Short, BufSizeWarnInfo>(); private java.util.Map<String, String> _typeToClassMap = new java.util.HashMap<String, String>(); final private String[] _packages; diff --git a/java/src/Ice/src/main/java/IceInternal/Network.java b/java/src/Ice/src/main/java/IceInternal/Network.java index ae551e30a1a..f2e521af2dd 100644 --- a/java/src/Ice/src/main/java/IceInternal/Network.java +++ b/java/src/Ice/src/main/java/IceInternal/Network.java @@ -117,7 +117,7 @@ public final class Network return false; } - public static boolean + public static boolean isIPv6Supported() { try @@ -797,7 +797,7 @@ public final class Network } public static java.util.List<java.net.InetSocketAddress> - getAddresses(String host, int port, int protocol, Ice.EndpointSelectionType selType, boolean preferIPv6, + getAddresses(String host, int port, int protocol, Ice.EndpointSelectionType selType, boolean preferIPv6, boolean blocking) { if(!blocking) @@ -988,7 +988,7 @@ public final class Network } public static void - setTcpBufSize(java.nio.channels.SocketChannel socket, Ice.Properties properties, Ice.Logger logger) + setTcpBufSize(java.nio.channels.SocketChannel socket, ProtocolInstance instance) { // // By default, on Windows we use a 128KB buffer size. On Unix @@ -1000,7 +1000,9 @@ public final class Network dfltBufSize = 128 * 1024; } - int sizeRequested = properties.getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); + System.err.println("XXX"); + + int sizeRequested = instance.properties().getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1010,13 +1012,21 @@ public final class Network // setRecvBufferSize(socket, sizeRequested); int size = getRecvBufferSize(socket); - if(size < sizeRequested) // Warn if the size that was set is less than the requested size. + //if(size < sizeRequested) { - logger.warning("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(Ice.TCPEndpointType.value); + if(!winfo.rcvWarn || sizeRequested != winfo.rcvSize) + { + instance.logger().warning("TCP receive buffer size: requested size of " + sizeRequested + + " adjusted to " + size); + instance.setRcvBufSizeWarn(Ice.TCPEndpointType.value, sizeRequested); + } } } - sizeRequested = properties.getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize); + sizeRequested = instance.properties().getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1026,15 +1036,23 @@ public final class Network // setSendBufferSize(socket, sizeRequested); int size = getSendBufferSize(socket); - if(size < sizeRequested) // Warn if the size that was set is less than the requested size. + //if(size < sizeRequested) { - logger.warning("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(Ice.TCPEndpointType.value); + if(!winfo.sndWarn || sizeRequested != winfo.sndSize) + { + instance.logger().warning("TCP send buffer size: requested size of " + sizeRequested + + " adjusted to " + size); + instance.setSndBufSizeWarn(Ice.TCPEndpointType.value, sizeRequested); + } } } } public static void - setTcpBufSize(java.nio.channels.ServerSocketChannel socket, Ice.Properties properties, Ice.Logger logger) + setTcpBufSize(java.nio.channels.ServerSocketChannel socket, ProtocolInstance instance) { // // By default, on Windows we use a 128KB buffer size. On Unix @@ -1046,10 +1064,12 @@ public final class Network dfltBufSize = 128 * 1024; } + System.err.println("YYY"); + // // Get property for buffer size. // - int sizeRequested = properties.getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); + int sizeRequested = instance.properties().getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize); if(sizeRequested > 0) { // @@ -1059,9 +1079,17 @@ public final class Network // setRecvBufferSize(socket, sizeRequested); int size = getRecvBufferSize(socket); - if(size < sizeRequested) // Warn if the size that was set is less than the requested size. + //if(size < sizeRequested) { - logger.warning("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(Ice.TCPEndpointType.value); + if(!winfo.rcvWarn || sizeRequested != winfo.rcvSize) + { + instance.logger().warning("TCP receive buffer size: requested size of " + sizeRequested + + " adjusted to " + size); + instance.setRcvBufSizeWarn(Ice.TCPEndpointType.value, sizeRequested); + } } } } diff --git a/java/src/Ice/src/main/java/IceInternal/ProtocolInstance.java b/java/src/Ice/src/main/java/IceInternal/ProtocolInstance.java index 195a554892e..b6c133863f1 100644 --- a/java/src/Ice/src/main/java/IceInternal/ProtocolInstance.java +++ b/java/src/Ice/src/main/java/IceInternal/ProtocolInstance.java @@ -104,6 +104,21 @@ public class ProtocolInstance _instance.endpointHostResolver().resolve(host, port, type, endpt, callback); } + public BufSizeWarnInfo getBufSizeWarn(short type) + { + return _instance.getBufSizeWarn(type); + } + + public void setSndBufSizeWarn(short type, int size) + { + _instance.setSndBufSizeWarn(type, size); + } + + public void setRcvBufSizeWarn(short type, int size) + { + _instance.setRcvBufSizeWarn(type, size); + } + ProtocolInstance(Instance instance, short type, String protocol, boolean secure) { _instance = instance; diff --git a/java/src/Ice/src/main/java/IceInternal/StreamSocket.java b/java/src/Ice/src/main/java/IceInternal/StreamSocket.java index 4079519ee48..61b546400b0 100644 --- a/java/src/Ice/src/main/java/IceInternal/StreamSocket.java +++ b/java/src/Ice/src/main/java/IceInternal/StreamSocket.java @@ -12,8 +12,8 @@ package IceInternal; public class StreamSocket { public StreamSocket(ProtocolInstance instance, - NetworkProxy proxy, - java.net.InetSocketAddress addr, + NetworkProxy proxy, + java.net.InetSocketAddress addr, java.net.InetSocketAddress sourceAddr) { _instance = instance; @@ -106,10 +106,10 @@ public class StreamSocket else if(_state == StateProxyConnected) { _proxy.finish(readBuffer, writeBuffer); - + readBuffer.clear(); writeBuffer.clear(); - + _state = StateConnected; } @@ -121,7 +121,7 @@ public class StreamSocket { return _state == StateConnected; } - + public java.nio.channels.SocketChannel fd() { return _fd; @@ -203,8 +203,8 @@ public class StreamSocket } } return read; - } - + } + public int write(java.nio.ByteBuffer buf) { assert(_fd != null); @@ -226,7 +226,7 @@ public class StreamSocket { ret = _fd.write(buf); } - + if(ret == -1) { throw new Ice.ConnectionLostException(); @@ -275,7 +275,7 @@ public class StreamSocket private void init() { Network.setBlock(_fd, false); - Network.setTcpBufSize(_fd, _instance.properties(), _instance.logger()); + Network.setTcpBufSize(_fd, _instance); if(System.getProperty("os.name").startsWith("Windows")) { diff --git a/java/src/Ice/src/main/java/IceInternal/TcpAcceptor.java b/java/src/Ice/src/main/java/IceInternal/TcpAcceptor.java index 7b69f8986ba..493a7b42184 100644 --- a/java/src/Ice/src/main/java/IceInternal/TcpAcceptor.java +++ b/java/src/Ice/src/main/java/IceInternal/TcpAcceptor.java @@ -92,7 +92,7 @@ class TcpAcceptor implements Acceptor { _fd = Network.createTcpServerSocket(); Network.setBlock(_fd, false); - Network.setTcpBufSize(_fd, instance.properties(), _instance.logger()); + Network.setTcpBufSize(_fd, instance); if(!System.getProperty("os.name").startsWith("Windows")) { // diff --git a/java/src/Ice/src/main/java/IceInternal/UdpTransceiver.java b/java/src/Ice/src/main/java/IceInternal/UdpTransceiver.java index cead447dda2..bffbeb3ce82 100644 --- a/java/src/Ice/src/main/java/IceInternal/UdpTransceiver.java +++ b/java/src/Ice/src/main/java/IceInternal/UdpTransceiver.java @@ -356,7 +356,7 @@ final class UdpTransceiver implements Transceiver try { _fd = Network.createUdpSocket(_addr); - setBufSize(instance.properties()); + setBufSize(); Network.setBlock(_fd, false); // // NOTE: setting the multicast interface before performing the @@ -393,7 +393,7 @@ final class UdpTransceiver implements Transceiver { _addr = Network.getAddressForServer(host, port, instance.protocolSupport(), instance.preferIPv6()); _fd = Network.createUdpSocket(_addr); - setBufSize(instance.properties()); + setBufSize(); Network.setBlock(_fd, false); } catch(Ice.LocalException ex) @@ -403,17 +403,19 @@ final class UdpTransceiver implements Transceiver } } - private synchronized void setBufSize(Ice.Properties properties) + private synchronized void setBufSize() { assert(_fd != null); for(int i = 0; i < 2; ++i) { + boolean isSnd; String direction; String prop; int dfltSize; if(i == 0) { + isSnd = false; direction = "receive"; prop = "Ice.UDP.RcvSize"; dfltSize = Network.getRecvBufferSize(_fd); @@ -421,6 +423,7 @@ final class UdpTransceiver implements Transceiver } else { + isSnd = true; direction = "send"; prop = "Ice.UDP.SndSize"; dfltSize = Network.getSendBufferSize(_fd); @@ -430,7 +433,7 @@ final class UdpTransceiver implements Transceiver // // 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 + IceInternal.Protocol.headerSize)) { _instance.logger().warning("Invalid " + prop + " value of " + sizeRequested + " adjusted to " + @@ -460,12 +463,27 @@ final class UdpTransceiver implements Transceiver } // - // 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(sizeSet < sizeRequested) { - _instance.logger().warning("UDP " + direction + " buffer size: requested size of " - + sizeRequested + " adjusted to " + sizeSet); + BufSizeWarnInfo winfo = _instance.getBufSizeWarn(Ice.UDPEndpointType.value); + if((isSnd && (!winfo.sndWarn || winfo.sndSize != sizeRequested)) || + (!isSnd && (!winfo.rcvWarn || winfo.rcvSize != sizeRequested))) + { + _instance.logger().warning("UDP " + direction + " buffer size: requested size of " + + sizeRequested + " adjusted to " + sizeSet); + + if(isSnd) + { + _instance.setSndBufSizeWarn(Ice.UDPEndpointType.value, sizeRequested); + } + else + { + _instance.setRcvBufSizeWarn(Ice.UDPEndpointType.value, sizeRequested); + } + } } } } diff --git a/java/src/Ice/src/main/java/IceSSL/AcceptorI.java b/java/src/Ice/src/main/java/IceSSL/AcceptorI.java index 55be3f583c6..ce158e9c872 100644 --- a/java/src/Ice/src/main/java/IceSSL/AcceptorI.java +++ b/java/src/Ice/src/main/java/IceSSL/AcceptorI.java @@ -115,7 +115,7 @@ final class AcceptorI implements IceInternal.Acceptor { _fd = IceInternal.Network.createTcpServerSocket(); IceInternal.Network.setBlock(_fd, false); - IceInternal.Network.setTcpBufSize(_fd, _instance.properties(), _instance.logger()); + IceInternal.Network.setTcpBufSize(_fd, _instance); if(!System.getProperty("os.name").startsWith("Windows")) { // |