Bug 249

Summary: Cleanup virtuals of UdpSocket and TcpSocket
Product: ns-3 Reporter: Gustavo J. A. M. Carneiro <gjcarneiro>
Component: networkAssignee: ns-bugs <ns-bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: pre-release   
Hardware: All   
OS: All   
Attachments: patch

Description Gustavo J. A. M. Carneiro 2008-07-09 08:01:08 UTC
As discussed in the mailing list: http://mailman.isi.edu/pipermail/ns-developers/2008-July/004425.html

This is a blocker for functional Socket Python bindings.
Comment 1 Gustavo J. A. M. Carneiro 2008-07-09 08:01:34 UTC
Created attachment 195 [details]
patch
Comment 2 Mathieu Lacage 2008-07-09 13:21:26 UTC
looks good to me. please, apply.
Comment 3 Craig Dowell 2008-07-09 13:36:48 UTC
I'm not at all sure why it is a good idea to clean out all of the methods of Socket since they defined what it meant to be a socket object.  There is a reason they were there.  Can someone explain to me why did we not do the usual thing:

struct Socket
{
  virtual ~Socket();
  virtual int Bind (void) { return -1; }
};

Socket::~Socket(){}

struct UdpSocket : public Socket
{
  virtual ~UdpSocket();

  virtual int Bind (int) { return 0; }
  virtual int Bind (void) { return Socket::Bind (); }
};

UdpSocket::~UdpSocket(){}

int main (int argc, char *argv[])
{
  UdpSocket sock;
  sock.Bind (123);
  sock.Bind ();
  return 0;
}
Comment 4 Gustavo J. A. M. Carneiro 2008-07-09 13:43:49 UTC
Sorry, I already applied the patch :P

(In reply to comment #3)
> I'm not at all sure why it is a good idea to clean out all of the methods of
> Socket since they defined what it meant to be a socket object.  There is a
> reason they were there.  Can someone explain to me why did we not do the usual
> thing:
> 
> struct Socket
> {
>   virtual ~Socket();
>   virtual int Bind (void) { return -1; }
> };
> 
> Socket::~Socket(){}
> 
> struct UdpSocket : public Socket
> {
>   virtual ~UdpSocket();
> 
>   virtual int Bind (int) { return 0; }
>   virtual int Bind (void) { return Socket::Bind (); }
> };
> 
> UdpSocket::~UdpSocket(){}
> 
> int main (int argc, char *argv[])
> {
>   UdpSocket sock;
>   sock.Bind (123);
>   sock.Bind ();
>   return 0;
> }
> 

Because the virtual methods declaration is pointless?.. Do the declarations solve any problem? No.  Do they create problems? Yes!  It's very logical IMHO...

Anyway, does this solution offend you, or can I close the bug?
Comment 5 Mathieu Lacage 2008-07-09 13:56:17 UTC
(In reply to comment #3)
> I'm not at all sure why it is a good idea to clean out all of the methods of
> Socket since they defined what it meant to be a socket object.  There is a
> reason they were there.  Can someone explain to me why did we not do the usual

I cannot see any reason why they were in udp-socket.h and tcp-socket.h: they just pointlessly repeated the information present in the socket.h header. There is just a single instance in our codebase where we do this in src/common/header.h and src/common/trailer.h but we do this for documentation purposes.
Comment 6 Rajib Bhattacharjea 2008-07-09 14:00:12 UTC
These classes were formerly non-abstract, but the actual implementations got pushed into *impl subclasses classes.  This fix is okay given this change.
Comment 7 Craig Dowell 2008-07-09 15:07:00 UTC
> I cannot see any reason why they were in udp-socket.h and tcp-socket.h ...

Okay.  From flipping between several threads in several places I got the idea that we were talking about removing the declarations from *Socket.*  I guess my brain was unable to cope with an instance of a pure virtual redlaration of a pure virtual base class method in a subclass.

I agree that having 

  virtual int Bind () = 0;

in UdpSocket and TcpSocket is bizarre, causes problems and is unneccessary.

+1
Comment 8 Mathieu Lacage 2008-07-09 18:25:46 UTC
changeset 266c6a334762