From: Kevin Hock Date: Sat, 11 Feb 2006 23:44:26 +0000 (+0000) Subject: Respect the REUSEADDR flag to allow rebinding; bind to local port prior to connecting... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/716a5baa6ecd0d5d0c31914567e4da3165ca6ff0 Respect the REUSEADDR flag to allow rebinding; bind to local port prior to connecting if a local port is specified [ Extension of patch 1415505 ] git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/gsocket.cpp b/src/msw/gsocket.cpp index 42873e0858..d72e553f28 100644 --- a/src/msw/gsocket.cpp +++ b/src/msw/gsocket.cpp @@ -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);