From e7dfe97c6df90aaf4d3ca752cddc42f4b882d683 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 12 Feb 2024 17:30:56 +0000 Subject: [PATCH] refactor!: remove TSend generic parameter from SendAndReceiveAsync --- TcpDotNet.ClientIntegrationTest/Program.cs | 4 ++-- TcpDotNet/BaseClientNode.cs | 4 +--- TcpDotNet/ProtocolClient.cs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/TcpDotNet.ClientIntegrationTest/Program.cs b/TcpDotNet.ClientIntegrationTest/Program.cs index ada9729..0ecd968 100644 --- a/TcpDotNet.ClientIntegrationTest/Program.cs +++ b/TcpDotNet.ClientIntegrationTest/Program.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using TcpDotNet; using TcpDotNet.ClientIntegrationTest; using TcpDotNet.ClientIntegrationTest.PacketHandlers; @@ -17,7 +17,7 @@ Console.WriteLine($"Connected to {client.RemoteEndPoint}. My session is {client. var ping = new PingPacket(); Console.WriteLine($"Sending ping packet with payload: {BitConverter.ToString(ping.Payload)}"); -var pong = await client.SendAndReceiveAsync(ping); +var pong = await client.SendAndReceiveAsync(ping); Console.WriteLine($"Received pong packet with payload: {BitConverter.ToString(pong.Payload)}"); Console.WriteLine(pong.Payload.SequenceEqual(ping.Payload) ? "Payload matches!" : "Payload does not match!"); diff --git a/TcpDotNet/BaseClientNode.cs b/TcpDotNet/BaseClientNode.cs index 9670bb0..c1df784 100644 --- a/TcpDotNet/BaseClientNode.cs +++ b/TcpDotNet/BaseClientNode.cs @@ -221,15 +221,13 @@ public abstract class BaseClientNode : Node /// /// The packet to send. /// A cancellation token that can be used to cancel the asynchronous operation. - /// The type of the packet to send. /// The type of the packet to return. /// The received packet. /// /// This method will consume all incoming packets, raising their associated handlers if such packets are recognised. /// - public async Task SendAndReceiveAsync(TSend packetToSend, + public async Task SendAndReceiveAsync(Packet packetToSend, CancellationToken cancellationToken = default) - where TSend : Packet where TReceive : Packet { var attribute = typeof(TReceive).GetCustomAttribute(); diff --git a/TcpDotNet/ProtocolClient.cs b/TcpDotNet/ProtocolClient.cs index 1294eb8..ff9979b 100644 --- a/TcpDotNet/ProtocolClient.cs +++ b/TcpDotNet/ProtocolClient.cs @@ -96,7 +96,7 @@ public sealed class ProtocolClient : BaseClientNode State = ClientState.Handshaking; var handshakeRequest = new HandshakeRequestPacket(ProtocolVersion); var handshakeResponse = - await SendAndReceiveAsync(handshakeRequest, cancellationToken); + await SendAndReceiveAsync(handshakeRequest, cancellationToken); if (handshakeResponse.HandshakeResponse != HandshakeResponse.Success) {