Add uint8_t* based API for sockets
authorRaj Bhattacharjea <raj.b@gatech.edu>
Thu, 13 Dec 2007 09:40:21 -0500
changeset 2186 69ad6ed6ccf4
parent 2185 d3582be30902
child 2187 d13161eb95df
Add uint8_t* based API for sockets
src/node/socket.cc
src/node/socket.h
--- a/src/node/socket.cc	Wed Dec 12 11:03:35 2007 +0100
+++ b/src/node/socket.cc	Thu Dec 13 09:40:21 2007 -0500
@@ -78,6 +78,36 @@
   m_receivedData = receivedData;
 }
 
+int Socket::Send (const uint8_t* buf, uint32_t size)
+{
+  NS_LOG_FUNCTION;
+  Ptr<Packet> p;
+  if (buf)
+    {
+      p = Create<Packet> (buf, size);
+    }
+  else
+    {
+      p = Create<Packet> (size);
+    }
+  return Send (p);
+}
+
+int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size)
+{
+  NS_LOG_FUNCTION;
+  Ptr<Packet> p;
+  if(buf)
+    {
+      p = Create<Packet> (buf, size);
+    }
+  else
+    {
+      p = Create<Packet> (size);
+    }
+  return SendTo (address,p);
+}
+
 void 
 Socket::NotifyCloseCompleted (void)
 {
--- a/src/node/socket.h	Wed Dec 12 11:03:35 2007 +0100
+++ b/src/node/socket.h	Thu Dec 13 09:40:21 2007 -0500
@@ -177,6 +177,17 @@
   virtual int Send (Ptr<Packet> p) = 0;
   
   /**
+   * \brief Send data (or dummy data) to the remote host
+   * \param buf A pointer to a raw byte buffer of some data to send.  If this 
+   * is 0, we send dummy data whose size is specified by the second parameter
+   * \param size the number of bytes to copy from the buffer
+   * 
+   * This is provided so as to have an API which is closer in appearance 
+   * to that of real network or BSD sockets.  
+   */
+  int Send (const uint8_t* buf, uint32_t size);
+  
+  /**
    * \brief Send data to a specified peer.
    * \param address IP Address of remote host
    * \param p packet to send
@@ -185,6 +196,20 @@
    */
   virtual int SendTo(const Address &address,Ptr<Packet> p) = 0;
 
+  /**
+   * \brief Send data to a specified peer.
+   * \param address IP Address of remote host
+   * \param buf A pointer to a raw byte buffer of some data to send.  If this 
+   * is 0, we send dummy data whose size is specified by the third parameter
+   * \param size the number of bytes to copy from the buffer
+   * \returns -1 in case of error or the number of bytes copied in the 
+   *          internal buffer and accepted for transmission.
+   *
+   * This is provided so as to have an API which is closer in appearance 
+   * to that of real network or BSD sockets.
+   */
+  int SendTo(const Address &address, const uint8_t* buf, uint32_t size);
+
 protected:
   void NotifyCloseCompleted (void);
   void NotifyConnectionSucceeded (void);