[Ns-developers] SendTo parameters swapped
Tom Henderson
tomh at tomh.org
Tue May 13 09:49:38 PDT 2008
>-----Original Message-----
>From: Gustavo Carneiro [mailto:gjcarneiro at gmail.com]
>Sent: Tuesday, May 13, 2008 05:56 AM
>To: 'ns-developers'
>Subject: [Ns-developers] SendTo parameters swapped
>
>In BSD sockets:
>
> ssize_t sendto(int s, const void *buf, size_t len, int flags,
> const struct sockaddr *to, socklen_t tolen);
>
>
>In NS-3:
> /**
> * \brief Send data to a specified peer.
> * \param address IP Address of remote host
> * \param p packet to send
> * \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,Ptr<Packet> p) = 0;
>
>This keeps confusing me. NS-3 SendTo should move address to second
>argument, not first.
I aligned this as you suggested, in ns-3-dev-socket branch.
>While you're at it, does "const Address &" have any
>advantage over "Address" ?
I don't know whether there is an advantage. Address is a 32-byte object; potentially this call could frequently occur in a simulation. This is historical per the basic C++ guidance "prefer pass by reference to const instead of by value". But pass by value also works for this particular class and is implemented as pass-by-value elsewhere in the ns-3 API.
Tom
More information about the Ns-developers
mailing list