Skip to content

Commit

Permalink
Fix check for non disposed socket (instead of connected)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusfriedman committed Nov 21, 2023
1 parent 89f7de7 commit 42e4958
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Common/Extensions/SocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ public static int AlignedReceive(byte[] buffer, int offset, int amount, System.N
while (amount > 0) //poll write 0
{
//Receive it into the buffer at the given offset taking into account what was already received
if (socket.Connected) justReceived = socket.Receive(buffer, offset, amount, System.Net.Sockets.SocketFlags.None, out error);
if (socket.IsNullOrDisposed() is false) justReceived = socket.Receive(buffer, offset, amount, System.Net.Sockets.SocketFlags.None, out error);
else justReceived = 0;

//Determine how to continue
Expand Down
4 changes: 3 additions & 1 deletion Rtp/RtpClient.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The above copyright notice and this permission notice shall be included in all c
*
* v//
*/
using Media.Common.Extensions.Socket;

namespace Media.Rtp
{
/// <summary>
Expand Down Expand Up @@ -1471,7 +1473,7 @@ int ReadApplicationLayerFraming(ref int received, ref int sessionRequired, ref i
//{

do received += justRecieved = socket.ReceiveFrom(buffer.Array, buffer.Offset + received, buffer.Count - received, System.Net.Sockets.SocketFlags.None, ref remote);
while (received is 0 /*|| justRecieved > 0 && received + justRecieved < pmax*/ && socket.Connected);
while (socket.IsNullOrDisposed() is false && received is 0 /*|| justRecieved > 0 && received + justRecieved < pmax && socket.Connected*/);

////Lookup the context to determine if the packet will fit
//var context = GetContextBySocket(socket);
Expand Down
14 changes: 7 additions & 7 deletions UnitTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static async Task Main(string[] args)

RunTest(async () =>
{
await RunTestAsync(TestServerAsync);
await RunTestAsync(TestServerAsync, nameof(TestServerAsync));
});
}

Expand Down Expand Up @@ -4629,10 +4629,10 @@ static void RunTest(Action test, int count = 1, bool waitForGoAhead = true)
System.Console.Clear();
Console.WriteLine("About to run test: " + test.Method.Name);
Console.WriteLine("Press Q to skip or any other key to continue.");
RunTestAsync(() => { test(); return Task.CompletedTask; }, count, waitForGoAhead).GetAwaiter().GetResult();
RunTestAsync(() => { test(); return Task.CompletedTask; }, test.Method.Name, count, waitForGoAhead).GetAwaiter().GetResult();
}

static async Task RunTestAsync(Func<Task> test, int count = 1, bool waitForGoAhead = true)
static async Task RunTestAsync(Func<Task> test, string testMethodName, int count = 1, bool waitForGoAhead = true)
{
//If the debugger is attached get a ConsoleKey, the key is Q return.
if (waitForGoAhead && /*System.Diagnostics.Debugger.IsAttached && */ Console.ReadKey(true).Key == ConsoleKey.Q) return;
Expand All @@ -4652,12 +4652,12 @@ static async Task RunTestAsync(Func<Task> test, int count = 1, bool waitForGoAhe
//Decrement remaining
--remaining;

TraceMessage("Beginning Test '" + testIndex + "'");
TraceMessage("Beginning Test '" + testIndex + "'" + testMethodName);

//Run the test
await test();
await test().ConfigureAwait(false);

TraceMessage("Completed Test'" + testIndex + "'");
TraceMessage("Completed Test'" + testIndex + "'" + testMethodName);

//Increment the success counter
++successes;
Expand Down Expand Up @@ -4706,7 +4706,7 @@ static async Task RunTestAsync(Func<Task> test, int count = 1, bool waitForGoAhe
{
case ConsoleKey.W:
{
await RunTestAsync(test, 1, false).ConfigureAwait(false);
await RunTestAsync(test, testMethodName, 1, false).ConfigureAwait(false);
return;
}
case ConsoleKey.D:
Expand Down

0 comments on commit 42e4958

Please sign in to comment.