diff --git a/CHANGES b/CHANGES index 4c57bf68..b84ed21e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2.0.11 2014-11-23 +- Fix a crash +- Only switch the system proxy off if we have switched it on + 2.0.10 2014-11-18 - Minor fixes - Optimize code diff --git a/shadowsocks-csharp/Controller/Local.cs b/shadowsocks-csharp/Controller/Local.cs index 97f21474..15649b40 100755 --- a/shadowsocks-csharp/Controller/Local.cs +++ b/shadowsocks-csharp/Controller/Local.cs @@ -144,7 +144,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -176,7 +176,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); } } if (remote != null) @@ -188,7 +188,7 @@ namespace Shadowsocks.Controller } catch (SocketException e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); } } lock (encryptionLock) @@ -218,7 +218,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -236,7 +236,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -269,7 +269,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -296,7 +296,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -324,7 +324,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -346,7 +346,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -384,7 +384,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -421,7 +421,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -440,7 +440,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -459,7 +459,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } diff --git a/shadowsocks-csharp/Controller/Logging.cs b/shadowsocks-csharp/Controller/Logging.cs index 58a994f5..ada32ce5 100755 --- a/shadowsocks-csharp/Controller/Logging.cs +++ b/shadowsocks-csharp/Controller/Logging.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net.Sockets; using System.Text; namespace Shadowsocks.Controller @@ -30,5 +31,31 @@ namespace Shadowsocks.Controller return false; } } + + public static void LogUsefulException(Exception e) + { + // just log useful exceptions, not all of them + if (e is SocketException) + { + SocketException se = (SocketException)e; + if (se.SocketErrorCode == SocketError.ConnectionAborted) + { + // closed by browser when sending + // normally happens when download is canceled or a tab is closed before page is loaded + } + else if (se.SocketErrorCode == SocketError.ConnectionReset) + { + // received rst + } + else + { + Console.WriteLine(e); + } + } + else + { + Console.WriteLine(e); + } + } } } diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index 7b39252d..6e611b2b 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -174,7 +174,12 @@ Connection: Close private void SendCallback(IAsyncResult ar) { Socket conn = (Socket)ar.AsyncState; - conn.Shutdown(SocketShutdown.Send); + try + { + conn.Shutdown(SocketShutdown.Send); + } + catch + { } } private void WatchPacFile() diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index b4de4cf9..f5bdb44c 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -22,6 +22,8 @@ namespace Shadowsocks.Controller private PolipoRunner polipoRunner; private bool stopped = false; + private bool _systemProxyIsDirty = false; + public class PathEventArgs : EventArgs { public string Path; @@ -174,10 +176,16 @@ namespace Shadowsocks.Controller if (_config.enabled) { SystemProxy.Enable(); + _systemProxyIsDirty = true; } else { - SystemProxy.Disable(); + // only switch it off if we have switched it on + if (_systemProxyIsDirty) + { + SystemProxy.Disable(); + _systemProxyIsDirty = false; + } } } diff --git a/shadowsocks-csharp/Properties/AssemblyInfo.cs b/shadowsocks-csharp/Properties/AssemblyInfo.cs index e65ce0b3..47f94a5e 100755 --- a/shadowsocks-csharp/Properties/AssemblyInfo.cs +++ b/shadowsocks-csharp/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.10")] +[assembly: AssemblyVersion("2.0.11")] // [assembly: AssemblyFileVersion("2.0.0")]