From ca67fb2e8f0e6360f511ac658c893f28f4baa4a6 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Fri, 3 Sep 2010 17:17:31 -0400 Subject: [PATCH] lib: avoiding non-const references A non-const reference prevents constructing a shared_ptr on the fly, and passing it into the function, as far as I know. It might be conceivable that a user might not care about the handler after passing it in. --- src/router.cc | 2 +- src/router.h | 4 ++-- src/socket.cc | 2 +- src/socket.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/router.cc b/src/router.cc index fc281abb..0edbe07f 100644 --- a/src/router.cc +++ b/src/router.cc @@ -208,7 +208,7 @@ DataHandle SocketRoutingQueue::DefaultRead(int timeout) /// Throws std::logic_error if already registered. /// void SocketRoutingQueue::RegisterInterest(SocketId socket, - std::tr1::shared_ptr& handler) + std::tr1::shared_ptr handler) { // modifying our own std::map, need a lock scoped_lock lock(m_mutex); diff --git a/src/router.h b/src/router.h index 020f6be1..8c9d2a33 100644 --- a/src/router.h +++ b/src/router.h @@ -85,7 +85,7 @@ public: std::tr1::shared_ptr m_handler; DataQueue m_queue; - QueueEntry(std::tr1::shared_ptr& h) + QueueEntry(std::tr1::shared_ptr h) : m_handler(h) {} }; @@ -171,7 +171,7 @@ public: // copying is done. Once the handler returns, the data is // considered processed and not added to the interested queue, // but instead returned to m_free. - void RegisterInterest(SocketId socket, std::tr1::shared_ptr& handler); + void RegisterInterest(SocketId socket, std::tr1::shared_ptr handler); // Unregisters interest in data from the given socket, and discards // any existing data in its interest queue. Any new incoming data diff --git a/src/socket.cc b/src/socket.cc index c851152b..5704cafc 100644 --- a/src/socket.cc +++ b/src/socket.cc @@ -1098,7 +1098,7 @@ void Socket::NextRecord(Data &receive) Packet(command, receive); } -void Socket::RegisterInterest(std::tr1::shared_ptr& handler) +void Socket::RegisterInterest(std::tr1::shared_ptr handler) { if( !m_zero->m_queue ) throw std::logic_error("SocketRoutingQueue required in SocketZero in order to call Socket::RegisterInterest()"); diff --git a/src/socket.h b/src/socket.h index 69027676..d1081203 100644 --- a/src/socket.h +++ b/src/socket.h @@ -189,7 +189,7 @@ public: // Register a callback for incoming data from the device. // This function assumes that this socket is based on a socketZero // that has a SocketRoutingQueue, otherwise throws logic_error. - void RegisterInterest(std::tr1::shared_ptr& handler); + void RegisterInterest(std::tr1::shared_ptr handler); void UnregisterInterest(); -- 2.11.4.GIT