aboutsummaryrefslogtreecommitdiff
path: root/RSSDP
diff options
context:
space:
mode:
authorBond_009 <Bond.009@outlook.com>2019-02-24 03:16:19 +0100
committerBond-009 <bond.009@outlook.com>2019-03-25 21:33:48 +0100
commit2696ac5eacfb4702d629bc06a8b42b868c316116 (patch)
treeafbd4501aa7bc55a4c5b04d1e0e357ec7acebfa3 /RSSDP
parent5024c52c60617fffc09ee7b6eeabe0ac400bae75 (diff)
Lower the amount of running tasks
Diffstat (limited to 'RSSDP')
-rw-r--r--RSSDP/HttpParserBase.cs6
-rw-r--r--RSSDP/SsdpCommunicationsServer.cs21
2 files changed, 10 insertions, 17 deletions
diff --git a/RSSDP/HttpParserBase.cs b/RSSDP/HttpParserBase.cs
index 18712470d..76d816e7b 100644
--- a/RSSDP/HttpParserBase.cs
+++ b/RSSDP/HttpParserBase.cs
@@ -23,8 +23,6 @@ namespace Rssdp.Infrastructure
#region Public Methods
- private static byte[] EmptyByteArray = new byte[]{};
-
/// <summary>
/// Parses the <paramref name="data"/> provided into either a <see cref="HttpRequestMessage"/> or <see cref="HttpResponseMessage"/> object.
/// </summary>
@@ -46,7 +44,7 @@ namespace Rssdp.Infrastructure
if (data.Length == 0) throw new ArgumentException("data cannot be an empty string.", nameof(data));
if (!LineTerminators.Any(data.Contains)) throw new ArgumentException("data is not a valid request, it does not contain any CRLF/LF terminators.", nameof(data));
- using (var retVal = new ByteArrayContent(EmptyByteArray))
+ using (var retVal = new ByteArrayContent(Array.Empty<byte>()))
{
var lines = data.Split(LineTerminators, StringSplitOptions.None);
@@ -209,4 +207,4 @@ namespace Rssdp.Infrastructure
#endregion
}
-} \ No newline at end of file
+}
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs
index d9a4b6ac0..5d2afc37a 100644
--- a/RSSDP/SsdpCommunicationsServer.cs
+++ b/RSSDP/SsdpCommunicationsServer.cs
@@ -355,7 +355,7 @@ namespace Rssdp.Infrastructure
{
var socket = _SocketFactory.CreateUdpMulticastSocket(SsdpConstants.MulticastLocalAdminAddress, _MulticastTtl, SsdpConstants.MulticastPort);
- ListenToSocket(socket);
+ _ = ListenToSocketInternal(socket);
return socket;
}
@@ -389,19 +389,12 @@ namespace Rssdp.Infrastructure
foreach (var socket in sockets)
{
- ListenToSocket(socket);
+ _ = ListenToSocketInternal(socket);
}
return sockets;
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "t", Justification = "Capturing task to local variable removes compiler warning, task is not otherwise required.")]
- private void ListenToSocket(ISocket socket)
- {
- // Tasks are captured to local variables even if we don't use them just to avoid compiler warnings.
- var t = Task.Run(() => ListenToSocketInternal(socket));
- }
-
private async Task ListenToSocketInternal(ISocket socket)
{
var cancelled = false;
@@ -448,10 +441,10 @@ namespace Rssdp.Infrastructure
private void ProcessMessage(string data, IpEndPointInfo endPoint, IpAddressInfo receivedOnLocalIpAddress)
{
- //Responses start with the HTTP version, prefixed with HTTP/ while
- //requests start with a method which can vary and might be one we haven't
- //seen/don't know. We'll check if this message is a request or a response
- //by checking for the HTTP/ prefix on the start of the message.
+ // Responses start with the HTTP version, prefixed with HTTP/ while
+ // requests start with a method which can vary and might be one we haven't
+ // seen/don't know. We'll check if this message is a request or a response
+ // by checking for the HTTP/ prefix on the start of the message.
if (data.StartsWith("HTTP/", StringComparison.OrdinalIgnoreCase))
{
HttpResponseMessage responseMessage = null;
@@ -465,7 +458,9 @@ namespace Rssdp.Infrastructure
}
if (responseMessage != null)
+ {
OnResponseReceived(responseMessage, endPoint, receivedOnLocalIpAddress);
+ }
}
else
{