From b954d65b8fda467d57f31b35a74e59e97532c00e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 1 Aug 2007 19:19:42 +0200 Subject: [PATCH] remove uint8_t * from the send path of the socket API --- samples/main-simple.cc | 2 +- src/applications/onoff-application.cc | 3 ++- src/internet-node/udp-socket.cc | 25 ++----------------------- src/internet-node/udp-socket.h | 4 ++-- src/node/packet-socket.cc | 19 +++---------------- src/node/packet-socket.h | 4 ++-- src/node/socket.h | 10 ++++------ 7 files changed, 16 insertions(+), 51 deletions(-) diff --git a/samples/main-simple.cc b/samples/main-simple.cc index 11cd27d16..c9ae24ce3 100644 --- a/samples/main-simple.cc +++ b/samples/main-simple.cc @@ -14,7 +14,7 @@ static void GenerateTraffic (Ptr socket, uint32_t size) { std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl; - socket->Send (0, size); + socket->Send (Packet (size)); if (size > 0) { Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50); diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index 5fa2c8266..32bcd7564 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -31,6 +31,7 @@ #include "ns3/simulator.h" #include "ns3/socket-factory.h" #include "ns3/default-value.h" +#include "ns3/packet.h" #include "onoff-application.h" using namespace std; @@ -205,7 +206,7 @@ void OnOffApplication::ScheduleStopEvent() void OnOffApplication::SendPacket() { NS_ASSERT (m_sendEvent.IsExpired ()); - m_socket->Send(0, m_pktSize); + m_socket->Send(Packet (m_pktSize)); m_totBytes += m_pktSize; m_lastStartTime = Simulator::Now(); m_residualBits = 0; diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index bfcce63bf..7c9d6b015 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -155,23 +155,13 @@ UdpSocket::Connect(const Address & address) return 0; } int -UdpSocket::Send (const uint8_t* buffer, - uint32_t size) +UdpSocket::Send (const Packet &p) { if (!m_connected) { m_errno = ERROR_NOTCONN; return -1; } - Packet p; - if (buffer == 0) - { - p = Packet (size); - } - else - { - p = Packet (buffer, size); - } return DoSendTo (p, m_defaultAddress, m_defaultPort); } int @@ -205,24 +195,13 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address ipv4, uint16_t port) return 0; } int -UdpSocket::SendTo(const Address &address, - const uint8_t *buffer, - uint32_t size) +UdpSocket::SendTo(const Address &address, const Packet &p) { if (m_connected) { m_errno = ERROR_ISCONN; return -1; } - Packet p; - if (buffer == 0) - { - p = Packet (size); - } - else - { - p = Packet (buffer, size); - } InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); Ipv4Address ipv4 = transport.GetIpv4 (); uint16_t port = transport.GetPort (); diff --git a/src/internet-node/udp-socket.h b/src/internet-node/udp-socket.h index 2ef148247..b3674f7ef 100644 --- a/src/internet-node/udp-socket.h +++ b/src/internet-node/udp-socket.h @@ -51,8 +51,8 @@ public: virtual int ShutdownSend (void); virtual int ShutdownRecv (void); virtual int Connect(const Address &address); - virtual int Send (const uint8_t* buffer, uint32_t size); - virtual int SendTo(const Address &address,const uint8_t *buffer, uint32_t size); + virtual int Send (const Packet &p); + virtual int SendTo(const Address &address,const Packet &p); private: diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 8fe64714e..6035f74f6 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -186,8 +186,7 @@ PacketSocket::Connect(const Address &ad) } int -PacketSocket::Send (const uint8_t* buffer, - uint32_t size) +PacketSocket::Send (const Packet &p) { if (m_state == STATE_OPEN || m_state == STATE_BOUND) @@ -195,13 +194,11 @@ PacketSocket::Send (const uint8_t* buffer, m_errno = ERROR_NOTCONN; return -1; } - return SendTo (m_destAddr, buffer, size); + return SendTo (m_destAddr, p); } int -PacketSocket::SendTo(const Address &address, - const uint8_t *buffer, - uint32_t size) +PacketSocket::SendTo(const Address &address, const Packet &p) { PacketSocketAddress ad; if (m_state == STATE_CLOSED) @@ -226,16 +223,6 @@ PacketSocket::SendTo(const Address &address, return -1; } ad = PacketSocketAddress::ConvertFrom (address); - - Packet p; - if (buffer == 0) - { - p = Packet (size); - } - else - { - p = Packet (buffer, size); - } bool error = false; Address dest = ad.GetPhysicalAddress (); diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index c18d69087..8dc1b9e62 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -82,8 +82,8 @@ public: virtual int ShutdownSend (void); virtual int ShutdownRecv (void); virtual int Connect(const Address &address); - virtual int Send (const uint8_t* buffer, uint32_t size); - virtual int SendTo(const Address &address,const uint8_t *buffer, uint32_t size); + virtual int Send (const Packet &p); + virtual int SendTo(const Address &address,const Packet &p); private: diff --git a/src/node/socket.h b/src/node/socket.h index 14e105da8..e3365fcd8 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -169,24 +169,22 @@ public: /** * \brief Send data (or dummy data) to the remote host - * \param buffer Data to send (nil if dummy data). - * \param size Number of bytes to send. + * \param p packet to send * \param dataSent Data sent callback. * \returns -1 in case of error or the number of bytes copied in the * internal buffer and accepted for transmission. */ - virtual int Send (const uint8_t* buffer, uint32_t size) = 0; + virtual int Send (const Packet &p) = 0; /** * \brief Send data to a specified peer. * \param address IP Address of remote host - * \param buffer Data to send (nil if dummy data). - * \param size Number of bytes to send. + * \param p packet to send * \param dataSent Data sent callback. * \returns -1 in case of error or the number of bytes copied in the * internal buffer and accepted for transmission. */ - virtual int SendTo(const Address &address,const uint8_t *buffer, uint32_t size) = 0; + virtual int SendTo(const Address &address,const Packet &p) = 0; protected: void NotifyCloseCompleted (void);