Bug 1201

Summary: UDP sockets need to set connected state before notifying the ConnectionSucceeded callback
Product: ns-3 Reporter: Tom Henderson <tomh>
Component: internetAssignee: George Riley <riley>
Status: RESOLVED FIXED    
Severity: normal CC: ns-bugs, smarotta, tommaso.pecorella
Priority: P5    
Version: pre-release   
Hardware: All   
OS: All   

Description Tom Henderson 2011-06-28 02:15:51 UTC
Steve Marotta suggested this fix on the ns-users list here:
http://groups.google.com/group/ns-3-users/browse_thread/thread/456d72d7c38ae2a0

diff -r b5c7eb57d8d6 src/internet/model/udp-socket-impl.cc
--- a/src/internet/model/udp-socket-impl.cc	Fri Jun 24 16:08:55 2011 +0100
+++ b/src/internet/model/udp-socket-impl.cc	Mon Jun 27 23:10:36 2011 -0700
@@ -231,8 +231,8 @@
   InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   m_defaultAddress = transport.GetIpv4 ();
   m_defaultPort = transport.GetPort ();
+  m_connected = true;
   NotifyConnectionSucceeded ();
-  m_connected = true;
 
   return 0;
 }
Comment 1 Tommaso Pecorella 2011-06-28 02:43:46 UTC
I don't see any drawbacks and any reason we shouldn't do it. After all if the user will check the connection state right in the Notify (kinda stupid imho, but they could), they'd find it not yet connected.

So for consistency it seems quite reasonable.

+1
Comment 2 Tom Henderson 2011-06-28 13:05:34 UTC
fixed:  changeset 21678ba057ef
Comment 3 Steve Marotta 2011-06-28 14:14:35 UTC
(In reply to comment #1)
> I don't see any drawbacks and any reason we shouldn't do it. After all if the
> user will check the connection state right in the Notify (kinda stupid imho,
> but they could), they'd find it not yet connected.
> 
> So for consistency it seems quite reasonable.
> 
> +1

It's not just for consistency. If you try to send data on a Socket whose m_connected is false, it doesn't work.