summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2003-07-30 03:09:01 +0000
committerMichi Henning <michi@zeroc.com>2003-07-30 03:09:01 +0000
commit61924a00ce03e089df17fbecba1e11815bec32d9 (patch)
tree2f423907f83c50da173eeaa850ef31e056beacb2 /cpp/src
parentgcc fixes for Win32 changes (diff)
downloadice-61924a00ce03e089df17fbecba1e11815bec32d9.tar.bz2
ice-61924a00ce03e089df17fbecba1e11815bec32d9.tar.xz
ice-61924a00ce03e089df17fbecba1e11815bec32d9.zip
Updated receiving side for DatagramLimitException. Test is now done in
ThreadPool, as it should have been all along.
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Connection.cpp26
-rw-r--r--cpp/src/Ice/Connection.h3
-rw-r--r--cpp/src/Ice/ConnectionFactory.cpp6
-rw-r--r--cpp/src/Ice/ConnectionFactory.h1
-rw-r--r--cpp/src/Ice/EventHandler.h5
-rw-r--r--cpp/src/Ice/Exception.cpp2
-rw-r--r--cpp/src/Ice/TcpTransceiver.cpp15
-rw-r--r--cpp/src/Ice/TcpTransceiver.h3
-rw-r--r--cpp/src/Ice/ThreadPool.cpp21
-rw-r--r--cpp/src/Ice/ThreadPool.h2
-rw-r--r--cpp/src/Ice/Transceiver.h2
-rw-r--r--cpp/src/Ice/UdpTransceiver.cpp48
-rw-r--r--cpp/src/Ice/UdpTransceiver.h4
-rw-r--r--cpp/src/IceSSL/SslTransceiver.cpp29
-rw-r--r--cpp/src/IceSSL/SslTransceiver.h3
15 files changed, 63 insertions, 107 deletions
diff --git a/cpp/src/Ice/Connection.cpp b/cpp/src/Ice/Connection.cpp
index c9970afbcc9..264fb7fffff 100644
--- a/cpp/src/Ice/Connection.cpp
+++ b/cpp/src/Ice/Connection.cpp
@@ -906,6 +906,12 @@ IceInternal::Connection::getAdapter() const
}
bool
+IceInternal::Connection::datagram() const
+{
+ return _endpoint->datagram();
+}
+
+bool
IceInternal::Connection::readable() const
{
return true;
@@ -1020,23 +1026,6 @@ IceInternal::Connection::message(BasicStream& stream, const ThreadPoolPtr& threa
stream.b.swap(ustream.b);
}
- if(_endpoint->datagram())
- {
- Int messageSize;
- stream.read(messageSize);
- if(messageSize > _maxRecvSize) // Truncated datagram
- {
- DatagramLimitException ex(__FILE__, __LINE__);
- ex.maxSize = _maxRecvSize;
- if(_warnUdp)
- {
- Warning out(_logger);
- out << "datagram exception:\n" << ex << '\n' << _transceiver->toString();
- }
- throw ex;
- }
- }
-
stream.i = stream.b.begin() + headerSize;
switch(messageType)
@@ -1344,8 +1333,7 @@ IceInternal::Connection::Connection(const InstancePtr& instance,
_batchRequestNum(0),
_dispatchCount(0),
_proxyCount(0),
- _state(StateNotValidated),
- _maxRecvSize(transceiver->maxRecvSize())
+ _state(StateNotValidated)
{
if(_adapter)
{
diff --git a/cpp/src/Ice/Connection.h b/cpp/src/Ice/Connection.h
index 4345fda3361..bf3061c3fea 100644
--- a/cpp/src/Ice/Connection.h
+++ b/cpp/src/Ice/Connection.h
@@ -89,6 +89,7 @@ public:
//
// Operations from EventHandler
//
+ virtual bool datagram() const;
virtual bool readable() const;
virtual void read(BasicStream&);
virtual void message(BasicStream&, const ThreadPoolPtr&);
@@ -168,8 +169,6 @@ private:
int _proxyCount; // The number of proxies using this connection.
State _state;
-
- int _maxRecvSize;
};
}
diff --git a/cpp/src/Ice/ConnectionFactory.cpp b/cpp/src/Ice/ConnectionFactory.cpp
index 11554df23af..6661b7322b2 100644
--- a/cpp/src/Ice/ConnectionFactory.cpp
+++ b/cpp/src/Ice/ConnectionFactory.cpp
@@ -494,6 +494,12 @@ IceInternal::IncomingConnectionFactory::connections() const
}
bool
+IceInternal::IncomingConnectionFactory::datagram() const
+{
+ return _endpoint->datagram();
+}
+
+bool
IceInternal::IncomingConnectionFactory::readable() const
{
return false;
diff --git a/cpp/src/Ice/ConnectionFactory.h b/cpp/src/Ice/ConnectionFactory.h
index 42d46756d13..1f0cfb9ea2f 100644
--- a/cpp/src/Ice/ConnectionFactory.h
+++ b/cpp/src/Ice/ConnectionFactory.h
@@ -82,6 +82,7 @@ public:
//
// Operations from EventHandler
//
+ virtual bool datagram() const;
virtual bool readable() const;
virtual void read(BasicStream&);
virtual void message(BasicStream&, const ThreadPoolPtr&);
diff --git a/cpp/src/Ice/EventHandler.h b/cpp/src/Ice/EventHandler.h
index 7b225b97696..99b9337b38f 100644
--- a/cpp/src/Ice/EventHandler.h
+++ b/cpp/src/Ice/EventHandler.h
@@ -36,6 +36,11 @@ class EventHandler : public ::IceUtil::Shared
public:
//
+ // Return true if the handler is for a datagram transport, false otherwise.
+ //
+ virtual bool datagram() const = 0;
+
+ //
// Return true if read() must be called before calling message().
//
virtual bool readable() const = 0;
diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp
index 77f3974bdd2..ab4f2616e64 100644
--- a/cpp/src/Ice/Exception.cpp
+++ b/cpp/src/Ice/Exception.cpp
@@ -385,7 +385,7 @@ void
Ice::DatagramLimitException::ice_print(ostream& out) const
{
Exception::ice_print(out);
- out << ":\nprotocol error: maximum datagram payload size of " << maxSize << " bytes exceeded";
+ out << ":\nprotocol error: maximum datagram payload size exceeded";
}
void
diff --git a/cpp/src/Ice/TcpTransceiver.cpp b/cpp/src/Ice/TcpTransceiver.cpp
index c4b529a2e88..e5003c94954 100644
--- a/cpp/src/Ice/TcpTransceiver.cpp
+++ b/cpp/src/Ice/TcpTransceiver.cpp
@@ -283,25 +283,12 @@ IceInternal::TcpTransceiver::toString() const
return _desc;
}
-int
-IceInternal::TcpTransceiver::maxRecvSize() const
-{
- return _maxSize;
-}
-
-int
-IceInternal::TcpTransceiver::maxSendSize() const
-{
- return _maxSize;
-}
-
IceInternal::TcpTransceiver::TcpTransceiver(const InstancePtr& instance, SOCKET fd) :
_traceLevels(instance->traceLevels()),
_logger(instance->logger()),
_stats(instance->stats()),
_name("tcp"),
- _fd(fd),
- _maxSize(instance->messageSizeMax())
+ _fd(fd)
{
FD_ZERO(&_rFdSet);
FD_ZERO(&_wFdSet);
diff --git a/cpp/src/Ice/TcpTransceiver.h b/cpp/src/Ice/TcpTransceiver.h
index fb6e488283a..3b4e22e934d 100644
--- a/cpp/src/Ice/TcpTransceiver.h
+++ b/cpp/src/Ice/TcpTransceiver.h
@@ -37,8 +37,6 @@ public:
virtual void write(Buffer&, int);
virtual void read(Buffer&, int);
virtual std::string toString() const;
- virtual int maxRecvSize() const;
- virtual int maxSendSize() const;
private:
@@ -56,7 +54,6 @@ private:
SOCKET _fd;
fd_set _rFdSet;
fd_set _wFdSet;
- int _maxSize;
};
}
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp
index f14a4986fa4..22882fd21a4 100644
--- a/cpp/src/Ice/ThreadPool.cpp
+++ b/cpp/src/Ice/ThreadPool.cpp
@@ -42,7 +42,8 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& p
_messageSizeMax(0),
_running(0),
_inUse(0),
- _load(0)
+ _load(0),
+ _warnUdp(_instance->properties()->getPropertyAsInt("Ice.Warn.Datagrams") > 0)
{
SOCKET fds[2];
createPipe(fds);
@@ -702,8 +703,22 @@ IceInternal::ThreadPool::read(const EventHandlerPtr& handler)
if(stream.i != stream.b.end())
{
- handler->read(stream);
- assert(stream.i == stream.b.end());
+ if(handler->datagram())
+ {
+ if(_warnUdp)
+ {
+ Warning out(_instance->logger());
+ out << "DatagramLimitException: maximum size of " << pos << " exceeded";
+ stream.resize(0);
+ stream.i = stream.b.begin();
+ }
+ throw DatagramLimitException(__FILE__, __LINE__);
+ }
+ else
+ {
+ handler->read(stream);
+ assert(stream.i == stream.b.end());
+ }
}
}
diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h
index c5a79409bdc..3b22c508400 100644
--- a/cpp/src/Ice/ThreadPool.h
+++ b/cpp/src/Ice/ThreadPool.h
@@ -100,6 +100,8 @@ private:
int _inUse; // Number of threads that are currently in use.
double _load; // Current load in number of threads.
+ bool _warnUdp;
+
IceUtil::Mutex _promoteMutex;
};
diff --git a/cpp/src/Ice/Transceiver.h b/cpp/src/Ice/Transceiver.h
index d9ea8415a27..b5cd431fdae 100644
--- a/cpp/src/Ice/Transceiver.h
+++ b/cpp/src/Ice/Transceiver.h
@@ -39,8 +39,6 @@ public:
virtual void write(Buffer&, int) = 0;
virtual void read(Buffer&, int) = 0;
virtual std::string toString() const = 0;
- virtual int maxRecvSize() const = 0;
- virtual int maxSendSize() const = 0;
};
}
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp
index 468f8da6cfa..9e7af7bc5ad 100644
--- a/cpp/src/Ice/UdpTransceiver.cpp
+++ b/cpp/src/Ice/UdpTransceiver.cpp
@@ -59,9 +59,10 @@ IceInternal::UdpTransceiver::write(Buffer& buf, int)
const int packetSize = min(_maxPacketSize, _sndSize - _udpOverhead);
if(packetSize < static_cast<int>(buf.b.size()))
{
- Ice::DatagramLimitException ex(__FILE__, __LINE__);
- ex.maxSize = packetSize;
- throw ex;
+ //
+ // We don't log a warning here because the client gets an exception anyway.
+ //
+ throw Ice::DatagramLimitException(__FILE__, __LINE__);
}
repeat:
@@ -127,9 +128,16 @@ IceInternal::UdpTransceiver::read(Buffer& buf, int)
const int packetSize = min(_maxPacketSize, _rcvSize - _udpOverhead);
if(packetSize < static_cast<int>(buf.b.size()))
{
- Ice::DatagramLimitException ex(__FILE__, __LINE__);
- ex.maxSize = packetSize;
- throw ex;
+ //
+ // We log a warning here because this is the server side -- without the
+ // the warning, there would only be silence.
+ //
+ if(_warn)
+ {
+ Warning out(_logger);
+ out << "DatagramLimitException: maximum size of " << packetSize << " exceeded";
+ }
+ throw Ice::DatagramLimitException(__FILE__, __LINE__);
}
buf.b.resize(packetSize);
buf.i = buf.b.begin();
@@ -200,11 +208,10 @@ repeat:
if(recvTruncated())
{
DatagramLimitException ex(__FILE__, __LINE__);
- ex.maxSize = packetSize;
if(_warn)
{
Warning out(_logger);
- out << "datagram exception:\n" << ex << '\n' << toString();
+ out << "DatagramLimitException: maximum size of " << packetSize << " exceeded";
}
throw ex;
@@ -236,18 +243,6 @@ IceInternal::UdpTransceiver::toString() const
return fdToString(_fd);
}
-int
-IceInternal::UdpTransceiver::maxRecvSize() const
-{
- return _rcvSize;
-}
-
-int
-IceInternal::UdpTransceiver::maxSendSize() const
-{
- return _sndSize;
-}
-
bool
IceInternal::UdpTransceiver::equivalent(const string& host, int port) const
{
@@ -299,7 +294,8 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
_stats(instance->stats()),
_name("udp"),
_incoming(true),
- _connect(connect)
+ _connect(connect),
+ _warn(instance->properties()->getPropertyAsInt("Ice.Warn.Datagrams") > 0)
{
try
{
@@ -344,8 +340,6 @@ IceInternal::UdpTransceiver::setBufSize(const InstancePtr& instance)
{
assert(_fd != INVALID_SOCKET);
- _warn = instance->properties()->getPropertyAsInt("Ice.Warn.Datagrams") > 0;
-
for(int i = 0; i < 2; ++i)
{
string direction;
@@ -358,6 +352,7 @@ IceInternal::UdpTransceiver::setBufSize(const InstancePtr& instance)
prop = "Ice.UDP.RcvSize";
addr = &_rcvSize;
dfltSize = getRecvBufferSize(_fd);
+ _rcvSize = dfltSize;
}
else
{
@@ -365,6 +360,7 @@ IceInternal::UdpTransceiver::setBufSize(const InstancePtr& instance)
prop = "Ice.UDP.SndSize";
addr = &_sndSize;
dfltSize = getSendBufferSize(_fd);
+ _sndSize = dfltSize;
}
//
@@ -386,7 +382,7 @@ IceInternal::UdpTransceiver::setBufSize(const InstancePtr& instance)
{
Warning out(_logger);
out << "UDP " << direction << " buffer size: requested size of " << sizeRequested << " adjusted to ";
- sizeRequested = min(messageSizeMax + _udpOverhead, static_cast<size_t>(_maxPacketSize) + _udpOverhead);
+ sizeRequested = min(messageSizeMax, static_cast<size_t>(_maxPacketSize)) + _udpOverhead;
out << sizeRequested << " (Ice.MessageSizeMax takes precendence)";
}
@@ -418,10 +414,6 @@ IceInternal::UdpTransceiver::setBufSize(const InstancePtr& instance)
<< sizeRequested << " adjusted to " << *addr;
}
}
- else
- {
- *addr = dfltSize;
- }
}
}
diff --git a/cpp/src/Ice/UdpTransceiver.h b/cpp/src/Ice/UdpTransceiver.h
index 1b961860230..852eed16990 100644
--- a/cpp/src/Ice/UdpTransceiver.h
+++ b/cpp/src/Ice/UdpTransceiver.h
@@ -42,8 +42,6 @@ public:
virtual void write(Buffer&, int);
virtual void read(Buffer&, int);
virtual std::string toString() const;
- virtual int maxRecvSize() const;
- virtual int maxSendSize() const;
bool equivalent(const std::string&, int) const;
int effectivePort() const;
@@ -71,9 +69,9 @@ private:
bool _connect;
int _rcvSize;
int _sndSize;
+ bool _warn;
static const int _udpOverhead;
static const int _maxPacketSize;
- bool _warn;
};
}
diff --git a/cpp/src/IceSSL/SslTransceiver.cpp b/cpp/src/IceSSL/SslTransceiver.cpp
index 93fdfda5ec0..164c642aec6 100644
--- a/cpp/src/IceSSL/SslTransceiver.cpp
+++ b/cpp/src/IceSSL/SslTransceiver.cpp
@@ -276,17 +276,6 @@ IceSSL::SslTransceiver::toString() const
return _desc;
}
-int
-IceSSL::SslTransceiver::maxRecvSize() const
-{
- return _messageSizeMax;
-}
-
-int
-IceSSL::SslTransceiver::maxSendSize() const
-{
- return _messageSizeMax;
-}
void
IceSSL::SslTransceiver::forceHandshake()
{
@@ -1033,24 +1022,6 @@ IceSSL::SslTransceiver::SslTransceiver(const OpenSSLPluginIPtr& plugin,
// fdToString may raise a socket exception.
//
const_cast<string&>(_desc) = fdToString(_fd);
-
- //
- // Initialize max message size.
- //
- static const int defaultMessageSizeMax = 1024;
- Int num = plugin->getProperties()->getPropertyAsIntWithDefault("Ice.MessageSizeMax", defaultMessageSizeMax);
- if(num < 1)
- {
- _messageSizeMax = defaultMessageSizeMax; // Ignore stupid values.
- }
- else if(static_cast<size_t>(num) > (size_t)(0x7fffffff / 1024))
- {
- _messageSizeMax = static_cast<size_t>(0x7fffffff);
- }
- else
- {
- _messageSizeMax = static_cast<size_t>(num) * 1024; // Property is in kilobytes, _messageSizeMax in bytes.
- }
}
IceSSL::SslTransceiver::~SslTransceiver()
diff --git a/cpp/src/IceSSL/SslTransceiver.h b/cpp/src/IceSSL/SslTransceiver.h
index 61945dff90f..582d648587e 100644
--- a/cpp/src/IceSSL/SslTransceiver.h
+++ b/cpp/src/IceSSL/SslTransceiver.h
@@ -138,8 +138,6 @@ public:
virtual void write(IceInternal::Buffer&, int) = 0;
virtual void read(IceInternal::Buffer&, int);
virtual std::string toString() const;
- virtual int maxRecvSize() const;
- virtual int maxSendSize() const;
void forceHandshake();
virtual int handshake(int timeout = 0) = 0;
@@ -218,7 +216,6 @@ protected:
SOCKET _fd;
fd_set _rFdSet;
fd_set _wFdSet;
- int _messageSizeMax;
IceSSL::CertificateVerifierPtr _certificateVerifier;
};