diff --git a/src/node/socket.cc b/src/node/socket.cc index 78d8cbf72..d6e47e3f1 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -78,6 +78,36 @@ Socket::SetRecvCallback (Callback, Ptr,const Address&> m_receivedData = receivedData; } +int Socket::Send (const uint8_t* buf, uint32_t size) +{ + NS_LOG_FUNCTION; + Ptr p; + if (buf) + { + p = Create (buf, size); + } + else + { + p = Create (size); + } + return Send (p); +} + +int Socket::SendTo (const Address &address, const uint8_t* buf, uint32_t size) +{ + NS_LOG_FUNCTION; + Ptr p; + if(buf) + { + p = Create (buf, size); + } + else + { + p = Create (size); + } + return SendTo (address,p); +} + void Socket::NotifyCloseCompleted (void) { diff --git a/src/node/socket.h b/src/node/socket.h index 4e6bb2a19..c27de2f59 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -176,6 +176,17 @@ public: */ virtual int Send (Ptr 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 @@ -185,6 +196,20 @@ public: */ virtual int SendTo(const Address &address,Ptr 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);