remove uint8_t * from the send path of the socket API
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 01 Aug 2007 19:19:42 +0200
changeset 1267 0ea5ae44f96b
parent 1266 6b27f6b349ba
child 1268 0cd947bd1419
remove uint8_t * from the send path of the socket API
samples/main-simple.cc
src/applications/onoff-application.cc
src/internet-node/udp-socket.cc
src/internet-node/udp-socket.h
src/node/packet-socket.cc
src/node/packet-socket.h
src/node/socket.h
--- a/samples/main-simple.cc	Wed Aug 01 19:19:28 2007 +0200
+++ b/samples/main-simple.cc	Wed Aug 01 19:19:42 2007 +0200
@@ -14,7 +14,7 @@
 GenerateTraffic (Ptr<Socket> 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);
--- a/src/applications/onoff-application.cc	Wed Aug 01 19:19:28 2007 +0200
+++ b/src/applications/onoff-application.cc	Wed Aug 01 19:19:42 2007 +0200
@@ -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::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;
--- a/src/internet-node/udp-socket.cc	Wed Aug 01 19:19:28 2007 +0200
+++ b/src/internet-node/udp-socket.cc	Wed Aug 01 19:19:42 2007 +0200
@@ -155,23 +155,13 @@
   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 @@
   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 ();
--- a/src/internet-node/udp-socket.h	Wed Aug 01 19:19:28 2007 +0200
+++ b/src/internet-node/udp-socket.h	Wed Aug 01 19:19:42 2007 +0200
@@ -51,8 +51,8 @@
   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:
 
--- a/src/node/packet-socket.cc	Wed Aug 01 19:19:28 2007 +0200
+++ b/src/node/packet-socket.cc	Wed Aug 01 19:19:42 2007 +0200
@@ -186,8 +186,7 @@
 }
 
 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 @@
       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 @@
       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 ();
--- a/src/node/packet-socket.h	Wed Aug 01 19:19:28 2007 +0200
+++ b/src/node/packet-socket.h	Wed Aug 01 19:19:42 2007 +0200
@@ -82,8 +82,8 @@
   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:
--- a/src/node/socket.h	Wed Aug 01 19:19:28 2007 +0200
+++ b/src/node/socket.h	Wed Aug 01 19:19:42 2007 +0200
@@ -169,24 +169,22 @@
     
   /**
    * \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);