diff options
| author | Gordon Sim <gsim@apache.org> | 2013-09-20 15:43:41 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2013-09-20 15:43:41 +0000 |
| commit | 7da77d485b85a36199de80b88a501e414c1ec4eb (patch) | |
| tree | dc7a82b7a0bb488c7b2630a4688ae13757bd7aa9 /qpid/cpp | |
| parent | abd0ec3213fa84421f6c845113fd129060d3ccda (diff) | |
| download | qpid-python-7da77d485b85a36199de80b88a501e414c1ec4eb.tar.gz | |
QPID-5147: improvements to error handling
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1525041 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
| -rw-r--r-- | qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp | 24 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.h | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp b/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp index f3b03f4c84..dba5cb1e1c 100644 --- a/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp +++ b/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp @@ -264,7 +264,7 @@ void ConnectionContext::attach(boost::shared_ptr<SessionContext> ssn, boost::sha { qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock); lnk->configure(); - attach(lnk->sender); + attach(ssn, lnk->sender); checkClosed(ssn, lnk); lnk->verify(); QPID_LOG(debug, "Attach succeeded to " << lnk->getTarget()); @@ -274,13 +274,13 @@ void ConnectionContext::attach(boost::shared_ptr<SessionContext> ssn, boost::sha { qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock); lnk->configure(); - attach(lnk->receiver, lnk->capacity); + attach(ssn, lnk->receiver, lnk->capacity); checkClosed(ssn, lnk); lnk->verify(); QPID_LOG(debug, "Attach succeeded from " << lnk->getSource()); } -void ConnectionContext::attach(pn_link_t* link, int credit) +void ConnectionContext::attach(boost::shared_ptr<SessionContext> ssn, pn_link_t* link, int credit) { pn_link_open(link); QPID_LOG(debug, "Link attach sent for " << link << ", state=" << pn_link_state(link)); @@ -288,7 +288,7 @@ void ConnectionContext::attach(pn_link_t* link, int credit) wakeupDriver(); while (pn_link_state(link) & PN_REMOTE_UNINIT) { QPID_LOG(debug, "Waiting for confirmation of link attach for " << link << ", state=" << pn_link_state(link) << "..."); - wait(); + wait(ssn); } } @@ -454,8 +454,15 @@ void ConnectionContext::checkClosed(boost::shared_ptr<SessionContext> ssn) { check(); if ((pn_session_state(ssn->session) & REQUIRES_CLOSE) == REQUIRES_CLOSE) { + pn_condition_t* error = pn_session_remote_condition(ssn->session); + std::stringstream text; + if (pn_condition_is_set(error)) { + text << "Session ended by peer with " << pn_condition_get_name(error) << ": " << pn_condition_get_description(error); + } else { + text << "Session ended by peer"; + } pn_session_close(ssn->session); - throw qpid::messaging::SessionError("Session ended by peer"); + throw qpid::messaging::SessionError(text.str()); } else if ((pn_session_state(ssn->session) & IS_CLOSED) == IS_CLOSED) { throw qpid::messaging::SessionError("Session has ended"); } @@ -497,14 +504,14 @@ void ConnectionContext::restartSession(boost::shared_ptr<SessionContext> s) for (SessionContext::SenderMap::iterator i = s->senders.begin(); i != s->senders.end(); ++i) { QPID_LOG(debug, id << " reattaching sender " << i->first); - attach(i->second->sender); + attach(s, i->second->sender); i->second->verify(); QPID_LOG(debug, id << " sender " << i->first << " reattached"); i->second->resend(); } for (SessionContext::ReceiverMap::iterator i = s->receivers.begin(); i != s->receivers.end(); ++i) { QPID_LOG(debug, id << " reattaching receiver " << i->first); - attach(i->second->receiver, i->second->capacity); + attach(s, i->second->receiver, i->second->capacity); i->second->verify(); QPID_LOG(debug, id << " receiver " << i->first << " reattached"); } @@ -767,7 +774,7 @@ void ConnectionContext::open() if (state != DISCONNECTED) throw qpid::messaging::ConnectionError("Connection was already opened!"); if (!driver) driver = DriverImpl::getDefault(); - tryConnect(); + autoconnect(); } @@ -936,6 +943,7 @@ bool ConnectionContext::tryConnect(const qpid::Address& address) } } catch (const std::exception& e) { QPID_LOG(info, id << " Error while connecting: " << e.what()); + state = DISCONNECTED; } transport = boost::shared_ptr<Transport>(); return false; diff --git a/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.h b/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.h index 7387dba13e..2fdba7a3b2 100644 --- a/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.h +++ b/qpid/cpp/src/qpid/messaging/amqp/ConnectionContext.h @@ -147,7 +147,7 @@ class ConnectionContext : public qpid::sys::ConnectionCodec, public qpid::messag void checkClosed(boost::shared_ptr<SessionContext>, boost::shared_ptr<SenderContext>); void checkClosed(boost::shared_ptr<SessionContext>, pn_link_t*); void wakeupDriver(); - void attach(pn_link_t*, int credit=0); + void attach(boost::shared_ptr<SessionContext>, pn_link_t*, int credit=0); void autoconnect(); bool tryConnect(); bool tryConnect(const qpid::Url& url); |
