本文整理汇总了C++中ice::ConnectionPtr::setCloseCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionPtr::setCloseCallback方法的具体用法?C++ ConnectionPtr::setCloseCallback怎么用?C++ ConnectionPtr::setCloseCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ice::ConnectionPtr
的用法示例。
在下文中一共展示了ConnectionPtr::setCloseCallback方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sync
void
ReapThread::add(const ReapablePtr& reapable, int timeout, const Ice::ConnectionPtr& connection)
{
Lock sync(*this);
if(_terminated)
{
return;
}
//
// NOTE: registering a reapable with a null timeout is allowed. The reapable is reaped
// only when the reaper thread is shutdown.
//
//
// 10 seconds is the minimum permissable timeout.
//
if(timeout > 0 && timeout < 10)
{
timeout = 10;
}
ReapableItem item;
item.item = reapable;
item.connection = connection;
item.timeout = timeout == 0 ? IceUtil::Time() : IceUtil::Time::seconds(timeout);
_sessions.push_back(item);
if(connection)
{
map<Ice::ConnectionPtr, set<ReapablePtr> >::iterator p = _connections.find(connection);
if(p == _connections.end())
{
p = _connections.insert(make_pair(connection, set<ReapablePtr>())).first;
connection->setCloseCallback(_closeCallback);
connection->setHeartbeatCallback(_heartbeatCallback);
}
p->second.insert(reapable);
}
if(timeout > 0)
{
//
// If there is a new minimum wake interval then wake the reaping
// thread.
//
if(calcWakeInterval())
{
notify();
}
//
// Since we just added a new session with a non null timeout there
// must be a non-zero wakeInterval.
//
assert(_wakeInterval != IceUtil::Time());
}
}
示例2: assert
void
SessionHelperI::connected(const Glacier2::RouterPrxPtr& router, const Glacier2::SessionPrxPtr& session)
{
//
// Remote invocation should be done without acquiring a mutex lock.
//
assert(router);
Ice::ConnectionPtr conn = router->ice_getCachedConnection();
string category = router->getCategoryForClient();
Ice::Int acmTimeout = 0;
try
{
acmTimeout = router->getACMTimeout();
}
catch(const Ice::OperationNotExistException&)
{
}
if(acmTimeout <= 0)
{
acmTimeout = static_cast<Ice::Int>(router->getSessionTimeout());
}
//
// We create the callback object adapter here because createObjectAdapter internally
// makes synchronous RPCs to the router. We can't create the OA on-demand when the
// client calls objectAdapter() or addWithUUID() because they can be called from the
// GUI thread.
//
if(_useCallbacks)
{
_adapter = _communicator->createObjectAdapterWithRouter("", router);
_adapter->activate();
}
bool destroy;
{
IceUtil::Mutex::Lock sync(_mutex);
_router = router;
destroy = _destroy;
if(!_destroy)
{
//
// Cache the category.
//
_category = category;
//
// Assign the session after _destroy is checked.
//
_session = session;
_connected = true;
if(acmTimeout > 0)
{
Ice::ConnectionPtr connection = _router->ice_getCachedConnection();
assert(connection);
connection->setACM(acmTimeout, IceUtil::None, Ice::HeartbeatAlways);
#ifdef ICE_CPP11_MAPPING
connection->setCloseCallback([self = shared_from_this()](Ice::ConnectionPtr)
{
self->destroy();
});
#else
connection->setCloseCallback(ICE_MAKE_SHARED(CloseCallbackI, shared_from_this()));
#endif
}
}
}
if(destroy)
{
//
// connected() is only called from the ConnectThread so it is ok to
// call destroyInternal here.
//
destroyInternal(new Disconnected(shared_from_this(), _callback));
}
else
{
dispatchCallback(new Connected(_callback, shared_from_this()), conn);
}
}
示例3: out
bool
Glacier2::Application::doMain(Ice::StringSeq& args, const Ice::InitializationData& initData, int& status, int version)
{
//
// Reset internal state variables from Ice.Application. The
// remainder are reset at the end of this method.
//
_callbackInProgress = false;
_destroyed = false;
_interrupted = false;
bool restart = false;
bool sessionCreated = false;
status = 0;
try
{
_communicator = Ice::initialize(args, initData, version);
_router = ICE_UNCHECKED_CAST(Glacier2::RouterPrx, communicator()->getDefaultRouter());
if(!_router)
{
Error out(getProcessLogger());
out << _appName << ": no glacier2 router configured";
status = 1;
}
else
{
//
// The default is to destroy when a signal is received.
//
if(_signalPolicy == ICE_ENUM(SignalPolicy, HandleSignals))
{
destroyOnInterrupt();
}
// If createSession throws, we're done.
try
{
_session = createSession();
sessionCreated = true;
}
catch(const Ice::LocalException& ex)
{
Error out(getProcessLogger());
out << _appName << ": " << ex;
status = 1;
}
if(sessionCreated)
{
Ice::Int acmTimeout = 0;
try
{
acmTimeout = _router->getACMTimeout();
}
catch(const Ice::OperationNotExistException&)
{
}
if(acmTimeout <= 0)
{
acmTimeout = static_cast<Ice::Int>(_router->getSessionTimeout());
}
if(acmTimeout > 0)
{
Ice::ConnectionPtr connection = _router->ice_getCachedConnection();
assert(connection);
connection->setACM(acmTimeout, IceUtil::None, ICE_ENUM(ACMHeartbeat, HeartbeatAlways));
#ifdef ICE_CPP11_MAPPING
connection->setCloseCallback(
[this](Ice::ConnectionPtr)
{
sessionDestroyed();
});
#else
connection->setCloseCallback(ICE_MAKE_SHARED(CloseCallbackI, this));
#endif
}
_category = _router->getCategoryForClient();
IceInternal::ArgVector a(args);
status = runWithSession(a.argc, a.argv);
}
}
}
// We want to restart on those exceptions which indicate a
// break down in communications, but not those exceptions that
// indicate a programming logic error (ie: marshal, protocol
// failure, etc).
catch(const RestartSessionException&)
{
restart = true;
}
catch(const Ice::ConnectionRefusedException& ex)
{
Error out(getProcessLogger());
out << _appName << ": " << ex;
restart = true;
}
//.........这里部分代码省略.........