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); + } + } } }