From 1a4b9aa04a515a353f56525f8db137600e5bdf46 Mon Sep 17 00:00:00 2001 From: oldrev Date: Sat, 12 Dec 2020 16:40:41 +0800 Subject: [PATCH] code cleaning --- .../Airkiss/AirkissSmartConfigProvider.cs | 4 ++-- .../Esptouch/EspSmartConfigProvider.cs | 4 ++-- .../Networking/DatagramBroadcaster.cs | 11 +++++++++-- .../Networking/DefaultDatagramClient.cs | 15 --------------- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Sandwych.SmartConfig/Airkiss/AirkissSmartConfigProvider.cs b/src/Sandwych.SmartConfig/Airkiss/AirkissSmartConfigProvider.cs index e389cda..b7a4bc2 100644 --- a/src/Sandwych.SmartConfig/Airkiss/AirkissSmartConfigProvider.cs +++ b/src/Sandwych.SmartConfig/Airkiss/AirkissSmartConfigProvider.cs @@ -1,4 +1,4 @@ -using Sandwych.SmartConfig.Airkiss.Protocol; +using Sandwych.SmartConfig.Airkiss.Protocol; using Sandwych.SmartConfig.Protocol; using System; using System.Collections.Generic; @@ -15,7 +15,7 @@ public class AirkissSmartConfigProvider : AbstractSmartConfigProvider { yield return (StandardOptionNames.BroadcastingTargetPort, 10001); // The port to broadcast doesn't matter yield return (StandardOptionNames.ListeningPort, 10000); - yield return (StandardOptionNames.FrameInterval, TimeSpan.FromMilliseconds(0)); + yield return (StandardOptionNames.FrameInterval, TimeSpan.Zero); yield return (StandardOptionNames.SegmentInterval, TimeSpan.FromMilliseconds(5)); yield return (StandardOptionNames.GuideCodeTimeout, TimeSpan.FromSeconds(2)); diff --git a/src/Sandwych.SmartConfig/Esptouch/EspSmartConfigProvider.cs b/src/Sandwych.SmartConfig/Esptouch/EspSmartConfigProvider.cs index 6b0c7f3..4fe1ded 100644 --- a/src/Sandwych.SmartConfig/Esptouch/EspSmartConfigProvider.cs +++ b/src/Sandwych.SmartConfig/Esptouch/EspSmartConfigProvider.cs @@ -1,4 +1,4 @@ -using Sandwych.SmartConfig.Esptouch.Protocol; +using Sandwych.SmartConfig.Esptouch.Protocol; using Sandwych.SmartConfig.Protocol; using System; using System.Collections.Generic; @@ -16,7 +16,7 @@ public override IDevicePacketInterpreter CreateDevicePacketInterpreter() { yield return (StandardOptionNames.BroadcastingTargetPort, 7001); yield return (StandardOptionNames.ListeningPort, 18266); - yield return (StandardOptionNames.FrameInterval, TimeSpan.FromMilliseconds(8)); + yield return (StandardOptionNames.FrameInterval, TimeSpan.Zero); yield return (StandardOptionNames.SegmentInterval, TimeSpan.FromMilliseconds(8)); yield return (StandardOptionNames.GuideCodeTimeout, TimeSpan.FromSeconds(2)); yield return (EspOptionNames.DatumPeriodTimeout, TimeSpan.FromSeconds(4)); diff --git a/src/Sandwych.SmartConfig/Networking/DatagramBroadcaster.cs b/src/Sandwych.SmartConfig/Networking/DatagramBroadcaster.cs index ca78cb9..e38202e 100644 --- a/src/Sandwych.SmartConfig/Networking/DatagramBroadcaster.cs +++ b/src/Sandwych.SmartConfig/Networking/DatagramBroadcaster.cs @@ -74,10 +74,16 @@ private async Task BroadcastProcedureAsync( await this.BroadcastSegmentUntilAsync( context, segment, broadcastBuffer, userCancelToken); } - await Task.Delay(segmentInterval, userCancelToken); + if (segmentInterval > TimeSpan.Zero) + { + await Task.Delay(segmentInterval, userCancelToken); + } } - await Task.Delay(segmentInterval, userCancelToken); + if (segmentInterval > TimeSpan.Zero) + { + await Task.Delay(segmentInterval, userCancelToken); + } } } @@ -98,6 +104,7 @@ private async Task BroadcastSegmentByTimesAsync( var segmentInterval = context.GetOption(StandardOptionNames.FrameInterval); for (int i = 0; i < segment.BroadcastingMaxTimes; i++) { + token.ThrowIfCancellationRequested(); await this.BroadcastSingleSegmentAsync(segment, broadcastBuffer, segmentInterval, token); } } diff --git a/src/Sandwych.SmartConfig/Networking/DefaultDatagramClient.cs b/src/Sandwych.SmartConfig/Networking/DefaultDatagramClient.cs index f7b906c..66cc0b5 100644 --- a/src/Sandwych.SmartConfig/Networking/DefaultDatagramClient.cs +++ b/src/Sandwych.SmartConfig/Networking/DefaultDatagramClient.cs @@ -41,20 +41,5 @@ public void Dispose() _udp.Dispose(); } - private static int GetFirstWifiInterfaceIndex() - { - var adapters = NetworkInterface.GetAllNetworkInterfaces(); - var wifi = adapters.Where( - x => x.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 - && x.OperationalStatus == OperationalStatus.Up - && !x.IsReceiveOnly - ).FirstOrDefault(); - if(wifi == null) - { - throw new IOException("Cannot find available WiFi interface"); - } - return wifi.GetIPProperties().GetIPv4Properties().Index; - } - } }