return true;
}
+bool wxSocketBase::SetLocal(wxSockAddress& local)
+{
+ GAddress* la = local.GetAddress();
+
+ if (la && la->m_addr)
+ {
+ m_socket->SetLocal(la);
+
+ return true;
+ }
+
+ return false;
+}
+
// ==========================================================================
// wxSocketClient
// ==========================================================================
// Connect
// --------------------------------------------------------------------------
-bool wxSocketClient::Connect(wxSockAddress& addr_man, bool wait)
+bool wxSocketClient::DoConnect(wxSockAddress& addr_man, wxSockAddress* local, bool wait)
{
GSocketError err;
if (!wait)
m_socket->SetNonBlocking(1);
+ // Reuse makes sense for clients too, if we are trying to rebind to the same port
+ if (GetFlags() & wxSOCKET_REUSEADDR)
+ {
+ m_socket->SetReusable();
+ }
+
+ // Bind to the local IP address and port, when provided
+ if (local)
+ {
+ GAddress* la = local->GetAddress();
+
+ if (la && la->m_addr)
+ m_socket->SetLocal(la);
+ }
+
m_socket->SetPeer(addr_man.GetAddress());
err = m_socket->Connect(GSOCK_STREAMED);
return true;
}
+bool wxSocketClient::Connect(wxSockAddress& addr_man, bool wait)
+{
+ return (DoConnect(addr_man, NULL, wait));
+}
+
+bool wxSocketClient::Connect(wxSockAddress& addr_man, wxSockAddress& local, bool wait)
+{
+ return (DoConnect(addr_man, &local, wait));
+}
+
bool wxSocketClient::WaitOnConnect(long seconds, long milliseconds)
{
if (m_connected) // Already connected