From 30bbf68d3aa0ad475b25c69e04963ec700e589b6 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Tue, 28 Feb 2006 02:04:29 +0000 Subject: [PATCH] Make SetLocal actually work instead of crashing immediately; due to required longevity of the item to make it from SetLocal to Connect, we need to use a specifc address type. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37759 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/socket.tex | 2 +- include/wx/socket.h | 3 ++- src/common/socket.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/latex/wx/socket.tex b/docs/latex/wx/socket.tex index fae16a9068..4afed4bb82 100644 --- a/docs/latex/wx/socket.tex +++ b/docs/latex/wx/socket.tex @@ -589,7 +589,7 @@ reusing local addresses/ports. % \membersection{wxSocketBase::SetLocal}\label{wxsocketbasesetlocal} -\func{bool}{SetLocal}{\param{wxSockAddress\&}{ local}} +\func{bool}{SetLocal}{\param{wxIPV4address\&}{ local}} This function allows you to set the local address and port, useful when an application needs to reuse a particular port. When diff --git a/include/wx/socket.h b/include/wx/socket.h index 266a24321d..d04a733fd0 100644 --- a/include/wx/socket.h +++ b/include/wx/socket.h @@ -121,7 +121,7 @@ public: // addresses virtual bool GetLocal(wxSockAddress& addr_man) const; virtual bool GetPeer(wxSockAddress& addr_man) const; - virtual bool SetLocal(wxSockAddress& local); + virtual bool SetLocal(wxIPV4address& local); // base IO virtual bool Close(); @@ -202,6 +202,7 @@ private: wxList m_states; // stack of states bool m_interrupt; // interrupt ongoing wait operations? bool m_beingDeleted; // marked for delayed deletion? + wxIPV4address m_localAddress; // bind to local address? // pushback buffer void *m_unread; // pushback buffer diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 7285254c4b..05f337bfc3 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -1203,13 +1203,14 @@ bool wxSocketBase::SetOption(int level, int optname, const void *optval, return true; } -bool wxSocketBase::SetLocal(wxSockAddress& local) +bool wxSocketBase::SetLocal(wxIPV4address& local) { GAddress* la = local.GetAddress(); + // If the address is valid, save it for use when we call Connect if (la && la->m_addr) { - m_socket->SetLocal(la); + m_localAddress = local; return true; } @@ -1274,6 +1275,12 @@ bool wxSocketClient::DoConnect(wxSockAddress& addr_man, wxSockAddress* local, bo m_socket->SetReusable(); } + // If no local address was passed and one has been set, use the one that was Set + if (!local && m_localAddress.GetAddress()) + { + local = &m_localAddress; + } + // Bind to the local IP address and port, when provided if (local) { -- 2.45.2