This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] fix for the proxy port preference not being saved


This is the much-requested fix for the problem of not saving the proxy
port.  I had always expected this was some kind of trivial bug that just
needed a quick fix, but I was incorrect.  It was much more subtle than I
gave it credit for.

Essentially, save_dialog() is called any time a window message is
received that indicates something has changed in the dialog, and the
value is copied from the dialog into local variables.  When setup
terminates, these values are correctly saved to
/etc/setup/last-connection, and properly read upon startup the next
time.

The problem was that when load_dialog() runs to ostensibly restore these
saved values, it first sets the net_proxy_host value - but this causes a
window message to be dispatched, which results in save_dialog() being
called.  Since load_dialog has not yet had a chance to restore the proxy
port setting, save_dialog reads the value of 0 and replaces the value of
net_proxy_host with 0.

Seems simple enough in hindsight, but by the time I realized what was
going on I had been single stepping through disassembly in user32.dll
because I was convinced that the win32 call to SetDlgItemText() was
clobbering adjacent memory locations.  Silly me...

Brian

2005-05-03  Brian Dessent  <brian@dessent.net>

	* net.cc: (static doing_loading): Declare.  (load_dialog): Guard
	against triggering call to save_dialog() when fields are changed
	here. (save_dialog): Ditto.  (NetPage::OnInit): Initialize here.
Index: net.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/net.cc,v
retrieving revision 2.15
diff -u -p -r2.15 net.cc
--- net.cc	27 Dec 2004 16:12:44 -0000	2.15
+++ net.cc	3 May 2005 12:27:55 -0000
@@ -40,6 +40,7 @@ extern ThreeBarProgressPage Progress;
 
 static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
 static ConnectionSetting theSetting;
+static bool doing_loading;
 
 void
 NetPage::CheckIfEnableNext ()
@@ -72,16 +73,25 @@ NetPage::CheckIfEnableNext ()
 static void
 load_dialog (HWND h)
 {
+  doing_loading = true;
   rbset (h, rb, net_method);
   eset (h, IDC_PROXY_HOST, net_proxy_host);
   if (net_proxy_port == 0)
     net_proxy_port = 80;
   eset (h, IDC_PROXY_PORT, net_proxy_port);
+  doing_loading = false;
 }
 
 static void
 save_dialog (HWND h)
 {
+  // Without this, save_dialog() is called in the middle of load_dialog() because
+  // the window receives a message when the value changes.  If this happens,
+  // save_dialog() tries to read the values of the fields, resulting in 
+  // the net_proxy_port being reset to zero - this is the cause of the preference
+  // not sticking.
+  if (doing_loading)
+    return;
   net_method = rbget (h, rb);
   net_proxy_host = eget (h, IDC_PROXY_HOST, net_proxy_host);
   net_proxy_port = eget (h, IDC_PROXY_PORT);
@@ -98,6 +108,7 @@ NetPage::OnInit ()
 {
   HWND h = GetHWND ();
 
+  doing_loading = false;
   if (!net_method)
     net_method = IDC_NET_DIRECT;
   load_dialog (h);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]