diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 3ef89a090..52f0a749d 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -26,7 +26,7 @@ namespace ns3 { -UdpSocket::UdpSocket (Node *node, Udp *udp) +UdpSocket::UdpSocket (Ptr node, Udp *udp) : m_endPoint (0), m_node (node), m_udp (udp), @@ -36,15 +36,10 @@ UdpSocket::UdpSocket (Node *node, Udp *udp) m_connected (false) { m_udp->Ref (); - m_node->Ref (); } UdpSocket::~UdpSocket () { - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; if (m_endPoint != 0) { NS_ASSERT (m_udp != 0); @@ -67,8 +62,8 @@ UdpSocket::~UdpSocket () } } -Node * -UdpSocket::PeekNode (void) const +Ptr +UdpSocket::GetNode (void) const { return m_node; } @@ -76,11 +71,7 @@ UdpSocket::PeekNode (void) const void UdpSocket::Destroy (void) { - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; m_endPoint = 0; if (m_udp != 0) { diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index c75ff9ae6..cab448b13 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -24,6 +24,7 @@ #include #include "ns3/callback.h" #include "ns3/socket.h" +#include "ns3/ptr.h" namespace ns3 { @@ -38,11 +39,11 @@ public: /** * Create an unbound udp socket. */ - UdpSocket (Node *node, Udp *udp); + UdpSocket (Ptr node, Udp *udp); virtual ~UdpSocket (); virtual enum SocketErrno GetErrno (void) const; - virtual Node *PeekNode (void) const; + virtual Ptr GetNode (void) const; virtual int Bind (void); virtual int Bind (Ipv4Address address); virtual int Bind (uint16_t port); @@ -81,7 +82,7 @@ private: ns3::Callback dataSent); Ipv4EndPoint *m_endPoint; - Node *m_node; + Ptr m_node; Udp *m_udp; Ipv4Address m_defaultAddress; uint16_t m_defaultPort; diff --git a/src/internet-node/udp.cc b/src/internet-node/udp.cc index 9261aa9a6..0fd2ae18f 100644 --- a/src/internet-node/udp.cc +++ b/src/internet-node/udp.cc @@ -38,13 +38,11 @@ namespace ns3 { /* see http://www.iana.org/assignments/protocol-numbers */ const uint8_t Udp::PROT_NUMBER = 17; -Udp::Udp (Node *node) +Udp::Udp (Ptr node) : Ipv4L4Protocol (PROT_NUMBER, 2), m_node (node), m_endPoints (new Ipv4EndPointDemux ()) -{ - m_node->Ref (); -} +{} Udp::~Udp () {} @@ -63,11 +61,7 @@ Udp::DoDispose (void) delete m_endPoints; m_endPoints = 0; } - if (m_node != 0) - { - m_node->Unref (); - m_node = 0; - } + m_node = 0; Ipv4L4Protocol::DoDispose (); } diff --git a/src/internet-node/udp.h b/src/internet-node/udp.h index 191dd2b73..5413f1bca 100644 --- a/src/internet-node/udp.h +++ b/src/internet-node/udp.h @@ -26,6 +26,7 @@ #include "ns3/packet.h" #include "ns3/ipv4-address.h" +#include "ns3/ptr.h" #include "ipv4-end-point-demux.h" #include "ipv4-l4-protocol.h" @@ -40,7 +41,7 @@ class Udp : public Ipv4L4Protocol { public: static const uint8_t PROT_NUMBER; - Udp (Node *node); + Udp (Ptr node); virtual ~Udp (); virtual TraceResolver *CreateTraceResolver (TraceContext const &context); @@ -67,7 +68,7 @@ public: protected: virtual void DoDispose (void); private: - Node *m_node; + Ptr m_node; Ipv4EndPointDemux *m_endPoints; }; diff --git a/src/node/socket.h b/src/node/socket.h index 950318505..396b79d71 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -22,6 +22,7 @@ #define __SOCKET_H__ #include "ns3/callback.h" +#include "ns3/ptr.h" #include "ipv4-address.h" #include "ns3/object.h" #include @@ -65,7 +66,7 @@ public: /** * \returns the node this socket is associated with. */ - virtual Node *PeekNode (void) const = 0; + virtual Ptr GetNode (void) const = 0; /** * Allocate a free port number and