]> git.saurik.com Git - wxWidgets.git/commitdiff
Respect the REUSEADDR flag to allow rebinding; bind to local port prior to connecting...
authorKevin Hock <hockkn@yahoo.com>
Sat, 11 Feb 2006 23:44:26 +0000 (23:44 +0000)
committerKevin Hock <hockkn@yahoo.com>
Sat, 11 Feb 2006 23:44:26 +0000 (23:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/gsocket.cpp

index 42873e0858fbe648904476c1d18d0be1ac9f89ca..d72e553f288c043411cd474aa27aec94b9f97550 100644 (file)
@@ -593,6 +593,18 @@ GSocketError GSocket::Connect(GSocketStream stream)
   ioctlsocket(m_fd, FIONBIO, (u_long FAR *) &arg);
   gs_gui_functions->Enable_Events(this);
 
+  // If the reuse flag is set, use the applicable socket reuse flag
+  if (m_reusable)
+  {
+     setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long));
+  }
+
+  // If a local address has been set, then we need to bind to it before calling connect
+  if (m_local && m_local->m_addr)
+  {
+    bind(m_fd, m_local->m_addr, m_local->m_len);
+  }
+
   /* Connect it to the peer address, with a timeout (see below) */
   ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);