From 5269fc0e04984b2d196d5eaf96e206e034d21184 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Fri, 20 Aug 2010 13:58:20 +0000 Subject: QPID-2798 - C++ Messaging Client .NET binding fails to clone managed objects correctly Patch from Chuck Rolke git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@987510 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/bindings/qpid/dotnet/src/Address.cpp | 9 +- cpp/bindings/qpid/dotnet/src/Address.h | 8 +- cpp/bindings/qpid/dotnet/src/Connection.cpp | 39 +----- cpp/bindings/qpid/dotnet/src/Connection.h | 15 +-- cpp/bindings/qpid/dotnet/src/Message.cpp | 6 +- cpp/bindings/qpid/dotnet/src/Message.h | 12 +- cpp/bindings/qpid/dotnet/src/Receiver.cpp | 95 ++++++------- cpp/bindings/qpid/dotnet/src/Receiver.h | 20 ++- cpp/bindings/qpid/dotnet/src/Sender.cpp | 5 +- cpp/bindings/qpid/dotnet/src/Sender.h | 6 +- cpp/bindings/qpid/dotnet/src/Session.cpp | 150 ++++----------------- cpp/bindings/qpid/dotnet/src/Session.h | 9 +- .../dotnet/src/sessionreceiver/sessionreceiver.cs | 6 +- 13 files changed, 132 insertions(+), 248 deletions(-) (limited to 'cpp/bindings/qpid/dotnet/src') diff --git a/cpp/bindings/qpid/dotnet/src/Address.cpp b/cpp/bindings/qpid/dotnet/src/Address.cpp index 2b6dbb4647..6d23136cbd 100644 --- a/cpp/bindings/qpid/dotnet/src/Address.cpp +++ b/cpp/bindings/qpid/dotnet/src/Address.cpp @@ -78,17 +78,16 @@ namespace Messaging { Type = type; } - // Copy constructor + // copy constructor Address::Address(const Address ^ address) : addressp(new ::qpid::messaging::Address( *(const_cast
(address)->NativeAddress))) { } - // Create from received address - // The new Address object consumes the unmanaged pointer - Address::Address(::qpid::messaging::Address * addrp) : - addressp(addrp) + // unmanaged clone + Address::Address(const ::qpid::messaging::Address & addrp) : + addressp(new ::qpid::messaging::Address(addrp)) { } diff --git a/cpp/bindings/qpid/dotnet/src/Address.h b/cpp/bindings/qpid/dotnet/src/Address.h index 1f2c3fe161..11b1e67a04 100644 --- a/cpp/bindings/qpid/dotnet/src/Address.h +++ b/cpp/bindings/qpid/dotnet/src/Address.h @@ -68,9 +68,8 @@ namespace Messaging { // copy constructor Address(const Address ^ address); - // Create from received address - // The new Address object consumes the unmanaged pointer - Address(::qpid::messaging::Address * addrp); + // unmanaged clone + Address(const ::qpid::messaging::Address & addrp); ~Address(); !Address(); @@ -84,7 +83,8 @@ namespace Messaging { } else { - delete addressp; + if (NULL != addressp) + delete addressp; addressp = new ::qpid::messaging::Address( *(const_cast
(rhs).NativeAddress) ); } diff --git a/cpp/bindings/qpid/dotnet/src/Connection.cpp b/cpp/bindings/qpid/dotnet/src/Connection.cpp index 50755302f3..322910d820 100644 --- a/cpp/bindings/qpid/dotnet/src/Connection.cpp +++ b/cpp/bindings/qpid/dotnet/src/Connection.cpp @@ -132,16 +132,13 @@ namespace Messaging { Session ^ Connection::CreateTransactionalSession(System::String ^ name) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Session * sessionp = NULL; Session ^ newSession = nullptr; try { - // allocate native session - sessionp = new ::qpid::messaging::Session ; - // create native session - *sessionp = connectionp->createTransactionalSession(QpidMarshal::ToNative(name)); + ::qpid::messaging::Session sessionp = + connectionp->createTransactionalSession(QpidMarshal::ToNative(name)); // create managed session newSession = gcnew Session(sessionp, this); @@ -160,13 +157,6 @@ namespace Messaging { { delete newSession; } - else - { - if (sessionp != NULL) - { - delete sessionp; - } - } } } @@ -191,16 +181,13 @@ namespace Messaging { Session ^ Connection::CreateSession(System::String ^ name) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Session * sessionp = NULL; Session ^ newSession = nullptr; try { - // allocate native session - sessionp = new ::qpid::messaging::Session ; - // create native session - *sessionp = connectionp->createSession(QpidMarshal::ToNative(name)); + ::qpid::messaging::Session sessionp = + connectionp->createSession(QpidMarshal::ToNative(name)); // create managed session newSession = gcnew Session(sessionp, this); @@ -219,13 +206,6 @@ namespace Messaging { { delete newSession; } - else - { - if (sessionp != NULL) - { - delete sessionp; - } - } } } @@ -241,14 +221,14 @@ namespace Messaging { Session ^ Connection::GetSession(System::String ^ name) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Session * sess = NULL; Session ^ newSession = nullptr; try { const std::string n = QpidMarshal::ToNative(name); - *sess = connectionp->::qpid::messaging::Connection::getSession(n); + ::qpid::messaging::Session sess = + connectionp->::qpid::messaging::Connection::getSession(n); newSession = gcnew Session(sess, this); } @@ -266,13 +246,6 @@ namespace Messaging { { delete newSession; } - else - { - if (sess != NULL) - { - delete sess; - } - } } } diff --git a/cpp/bindings/qpid/dotnet/src/Connection.h b/cpp/bindings/qpid/dotnet/src/Connection.h index 0907d996ab..23d0679fd5 100644 --- a/cpp/bindings/qpid/dotnet/src/Connection.h +++ b/cpp/bindings/qpid/dotnet/src/Connection.h @@ -60,6 +60,9 @@ namespace Messaging { // copy constructor Connection(const Connection ^ connection); + // unmanaged clone + // not defined + ~Connection(); !Connection(); @@ -72,7 +75,8 @@ namespace Messaging { } else { - delete connectionp; + if (NULL != connectionp) + delete connectionp; connectionp = new ::qpid::messaging::Connection( *(const_cast(rhs).NativeConnection) ); } @@ -84,15 +88,6 @@ namespace Messaging { ::qpid::messaging::Connection * get () { return connectionp; } } - property System::String ^ NPAddress - { - System::String ^ get () - { - System::IntPtr i((void *)connectionp); - return gcnew System::String(i.ToString()); - } - } - void SetOption(System::String ^ name, System::Object ^ value); void Open(); diff --git a/cpp/bindings/qpid/dotnet/src/Message.cpp b/cpp/bindings/qpid/dotnet/src/Message.cpp index def3051d75..139ecee165 100644 --- a/cpp/bindings/qpid/dotnet/src/Message.cpp +++ b/cpp/bindings/qpid/dotnet/src/Message.cpp @@ -120,9 +120,9 @@ namespace Messaging { } - // Create from received message - Message::Message(::qpid::messaging::Message * msgp) : - messagep(msgp) + // unmanaged clone + Message::Message(const ::qpid::messaging::Message & msgp) : + messagep(new ::qpid::messaging::Message(msgp)) { } diff --git a/cpp/bindings/qpid/dotnet/src/Message.h b/cpp/bindings/qpid/dotnet/src/Message.h index c7f6092a40..cbe8cfc7ab 100644 --- a/cpp/bindings/qpid/dotnet/src/Message.h +++ b/cpp/bindings/qpid/dotnet/src/Message.h @@ -69,15 +69,15 @@ namespace Messaging { // Create from byte array slice Message(array ^ bytes, int offset, int size); - // Create from received message - Message(::qpid::messaging::Message * msgp); - ~Message(); !Message(); // Copy constructor Message(const Message ^ message); + // unmanaged clone + Message(const ::qpid::messaging::Message & msgp); + // assignment operator Message % operator=(const Message % rhs) { @@ -87,7 +87,8 @@ namespace Messaging { } else { - delete messagep; + if (NULL != messagep) + delete messagep; messagep = new ::qpid::messaging::Message( *(const_cast(rhs).NativeMessage) ); } @@ -117,7 +118,7 @@ namespace Messaging { const ::qpid::messaging::Address & addrp = messagep->::qpid::messaging::Message::getReplyTo(); - return gcnew Address(const_cast<::qpid::messaging::Address *>(&addrp)); + return gcnew Address(addrp); } } @@ -299,6 +300,7 @@ namespace Messaging { gcnew System::Collections::Generic::Dictionary< System::String^, System::Object^> ; + TypeTranslator::NativeToManaged(map, dict); return dict; diff --git a/cpp/bindings/qpid/dotnet/src/Receiver.cpp b/cpp/bindings/qpid/dotnet/src/Receiver.cpp index 1e2f30d996..87ad299078 100644 --- a/cpp/bindings/qpid/dotnet/src/Receiver.cpp +++ b/cpp/bindings/qpid/dotnet/src/Receiver.cpp @@ -43,13 +43,16 @@ namespace Messaging { /// Receiver is a managed wrapper for a ::qpid::messaging::Receiver /// - Receiver::Receiver(::qpid::messaging::Receiver * r, + // unmanaged clone + Receiver::Receiver(const ::qpid::messaging::Receiver & r, Org::Apache::Qpid::Messaging::Session ^ sessRef) : - receiverp(r), + receiverp(new ::qpid::messaging::Receiver (r)), parentSession(sessRef) { } + // unmanaged clone + // undefined // Destructor Receiver::~Receiver() @@ -88,17 +91,24 @@ namespace Messaging { // // Get(message) // - bool Receiver::Get(Message ^ mmsgp) - { - return Get(mmsgp, DurationConstants::FORVER); - } - - bool Receiver::Get(Message ^ mmsgp, Duration ^ durationp) - { - ::qpid::messaging::Duration dur((*durationp).Milliseconds); - - return receiverp->Receiver::get(*(mmsgp->NativeMessage), dur); - } + // TBD + //bool Receiver::Get(Message ^ mmsgp) + //{ + // return Get(mmsgp, DurationConstants::FORVER); + //} + // + //bool Receiver::Get(Message ^ mmsgp, Duration ^ durationp) + //{ + // ::qpid::messaging::Duration dur((*durationp).Milliseconds); + // + // ::qpid::messaging::Message tmpMsg; + // + // bool result = receiverp->Receiver::get(tmpMsg, dur); + // + // mmsgp = gcnew Message(tmpMsg); + // + // return result; + //} // // message = Get() @@ -112,22 +122,19 @@ namespace Messaging { Message ^ Receiver::Get(Duration ^ durationp) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Message * msgp = NULL; Message ^ newMessage = nullptr; try { - // allocate a message - msgp = new ::qpid::messaging::Message; - // translate the duration ::qpid::messaging::Duration dur((*durationp).Milliseconds); // get the message - *msgp = receiverp->::qpid::messaging::Receiver::get(dur); + ::qpid::messaging::Message msg = + receiverp->::qpid::messaging::Receiver::get(dur); // create new managed message with received message embedded in it - newMessage = gcnew Message(msgp); + newMessage = gcnew Message(msg); } catch (const ::qpid::types::Exception & error) { @@ -138,10 +145,6 @@ namespace Messaging { { if (newException != nullptr) { - if (msgp != NULL) - { - delete msgp; - } if (newMessage != nullptr) { delete newMessage; @@ -159,17 +162,24 @@ namespace Messaging { // // Fetch(message) // - bool Receiver::Fetch(Message ^ mmsgp) - { - return Fetch(mmsgp, DurationConstants::FORVER); - } - - bool Receiver::Fetch(Message ^ mmsgp, Duration ^ durationp) - { - ::qpid::messaging::Duration dur((*durationp).Milliseconds); - - return receiverp->::qpid::messaging::Receiver::fetch(*((*mmsgp).NativeMessage), dur); - } + // TBD + //bool Receiver::Fetch(Message ^ mmsgp) + //{ + // return Fetch(mmsgp, DurationConstants::FORVER); + //} + // + //bool Receiver::Fetch(Message ^ mmsgp, Duration ^ durationp) + //{ + // ::qpid::messaging::Duration dur((*durationp).Milliseconds); + // + // ::qpid::messaging::Message tmpMsg; + // + // bool result = receiverp->Receiver::fetch(tmpMsg, dur); + // + // mmsgp = gcnew Message(tmpMsg); + // + // return result; + //} // @@ -183,23 +193,20 @@ namespace Messaging { Message ^ Receiver::Fetch(Duration ^ durationp) { - System::Exception ^ newException = nullptr; - ::qpid::messaging::Message * msgp = NULL; - Message ^ newMessage = nullptr; + System::Exception ^ newException = nullptr; + Message ^ newMessage = nullptr; try { - // allocate a message - ::qpid::messaging::Message * msgp = new ::qpid::messaging::Message; - // translate the duration ::qpid::messaging::Duration dur((*durationp).Milliseconds); // get the message - *msgp = receiverp->::qpid::messaging::Receiver::fetch(dur); + ::qpid::messaging::Message msg = + receiverp->::qpid::messaging::Receiver::fetch(dur); // create new managed message with received message embedded in it - newMessage = gcnew Message(msgp); + newMessage = gcnew Message(msg); } catch (const ::qpid::types::Exception & error) { @@ -210,10 +217,6 @@ namespace Messaging { { if (newException != nullptr) { - if (msgp != NULL) - { - delete msgp; - } if (newMessage != nullptr) { delete newMessage; diff --git a/cpp/bindings/qpid/dotnet/src/Receiver.h b/cpp/bindings/qpid/dotnet/src/Receiver.h index c52e901f7a..ae32f6f4d3 100644 --- a/cpp/bindings/qpid/dotnet/src/Receiver.h +++ b/cpp/bindings/qpid/dotnet/src/Receiver.h @@ -61,12 +61,17 @@ namespace Messaging { ::qpid::messaging::Receiver * receiverp; public: - Receiver(::qpid::messaging::Receiver * r, + + // unmanaged clone + Receiver(const ::qpid::messaging::Receiver & r, Session ^ sessRef); // copy constructor Receiver(const Receiver ^ receiver); + // unmanaged clone + // undefined + ~Receiver(); !Receiver(); @@ -79,7 +84,8 @@ namespace Messaging { } else { - delete receiverp; + if (NULL != receiverp) + delete receiverp; receiverp = new ::qpid::messaging::Receiver( *(const_cast(rhs).NativeReceiver)); parentSession = rhs.parentSession; @@ -93,16 +99,18 @@ namespace Messaging { } // Get(message) - bool Get(Message ^ mmsgp); - bool Get(Message ^ mmsgp, Duration ^ durationp); + // TBD + //bool Get(Message ^ mmsgp); + //bool Get(Message ^ mmsgp, Duration ^ durationp); // message = Get() Message ^ Get(); Message ^ Get(Duration ^ durationp); // Fetch(message) - bool Fetch(Message ^ mmsgp); - bool Fetch(Message ^ mmsgp, Duration ^ duration); + // TBD + //bool Fetch(Message ^ mmsgp); + //bool Fetch(Message ^ mmsgp, Duration ^ duration); // message = Fetch() Message ^ Fetch(); diff --git a/cpp/bindings/qpid/dotnet/src/Sender.cpp b/cpp/bindings/qpid/dotnet/src/Sender.cpp index bcc2407841..0249c511b8 100644 --- a/cpp/bindings/qpid/dotnet/src/Sender.cpp +++ b/cpp/bindings/qpid/dotnet/src/Sender.cpp @@ -39,9 +39,10 @@ namespace Messaging { /// Sender a managed wrapper for a ::qpid::messaging::Sender /// - Sender::Sender(::qpid::messaging::Sender * s, + // unmanaged clone + Sender::Sender(const ::qpid::messaging::Sender & s, Org::Apache::Qpid::Messaging::Session ^ sessRef) : - senderp(s), + senderp(new ::qpid::messaging::Sender (s)), parentSession(sessRef) { } diff --git a/cpp/bindings/qpid/dotnet/src/Sender.h b/cpp/bindings/qpid/dotnet/src/Sender.h index 670f11fe30..e8ba227c06 100644 --- a/cpp/bindings/qpid/dotnet/src/Sender.h +++ b/cpp/bindings/qpid/dotnet/src/Sender.h @@ -59,7 +59,8 @@ namespace Messaging { void Cleanup(); public: - Sender(::qpid::messaging::Sender * s, + // unmanaged clone + Sender(const ::qpid::messaging::Sender & s, Session ^ sessRef); // copy constructor @@ -77,7 +78,8 @@ namespace Messaging { } else { - delete senderp; + if (NULL != senderp) + delete senderp; senderp = new ::qpid::messaging::Sender( *(const_cast(rhs).NativeSender)); parentSession = rhs.parentSession; diff --git a/cpp/bindings/qpid/dotnet/src/Session.cpp b/cpp/bindings/qpid/dotnet/src/Session.cpp index 438c9c4d00..6d40a27605 100644 --- a/cpp/bindings/qpid/dotnet/src/Session.cpp +++ b/cpp/bindings/qpid/dotnet/src/Session.cpp @@ -45,10 +45,10 @@ namespace Messaging { /// Session is a managed wrapper for a ::qpid::messaging::Session /// - // constructor - Session::Session(::qpid::messaging::Session * sp, + // unmanaged clone + Session::Session(const ::qpid::messaging::Session & session, Org::Apache::Qpid::Messaging::Connection ^ connRef) : - sessionp(sp), + sessionp(new ::qpid::messaging::Session (session)), parentConnectionp(connRef) { } @@ -180,11 +180,10 @@ namespace Messaging { try { ::qpid::messaging::Duration dur(timeout->Milliseconds); - ::qpid::messaging::Receiver * rcvr = new ::qpid::messaging::Receiver; - *rcvr = sessionp->::qpid::messaging::Session::nextReceiver(dur); + ::qpid::messaging::Receiver receiver = sessionp->::qpid::messaging::Session::nextReceiver(dur); - Receiver ^ newRcvr = gcnew Receiver(rcvr, this); + Receiver ^ newRcvr = gcnew Receiver(receiver, this); return newRcvr; } @@ -210,19 +209,16 @@ namespace Messaging { Sender ^ Session::CreateSender (System::String ^ address) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Sender * senderp = NULL; Sender ^ newSender = nullptr; try { - // allocate a native sender - ::qpid::messaging::Sender * senderp = new ::qpid::messaging::Sender ; - // create the sender - *senderp = sessionp->::qpid::messaging::Session::createSender(QpidMarshal::ToNative(address)); + ::qpid::messaging::Sender sender = + sessionp->::qpid::messaging::Session::createSender(QpidMarshal::ToNative(address)); // create a managed sender - newSender = gcnew Sender(senderp, this); + newSender = gcnew Sender(sender, this); } catch (const ::qpid::types::Exception & error) { @@ -237,13 +233,6 @@ namespace Messaging { { delete newSender; } - else - { - if (senderp != NULL) - { - delete senderp; - } - } } } if (newException != nullptr) @@ -258,19 +247,16 @@ namespace Messaging { Sender ^ Session::CreateSender (Address ^ address) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Sender * senderp = NULL; - Sender ^ newSender = nullptr; + Sender ^ newSender = nullptr; try { // allocate a native sender - ::qpid::messaging::Sender * senderp = new ::qpid::messaging::Sender ; - - // create the sender - *senderp = sessionp->::qpid::messaging::Session::createSender(*(address->NativeAddress)); + ::qpid::messaging::Sender sender = + sessionp->::qpid::messaging::Session::createSender(*(address->NativeAddress)); // create a managed sender - newSender = gcnew Sender(senderp, this); + newSender = gcnew Sender(sender, this); } catch (const ::qpid::types::Exception & error) { @@ -285,13 +271,6 @@ namespace Messaging { { delete newSender; } - else - { - if (senderp != NULL) - { - delete senderp; - } - } } } if (newException != nullptr) @@ -306,19 +285,16 @@ namespace Messaging { Receiver ^ Session::CreateReceiver(System::String ^ address) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Receiver * receiverp = NULL; Receiver ^ newReceiver = nullptr; try { - // allocate a native receiver - receiverp = new ::qpid::messaging::Receiver; - // create the receiver - *receiverp = sessionp->createReceiver(QpidMarshal::ToNative(address)); + ::qpid::messaging::Receiver receiver = + sessionp->createReceiver(QpidMarshal::ToNative(address)); // create a managed receiver - newReceiver = gcnew Receiver(receiverp, this); + newReceiver = gcnew Receiver(receiver, this); } catch (const ::qpid::types::Exception & error) { @@ -333,13 +309,6 @@ namespace Messaging { { delete newReceiver; } - else - { - if (receiverp != NULL) - { - delete receiverp; - } - } } } if (newException != nullptr) @@ -354,19 +323,16 @@ namespace Messaging { Receiver ^ Session::CreateReceiver(Address ^ address) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Receiver * receiverp = NULL; Receiver ^ newReceiver = nullptr; try { - // allocate a native receiver - receiverp = new ::qpid::messaging::Receiver; - // create the receiver - *receiverp = sessionp->createReceiver(*(address->NativeAddress)); + ::qpid::messaging::Receiver receiver = + sessionp->createReceiver(*(address->NativeAddress)); // create a managed receiver - newReceiver = gcnew Receiver(receiverp, this); + newReceiver = gcnew Receiver(receiver, this); } catch (const ::qpid::types::Exception & error) { @@ -381,58 +347,6 @@ namespace Messaging { { delete newReceiver; } - else - { - if (receiverp != NULL) - { - delete receiverp; - } - } - } - } - if (newException != nullptr) - { - throw newException; - } - - return newReceiver; - } - - - Receiver ^ Session::CreateReceiver() - { - System::Exception ^ newException = nullptr; - ::qpid::messaging::Receiver * receiverp = NULL; - Receiver ^ newReceiver = nullptr; - - try - { - // allocate a native receiver - receiverp = new ::qpid::messaging::Receiver; - - // create a managed receiver - newReceiver = gcnew Receiver(receiverp, this); - } - catch (const ::qpid::types::Exception & error) - { - String ^ errmsg = gcnew String(error.what()); - newException = gcnew QpidException(errmsg); - } - finally - { - if (newException != nullptr) - { - if (newReceiver != nullptr) - { - delete newReceiver; - } - else - { - if (receiverp != NULL) - { - delete receiverp; - } - } } } if (newException != nullptr) @@ -447,14 +361,12 @@ namespace Messaging { Sender ^ Session::GetSender(System::String ^ name) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Sender * senderp = NULL; Sender ^ newSender = nullptr; try { - senderp = new ::qpid::messaging::Sender; - - *senderp = sessionp->::qpid::messaging::Session::getSender(QpidMarshal::ToNative(name)); + ::qpid::messaging::Sender senderp = + sessionp->::qpid::messaging::Session::getSender(QpidMarshal::ToNative(name)); newSender = gcnew Sender(senderp, this); } @@ -471,13 +383,6 @@ namespace Messaging { { delete newSender; } - else - { - if (senderp != NULL) - { - delete senderp; - } - } } } if (newException != nullptr) @@ -493,16 +398,14 @@ namespace Messaging { Receiver ^ Session::GetReceiver(System::String ^ name) { System::Exception ^ newException = nullptr; - ::qpid::messaging::Receiver * receiverp = NULL; Receiver ^ newReceiver = nullptr; try { - receiverp = new ::qpid::messaging::Receiver; + ::qpid::messaging::Receiver receiver = + sessionp->::qpid::messaging::Session::getReceiver(QpidMarshal::ToNative(name)); - *receiverp = sessionp->::qpid::messaging::Session::getReceiver(QpidMarshal::ToNative(name)); - - newReceiver = gcnew Receiver(receiverp, this); + newReceiver = gcnew Receiver(receiver, this); } catch (const ::qpid::types::Exception & error) { @@ -517,13 +420,6 @@ namespace Messaging { { delete newReceiver; } - else - { - if (receiverp != NULL) - { - delete receiverp; - } - } } } if (newException != nullptr) diff --git a/cpp/bindings/qpid/dotnet/src/Session.h b/cpp/bindings/qpid/dotnet/src/Session.h index 18dc09fb33..d34289b1bb 100644 --- a/cpp/bindings/qpid/dotnet/src/Session.h +++ b/cpp/bindings/qpid/dotnet/src/Session.h @@ -65,7 +65,9 @@ namespace Messaging { void Cleanup(); public: - Session(::qpid::messaging::Session * sessionp, + + // unmanaged clone + Session(const ::qpid::messaging::Session & sessionp, Connection ^ connRef); // copy constructor @@ -83,9 +85,11 @@ namespace Messaging { } else { - delete sessionp; + if (NULL != sessionp) + delete sessionp; sessionp = new ::qpid::messaging::Session( *(const_cast(rhs).NativeSession) ); + parentConnectionp = rhs.parentConnectionp; } return *this; } @@ -129,7 +133,6 @@ namespace Messaging { Receiver ^ CreateReceiver(System::String ^ address); Receiver ^ CreateReceiver(Address ^ address); - Receiver ^ CreateReceiver(); Sender ^ GetSender(System::String ^ name); Receiver ^ GetReceiver(System::String ^ name); diff --git a/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs b/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs index c5a1a7eecc..b349e5c1fc 100644 --- a/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs +++ b/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs @@ -67,13 +67,15 @@ namespace Org.Apache.Qpid.Messaging.SessionReceiver /// public void Open() { - Receiver rcvr = session.CreateReceiver(); + Receiver rcvr; Message msg; keepRunning = true; while (keepRunning) { - if (session.NextReceiver(rcvr, DurationConstants.SECOND)) + rcvr = session.NextReceiver(DurationConstants.SECOND); + + if (null != rcvr) { if (keepRunning) { -- cgit v1.2.1