summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Ice/ConnectionI.cpp67
-rw-r--r--cpp/src/Ice/ConnectionI.h1
-rw-r--r--cpp/test/Ice/adapterDeactivation/AllTests.cpp13
-rw-r--r--cpp/test/Ice/adapterDeactivation/TestI.cpp2
4 files changed, 49 insertions, 34 deletions
diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp
index 1e651481a64..4cbe952c43e 100644
--- a/cpp/src/Ice/ConnectionI.cpp
+++ b/cpp/src/Ice/ConnectionI.cpp
@@ -1604,24 +1604,17 @@ ConnectionI::dispatch(const StartCallbackPtr& startCB, const vector<OutgoingAsyn
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(--_dispatchCount == 0)
{
- if(_state == StateClosing)
+ //
+ // Only initiate shutdown if not already done. It might
+ // have already been done if the sent callback or AMI
+ // callback was dispatched when the connection was already
+ // in the closing state.
+ //
+ if(_state == StateClosing && !_shutdownInitiated)
{
- //
- // Only initiate shutdown if not already done. It
- // might have already been done if the sent callback
- // or AMI callback was dispatched when the connection
- // was already in the closing state.
- //
try
{
- if(!_shutdownInitiated)
- {
- initiateShutdown();
- }
- else
- {
- setState(StateClosed);
- }
+ initiateShutdown();
}
catch(const LocalException& ex)
{
@@ -1901,7 +1894,8 @@ Ice::ConnectionI::ConnectionI(const CommunicatorPtr& communicator,
_writeStream(_instance.get(), Ice::currentProtocolEncoding),
_dispatchCount(0),
_state(StateNotInitialized),
- _shutdownInitiated(false)
+ _shutdownInitiated(false),
+ _validated(false)
{
int& compressionLevel = const_cast<int&>(_compressionLevel);
compressionLevel = _instance->initializationData().properties->getPropertyAsIntWithDefault(
@@ -1991,27 +1985,24 @@ Ice::ConnectionI::setState(State state, const LocalException& ex)
assert(_state != StateClosed);
_exception.reset(ex.ice_clone());
-
- if(_warn)
+
+ //
+ // We don't warn if we are not validated.
+ //
+ if(_warn && _validated)
{
//
- // We don't warn if we are not validated.
+ // Don't warn about certain expected exceptions.
//
- if(_state > StateNotValidated)
+ if(!(dynamic_cast<const CloseConnectionException*>(_exception.get()) ||
+ dynamic_cast<const ForcedCloseConnectionException*>(_exception.get()) ||
+ dynamic_cast<const ConnectionTimeoutException*>(_exception.get()) ||
+ dynamic_cast<const CommunicatorDestroyedException*>(_exception.get()) ||
+ dynamic_cast<const ObjectAdapterDeactivatedException*>(_exception.get()) ||
+ (dynamic_cast<const ConnectionLostException*>(_exception.get()) && _state == StateClosing)))
{
- //
- // Don't warn about certain expected exceptions.
- //
- if(!(dynamic_cast<const CloseConnectionException*>(_exception.get()) ||
- dynamic_cast<const ForcedCloseConnectionException*>(_exception.get()) ||
- dynamic_cast<const ConnectionTimeoutException*>(_exception.get()) ||
- dynamic_cast<const CommunicatorDestroyedException*>(_exception.get()) ||
- dynamic_cast<const ObjectAdapterDeactivatedException*>(_exception.get()) ||
- (dynamic_cast<const ConnectionLostException*>(_exception.get()) && _state == StateClosing)))
- {
- Warning out(_logger);
- out << "connection exception:\n" << *_exception.get() << '\n' << _desc;
- }
+ Warning out(_logger);
+ out << "connection exception:\n" << *_exception.get() << '\n' << _desc;
}
}
}
@@ -2371,6 +2362,8 @@ Ice::ConnectionI::validate(SocketOperation operation)
throw IllegalMessageSizeException(__FILE__, __LINE__);
}
traceRecv(_readStream, _logger, _traceLevels);
+
+ _validated = true;
}
}
@@ -2831,6 +2824,14 @@ Ice::ConnectionI::parseMessage(BasicStream& stream, Int& invokeNum, Int& request
assert(stream.i == stream.b.end());
+ //
+ // Connection is validated on first message. This is only used by
+ // setState() to check wether or not we can print a connection
+ // warning (a client might close the connection forcefully if the
+ // connection isn't validated).
+ //
+ _validated = true;
+
try
{
//
diff --git a/cpp/src/Ice/ConnectionI.h b/cpp/src/Ice/ConnectionI.h
index 8ffe6d9d913..ca5f0cae263 100644
--- a/cpp/src/Ice/ConnectionI.h
+++ b/cpp/src/Ice/ConnectionI.h
@@ -368,6 +368,7 @@ private:
State _state; // The current state.
bool _shutdownInitiated;
+ bool _validated;
};
}
diff --git a/cpp/test/Ice/adapterDeactivation/AllTests.cpp b/cpp/test/Ice/adapterDeactivation/AllTests.cpp
index b334412bd08..3e1856eb542 100644
--- a/cpp/test/Ice/adapterDeactivation/AllTests.cpp
+++ b/cpp/test/Ice/adapterDeactivation/AllTests.cpp
@@ -55,6 +55,19 @@ allTests(const CommunicatorPtr& communicator)
obj->transient();
cout << "ok" << endl;
+ {
+ cout << "testing connection closure... " << flush;
+ for(int i = 0; i < 10; ++i)
+ {
+ Ice::InitializationData initData;
+ initData.properties = communicator->getProperties()->clone();
+ Ice::CommunicatorPtr comm = Ice::initialize(initData);
+ comm->stringToProxy("test:default -p 12010")->begin_ice_ping();
+ comm->destroy();
+ }
+ cout << "ok" << endl;
+ }
+
cout << "deactivating object adapter in the server... " << flush;
obj->deactivate();
cout << "ok" << endl;
diff --git a/cpp/test/Ice/adapterDeactivation/TestI.cpp b/cpp/test/Ice/adapterDeactivation/TestI.cpp
index cc5f8631d91..dd413206160 100644
--- a/cpp/test/Ice/adapterDeactivation/TestI.cpp
+++ b/cpp/test/Ice/adapterDeactivation/TestI.cpp
@@ -29,7 +29,7 @@ void
TestI::deactivate(const Current& current)
{
current.adapter->deactivate();
- IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
+ IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(100));
}
string