Procházet zdrojové kódy

Fix coming back from sleep error

Nick Babcock před 6 roky
rodič
revize
03cc15139c
1 změnil soubory, kde provedl 9 přidání a 1 odebrání
  1. 9 1
      OhmGraphite/GraphiteWriter.cs

+ 9 - 1
OhmGraphite/GraphiteWriter.cs

@@ -43,9 +43,17 @@ namespace OhmGraphite
                     Logger.Debug($"New connection to {_remoteHost}:{_remotePort}");
                     _client.Close();
                     _client = new TcpClient();
+                }
+
+                // When coming back from sleep they'll be "the operation is
+                // not allowed on non-connected sockets" so decouple
+                // connection from tcp client instantiation so that we can use
+                // the same tcp client whether it's disconnected or not
+                if (!_client.Connected)
+                {
                     await _client.ConnectAsync(_remoteHost, _remotePort);
                 }
-            
+
                 using (var writer = new StreamWriter(_client.GetStream(), Encoding.Default, 0x1000, true))
                 {
                     foreach (var sensor in sensors)