diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/ConnectionI.cpp | 34 | ||||
-rw-r--r-- | cpp/src/Ice/TcpTransceiver.cpp | 9 | ||||
-rw-r--r-- | cpp/src/Ice/TcpTransceiver.h | 1 | ||||
-rw-r--r-- | cpp/src/Ice/Transceiver.h | 1 | ||||
-rw-r--r-- | cpp/src/Ice/UdpTransceiver.cpp | 40 | ||||
-rw-r--r-- | cpp/src/Ice/UdpTransceiver.h | 1 | ||||
-rw-r--r-- | cpp/src/IceSSL/TransceiverI.cpp | 9 | ||||
-rw-r--r-- | cpp/src/IceSSL/TransceiverI.h | 1 |
8 files changed, 72 insertions, 24 deletions
diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index 2a393793093..d832f87a886 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -883,25 +883,39 @@ Ice::ConnectionI::finishBatchRequest(BasicStream* os, bool compress) // _batchStream.swap(*os); - if(_batchAutoFlush && _batchStream.b.size() > _instance->messageSizeMax()) + if(_batchAutoFlush) { + IceUtil::Mutex::Lock sendSync(_sendMutex); + if(!_transceiver) + { + assert(_exception.get()); + _exception->ice_throw(); // The exception is immutable at this point. + } + // // Throw memory limit exception if the first message added causes us to // go over limit. Otherwise put aside the marshalled message that caused // limit to be exceeded and rollback stream to the marker. // - if(_batchRequestNum == 0) + try { - resetBatch(true); - throw MemoryLimitException(__FILE__, __LINE__); + _transceiver->checkSendSize(_batchStream, _instance->messageSizeMax()); + } + catch(const Ice::Exception&) + { + if(_batchRequestNum == 0) + { + resetBatch(true); + throw; + } + vector<Ice::Byte>(_batchStream.b.begin() + _batchMarker, _batchStream.b.end()).swap(lastRequest); + _batchStream.b.resize(_batchMarker); + autoflush = true; } - - vector<Ice::Byte>(_batchStream.b.begin() + _batchMarker, _batchStream.b.end()).swap(lastRequest); - _batchStream.b.resize(_batchMarker); - autoflush = true; } - else - { + + if(!autoflush) + { // // Increment the number of requests in the batch. // diff --git a/cpp/src/Ice/TcpTransceiver.cpp b/cpp/src/Ice/TcpTransceiver.cpp index fbada343127..4eb5f54fa02 100644 --- a/cpp/src/Ice/TcpTransceiver.cpp +++ b/cpp/src/Ice/TcpTransceiver.cpp @@ -343,6 +343,15 @@ IceInternal::TcpTransceiver::initialize(int) { } +void +IceInternal::TcpTransceiver::checkSendSize(const Buffer& buf, size_t messageSizeMax) +{ + if(buf.b.size() > messageSizeMax) + { + throw MemoryLimitException(__FILE__, __LINE__); + } +} + IceInternal::TcpTransceiver::TcpTransceiver(const InstancePtr& instance, SOCKET fd) : _traceLevels(instance->traceLevels()), _logger(instance->initializationData().logger), diff --git a/cpp/src/Ice/TcpTransceiver.h b/cpp/src/Ice/TcpTransceiver.h index e2d9d301695..a6a7abbdb29 100644 --- a/cpp/src/Ice/TcpTransceiver.h +++ b/cpp/src/Ice/TcpTransceiver.h @@ -35,6 +35,7 @@ public: virtual std::string type() const; virtual std::string toString() const; virtual void initialize(int); + virtual void checkSendSize(const Buffer&, size_t); private: diff --git a/cpp/src/Ice/Transceiver.h b/cpp/src/Ice/Transceiver.h index 0a95324b7de..1e3d637c9f0 100644 --- a/cpp/src/Ice/Transceiver.h +++ b/cpp/src/Ice/Transceiver.h @@ -38,6 +38,7 @@ public: virtual std::string type() const = 0; virtual std::string toString() const = 0; virtual void initialize(int) = 0; + virtual void checkSendSize(const Buffer&, size_t) = 0; }; } diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 62b95f8286f..f7e26883e38 100644 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -109,13 +109,18 @@ void IceInternal::UdpTransceiver::write(Buffer& buf, int) { assert(buf.i == buf.b.begin()); + // + // The maximum packetSize is either the maximum allowable UDP + // packet size, or the UDP send buffer size (which ever is + // smaller). + // const int packetSize = min(_maxPacketSize, _sndSize - _udpOverhead); if(packetSize < static_cast<int>(buf.b.size())) { // // We don't log a warning here because the client gets an exception anyway. // - throw Ice::DatagramLimitException(__FILE__, __LINE__); + throw DatagramLimitException(__FILE__, __LINE__); } repeat: @@ -190,6 +195,11 @@ IceInternal::UdpTransceiver::read(Buffer& buf, int) { assert(buf.i == buf.b.begin()); + // + // The maximum packetSize is either the maximum allowable UDP + // packet size, or the UDP send buffer size (which ever is + // smaller). + // const int packetSize = min(_maxPacketSize, _rcvSize - _udpOverhead); if(packetSize < static_cast<int>(buf.b.size())) { @@ -202,7 +212,7 @@ IceInternal::UdpTransceiver::read(Buffer& buf, int) Warning out(_logger); out << "DatagramLimitException: maximum size of " << packetSize << " exceeded"; } - throw Ice::DatagramLimitException(__FILE__, __LINE__); + throw DatagramLimitException(__FILE__, __LINE__); } buf.b.resize(packetSize); buf.i = buf.b.begin(); @@ -337,6 +347,20 @@ IceInternal::UdpTransceiver::initialize(int) { } +void +IceInternal::UdpTransceiver::checkSendSize(const Buffer& buf, size_t messageSizeMax) +{ + if(buf.b.size() > messageSizeMax) + { + throw MemoryLimitException(__FILE__, __LINE__); + } + const int packetSize = min(_maxPacketSize, _sndSize - _udpOverhead); + if(packetSize < static_cast<int>(buf.b.size())) + { + throw DatagramLimitException(__FILE__, __LINE__); + } +} + bool IceInternal::UdpTransceiver::equivalent(const string& host, int port) const { @@ -475,18 +499,6 @@ IceInternal::UdpTransceiver::setBufSize(const InstancePtr& instance) sizeRequested = dfltSize; } - // - // Ice.MessageSizeMax overrides UDP buffer sizes if Ice.MessageSizeMax + _udpOverhead is less. - // - size_t messageSizeMax = instance->messageSizeMax(); - if(static_cast<size_t>(sizeRequested) > messageSizeMax + _udpOverhead) - { - Warning out(_logger); - out << "UDP " << direction << " buffer size: requested size of " << sizeRequested << " adjusted to "; - sizeRequested = min(static_cast<int>(messageSizeMax), _maxPacketSize) + _udpOverhead; - out << sizeRequested << " (Ice.MessageSizeMax takes precedence)"; - } - if(sizeRequested != dfltSize) { // diff --git a/cpp/src/Ice/UdpTransceiver.h b/cpp/src/Ice/UdpTransceiver.h index 12dc68f32ad..c39bd3f0a19 100644 --- a/cpp/src/Ice/UdpTransceiver.h +++ b/cpp/src/Ice/UdpTransceiver.h @@ -41,6 +41,7 @@ public: virtual std::string type() const; virtual std::string toString() const; virtual void initialize(int); + virtual void checkSendSize(const Buffer&, size_t); bool equivalent(const std::string&, int) const; int effectivePort() const; diff --git a/cpp/src/IceSSL/TransceiverI.cpp b/cpp/src/IceSSL/TransceiverI.cpp index 8ee4211da2b..eaf89fafef6 100644 --- a/cpp/src/IceSSL/TransceiverI.cpp +++ b/cpp/src/IceSSL/TransceiverI.cpp @@ -518,6 +518,15 @@ IceSSL::TransceiverI::initialize(int timeout) } } +void +IceSSL::TransceiverI::checkSendSize(const IceInternal::Buffer& buf, size_t messageSizeMax) +{ + if(buf.b.size() > messageSizeMax) + { + throw MemoryLimitException(__FILE__, __LINE__); + } +} + ConnectionInfo IceSSL::TransceiverI::getConnectionInfo() const { diff --git a/cpp/src/IceSSL/TransceiverI.h b/cpp/src/IceSSL/TransceiverI.h index 7de64ddc05c..46daa6d9570 100644 --- a/cpp/src/IceSSL/TransceiverI.h +++ b/cpp/src/IceSSL/TransceiverI.h @@ -38,6 +38,7 @@ public: virtual std::string type() const; virtual std::string toString() const; virtual void initialize(int); + virtual void checkSendSize(const IceInternal::Buffer&, size_t); ConnectionInfo getConnectionInfo() const; |