NetSharp

NetSharp.git
git clone git://git.lenczewski.org/NetSharp.git
Log | Files | Refs | README | LICENSE

commit 8f7f63eb48376ec161dec362707e04dcaed88afc
parent 714643f70efea0a1cf36457a3ad6bbec4733cb7b
Author: Mikolaj Lenczewski <33129490+EnderRifter@users.noreply.github.com>
Date:   Thu, 27 Feb 2020 22:14:38 +0000

Basic implementation of SocketAsyncEventArgs!

Diffstat:
MNetSharp/NetSharp/Connection.cs | 286++++++++++++++++++++++++++++----------------------------------------------------
ANetSharp/NetSharp/ConnectionFactory.cs | 37+++++++++++++++++++++++++++++++++++++
MNetSharp/NetSharp/Deprecated/Client.cs | 15+++------------
MNetSharp/NetSharp/Deprecated/ClientExtensions.cs | 3+--
MNetSharp/NetSharp/Deprecated/DefaultSocketOptions.cs | 2+-
MNetSharp/NetSharp/Deprecated/IClient.cs | 2+-
MNetSharp/NetSharp/Deprecated/INetworkSerialisable.cs | 2+-
MNetSharp/NetSharp/Deprecated/IPacket.cs | 2+-
MNetSharp/NetSharp/Deprecated/IPacketHandler.cs | 2+-
MNetSharp/NetSharp/Deprecated/IRequestPacket.cs | 2+-
MNetSharp/NetSharp/Deprecated/IResponsePacket.cs | 2+-
MNetSharp/NetSharp/Deprecated/IServer.cs | 2+-
MNetSharp/NetSharp/Deprecated/SerialisedPacket.cs | 4++--
MNetSharp/NetSharp/Deprecated/Server.cs | 15++++++---------
ANetSharp/NetSharp/Deprecated/ServerClientConnection.cs | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MNetSharp/NetSharp/Deprecated/ServerExtensions.cs | 3+--
MNetSharp/NetSharp/Deprecated/SocketOptions.cs | 6+++---
MNetSharp/NetSharp/Deprecated/TcpClient.cs | 15++++++---------
MNetSharp/NetSharp/Deprecated/TcpServer.cs | 15+++++----------
MNetSharp/NetSharp/Deprecated/TcpSocketOptions.cs | 2+-
MNetSharp/NetSharp/Deprecated/UdpClient.cs | 19+++++++------------
MNetSharp/NetSharp/Deprecated/UdpServer.cs | 23+++++++++--------------
MNetSharp/NetSharp/Deprecated/UdpSocketOptions.cs | 2+-
ANetSharp/NetSharp/Extensions/ConnectionExtensions.cs | 17+++++++++++++++++
MNetSharp/NetSharp/NetSharp.csproj | 1-
MNetSharp/NetSharp/NetSharp.xml | 1943+++++++++++++++++++++++++++++++++++++------------------------------------------
MNetSharp/NetSharp/Packets/Builtin/ConnectPacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/ConnectResponsePacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/DataPacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/DataResponsePacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/DisconnectPacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/PingPacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/PingResponsePacket.cs | 2+-
MNetSharp/NetSharp/Packets/Builtin/SimpleDataPacket.cs | 2+-
MNetSharp/NetSharp/Packets/NetworkPacket.cs | 10+++++-----
MNetSharp/NetSharp/Packets/PacketRegistry.cs | 2+-
MNetSharp/NetSharp/Packets/PacketTypeIdAttribute.cs | 2+-
ANetSharp/NetSharp/Pipelines/PacketPipeline.cs | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MNetSharp/NetSharp/Sockets/SocketAcceptor.cs | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
MNetSharp/NetSharp/Sockets/SocketReader.cs | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
MNetSharp/NetSharp/Sockets/SocketWriter.cs | 45+++++++++++++++++++++++++++++++++++++++------
DNetSharp/NetSharp/Utils/NetworkOperationsManager.cs | 331-------------------------------------------------------------------------------
ANetSharp/NetSharp/Utils/RingBuffer.cs | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
MNetSharp/NetSharp/Utils/TransmissionResult.cs | 24++++++++++++------------
MNetSharp/NetSharpExamples/Program.cs | 145++++++++++++++++++++++++++++++-------------------------------------------------
45 files changed, 1600 insertions(+), 1768 deletions(-)

diff --git a/NetSharp/NetSharp/Connection.cs b/NetSharp/NetSharp/Connection.cs @@ -1,260 +1,172 @@ using System; +using System.Collections.Concurrent; using System.IO; using System.Net; using System.Net.Sockets; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using NetSharp.Logging; using NetSharp.Packets; +using NetSharp.Sockets; using NetSharp.Utils; namespace NetSharp { - /// <summary> - /// Base class for connections, holding methods shared between the <see cref="Client"/> and <see cref="Server"/> classes. - /// </summary> - public abstract class Connection : IDisposable + public class Connection : IDisposable { - /// <summary> - /// Provides a wrapper around common network operations and enables awaiting for said operations. - /// </summary> - private readonly NetworkOperationsManager networkManager; + private readonly SocketAcceptor acceptor; + private readonly ConcurrentDictionary<EndPoint, Connection> connections; + private readonly CancellationTokenSource connectionShutdownTokenSource; + private readonly SocketReader listener; + private readonly Socket socket; + private readonly SocketWriter transmitter; /// <summary> - /// The logger to which the server can log messages. + /// Destroys a <see cref="Connection"/> class instance, freeing all managed resources. /// </summary> - protected Logger logger; + ~Connection() + { + Dispose(false); + } + + protected readonly CancellationToken ShutdownToken; /// <summary> - /// Initialises a new instance of the <see cref="Connection"/> class. + /// A logger object allowing for writing debug messages to an output stream. /// </summary> - protected Connection() - { - networkManager = new NetworkOperationsManager(); - - logger = new Logger(Stream.Null); - } + protected Logger logger; /// <summary> - /// Disposes of this <see cref="Connection"/> instance. + /// Disposes of the managed and unmanaged resources held by this instance. /// </summary> - /// <param name="disposing">Whether this instance is being disposed.</param> + /// <param name="disposing">Whether this method is called by <see cref="Dispose()"/> or by the finaliser.</param> protected virtual void Dispose(bool disposing) { if (disposing) { - logger.Dispose(); + socket.Dispose(); } } - /// <summary> - /// Listens for a packet to be received from the network. - /// </summary> - /// <param name="socket">The remote socket from which to receive data.</param> - /// <param name="socketFlags">The socket flags associated with the read operation.</param> - /// <param name="timeout"> - /// The timespan within which the packet should be received. After this timespan elapses, the receive task is cancelled. - /// </param> - /// <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - /// <returns>The packet that was received.</returns> - protected async Task<SerialisedPacket> DoReceivePacketAsync(Socket socket, SocketFlags socketFlags, TimeSpan timeout, - CancellationToken cancellationToken = default) + internal Connection(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, + int objectPoolSize = 10, bool preallocateBuffers = false, Stream? loggingStream = default, + LogLevel minimumLoggedSeverity = LogLevel.Info) { - using CancellationTokenSource timeoutCancellationTokenSource = new CancellationTokenSource(timeout); - using CancellationTokenSource cts = - CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, cancellationToken); + connectionShutdownTokenSource = new CancellationTokenSource(); + ShutdownToken = connectionShutdownTokenSource.Token; - throw new NotImplementedException(); + socket = new Socket(addressFamily, socketType, protocolType); - try - { - //(SerialisedPacket packet, EndPoint endPoint) = await NetworkOperationsManager.ReadPacketAsync(socket, socketFlags, cts.Token); + acceptor = new SocketAcceptor(objectPoolSize); + listener = new SocketReader(NetworkPacket.PacketSize, objectPoolSize, preallocateBuffers); + transmitter = new SocketWriter(NetworkPacket.PacketSize, objectPoolSize, preallocateBuffers); - //OnBytesReceived(endPoint, packet.Contents.Length); + connections = new ConcurrentDictionary<EndPoint, Connection>(); - // return packet; - } - catch (SocketException ex) - { - logger.LogException($"Socket exception while reading bytes from {socket.RemoteEndPoint}:", ex); - return SerialisedPacket.Null; - } - catch (Exception ex) - { - logger.LogException($"Exception while reading bytes from {socket.RemoteEndPoint}:", ex); - return SerialisedPacket.Null; - } + logger = new Logger(loggingStream ?? Stream.Null, minimumLoggedSeverity); } - /// <summary> - /// Listens for a packet to be received from the network. - /// </summary> - /// <param name="socket">The socket which will receive the packet.</param> - /// <param name="remoteEndPoint">The remote endpoint from which to receive the packet.</param> - /// <param name="socketFlags">The socket flags associated with the read operation.</param> - /// <param name="timeout"> - /// The timespan within which the packet should be received. After this timespan elapses, the receive task is cancelled. - /// </param> - /// <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - /// <returns> - /// The packet that was received and the associated transmission result. <see cref="NullPacket"/> if not received correctly. - /// </returns> - protected async Task<(SerialisedPacket packet, EndPoint remoteEndPoint)> DoReceivePacketFromAsync(Socket socket, EndPoint remoteEndPoint, SocketFlags socketFlags, - TimeSpan timeout, CancellationToken cancellationToken = default) + /// <inheritdoc /> + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + public Task<TransmissionResult> ReceiveAsync(Memory<byte> inputBuffer, SocketFlags flags) + => ReceiveAsync(inputBuffer, flags, Timeout.InfiniteTimeSpan); + + public Task<TransmissionResult> ReceiveAsync(Memory<byte> inputBuffer, SocketFlags flags, TimeSpan timeout) { using CancellationTokenSource timeoutCancellationTokenSource = new CancellationTokenSource(timeout); using CancellationTokenSource cts = - CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, cancellationToken); + CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, ShutdownToken); - throw new NotImplementedException(); + return listener.ReceiveAsync(socket, flags, inputBuffer, cts.Token); + } - try - { - //(SerialisedPacket packet, EndPoint endPoint) = await NetworkOperationsManager.ReadPacketFromAsync(socket, remoteEndPoint, socketFlags, cts.Token); + public Task<TransmissionResult> ReceiveFromAsync(EndPoint remoteEndPoint, Memory<byte> inputBuffer, SocketFlags flags) + => ReceiveFromAsync(remoteEndPoint, inputBuffer, flags, Timeout.InfiniteTimeSpan); - //OnBytesReceived(endPoint, packet.Contents.Length); + public Task<TransmissionResult> ReceiveFromAsync(EndPoint remoteEndPoint, Memory<byte> inputBuffer, SocketFlags flags, TimeSpan timeout) + { + using CancellationTokenSource timeoutCancellationTokenSource = new CancellationTokenSource(timeout); + using CancellationTokenSource cts = + CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, ShutdownToken); - //return (packet, remoteEndPoint); - } - catch (SocketException ex) - { - logger.LogException($"Socket exception while reading bytes from {remoteEndPoint}:", ex); - return (SerialisedPacket.Null, new IPEndPoint(IPAddress.None, IPEndPoint.MinPort)); - } - catch (Exception ex) - { - logger.LogException($"Exception while reading bytes from {remoteEndPoint}:", ex); - return (SerialisedPacket.Null, new IPEndPoint(IPAddress.None, IPEndPoint.MinPort)); - } + return listener.ReceiveFromAsync(socket, remoteEndPoint, flags, inputBuffer, cts.Token); } - /// <summary> - /// Sends the given packet to the network. - /// </summary> - /// <param name="remoteSocket">The remote socket to which to send the packet.</param> - /// <param name="packet">The packet to send.</param> - /// <param name="socketFlags">The socket flags associated with the write operation.</param> - /// <param name="timeout"> - /// The timespan within which the packet should be received. After this timespan elapses, the send task is cancelled. - /// </param> - /// <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - /// <returns>Whether the packet was successfully sent.</returns> - protected async Task<bool> DoSendPacketAsync(Socket remoteSocket, SerialisedPacket packet, SocketFlags socketFlags, TimeSpan timeout, - CancellationToken cancellationToken = default) + public Task<int> SendAsync(Memory<byte> outputBuffer, SocketFlags flags) + => SendAsync(outputBuffer, flags, Timeout.InfiniteTimeSpan); + + public Task<int> SendAsync(Memory<byte> outputBuffer, SocketFlags flags, TimeSpan timeout) { using CancellationTokenSource timeoutCancellationTokenSource = new CancellationTokenSource(timeout); using CancellationTokenSource cts = - CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, cancellationToken); + CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, ShutdownToken); - throw new NotImplementedException(); + return transmitter.SendAsync(socket, flags, outputBuffer, cts.Token); + } - try - { - //await NetworkOperationsManager.WritePacketAsync(remoteSocket, packet, socketFlags, cts.Token); + public Task<int> SendToAsync(EndPoint remoteEndPoint, Memory<byte> outputBuffer, SocketFlags flags) + => SendToAsync(remoteEndPoint, outputBuffer, flags, Timeout.InfiniteTimeSpan); - OnBytesSent(remoteSocket.RemoteEndPoint, packet.Contents.Length); + public Task<int> SendToAsync(EndPoint remoteEndPoint, Memory<byte> outputBuffer, SocketFlags flags, TimeSpan timeout) + { + using CancellationTokenSource timeoutCancellationTokenSource = new CancellationTokenSource(timeout); + using CancellationTokenSource cts = + CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, ShutdownToken); - return true; - } - catch (SocketException ex) - { - logger.LogException($"Socket exception while sending bytes to {remoteSocket.RemoteEndPoint}:", ex); - return false; - } - catch (Exception ex) - { - logger.LogException($"Exception while sending bytes to {remoteSocket.RemoteEndPoint}:", ex); - return false; - } + return transmitter.SendToAsync(socket, remoteEndPoint, flags, outputBuffer, cts.Token); + } + + public void SetLoggingStream(Stream? loggingStream, LogLevel minimumLoggedSeverity = LogLevel.Info) + { + logger = new Logger(loggingStream ?? Stream.Null, minimumLoggedSeverity); } /// <summary> - /// Sends the given packet to the network. + /// Attempts to synchronously bind the underlying socket to the given local endpoint. Blocks. + /// If the timeout is exceeded the binding attempt is aborted and the method returns false. + /// </summary> + /// <param name="localEndPoint">The local endpoint to bind to.</param> + /// <param name="timeout">The timeout within which to attempt the binding.</param> + /// <returns>Whether the binding was successful or not.</returns> + public bool TryBind(EndPoint localEndPoint, TimeSpan timeout) => + TryBindAsync(localEndPoint, timeout).Result; + + /// <summary> + /// Attempts to asynchronously bind the underlying socket to the given local endpoint. Does not block. + /// If the timeout is exceeded the binding attempt is aborted and the method returns false. /// </summary> - /// <param name="socket">The socket which should send the packet.</param> - /// <param name="remoteEndPoint">The remote endpoint to which to send the packet.</param> - /// <param name="packet">The packet to send.</param> - /// <param name="socketFlags">The socket flags associated with the write operation.</param> - /// <param name="timeout"> - /// The timespan within which the packet should be received. After this timespan elapses, the send task is cancelled. - /// </param> - /// <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - /// <returns>Whether the packet was successfully sent.</returns> - protected async Task<bool> DoSendPacketToAsync(Socket socket, EndPoint remoteEndPoint, SerialisedPacket packet, SocketFlags socketFlags, - TimeSpan timeout, CancellationToken cancellationToken = default) + /// <param name="localEndPoint">The local endpoint to bind to.</param> + /// <param name="timeout">The timeout within which to attempt the binding.</param> + /// <returns>Whether the binding was successful or not.</returns> + public async Task<bool> TryBindAsync(EndPoint localEndPoint, TimeSpan timeout) { using CancellationTokenSource timeoutCancellationTokenSource = new CancellationTokenSource(timeout); using CancellationTokenSource cts = - CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, cancellationToken); - - throw new NotImplementedException(); + CancellationTokenSource.CreateLinkedTokenSource(timeoutCancellationTokenSource.Token, ShutdownToken); try { - //await NetworkOperationsManager.WritePacketToAsync(socket, remoteEndPoint, packet, socketFlags, cts.Token); - - OnBytesSent(remoteEndPoint, packet.Contents.Length); + return await Task.Run(() => + { + socket.Bind(localEndPoint); - return true; + return true; + }, cts.Token); } - catch (SocketException ex) + catch (TaskCanceledException) { - logger.LogException($"Socket exception while sending bytes to {remoteEndPoint}:", ex); return false; } - catch (Exception ex) + catch (SocketException ex) { - logger.LogException($"Exception while sending bytes to {remoteEndPoint}:", ex); + logger.LogException($"Socket exception on binding socket to {localEndPoint}:", ex); return false; } } - - /// <summary> - /// Invokes the <see cref="BytesReceived"/> event. - /// </summary> - /// <param name="remoteEndPoint">The remote endpoint from which the bytes were received.</param> - /// <param name="bytesReceived">The number of bytes that were received from the remote endpoint.</param> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected void OnBytesReceived(EndPoint remoteEndPoint, int bytesReceived) => - BytesReceived?.Invoke(remoteEndPoint, bytesReceived); - - /// <summary> - /// Invokes the <see cref="BytesSent"/> event. - /// </summary> - /// <param name="remoteEndPoint">The remote endpoint to which the bytes were sent.</param> - /// <param name="bytesSent">The number of bytes that were sent to the remote endpoint.</param> - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected void OnBytesSent(EndPoint remoteEndPoint, int bytesSent) => - BytesSent?.Invoke(remoteEndPoint, bytesSent); - - /// <summary> - /// Signifies that some data has been received from the remote endpoint. - /// </summary> - public event Action<EndPoint, int>? BytesReceived; - - /// <summary> - /// Signifies that some data was sent to the remote endpoint. - /// </summary> - public event Action<EndPoint, int>? BytesSent; - - /// <summary> - /// Makes the client log to the given stream. - /// </summary> - /// <param name="loggingStream">The stream that new messages should be logged to.</param> - /// <param name="minimumMessageSeverityLevel"> - /// The minimum severity level that new messages must have to be logged to the stream. - /// </param> - public void ChangeLoggingStream(Stream loggingStream, LogLevel minimumMessageSeverityLevel = LogLevel.Info) - { - logger = new Logger(loggingStream, minimumMessageSeverityLevel); - } - - /// <inheritdoc /> - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } } } \ No newline at end of file diff --git a/NetSharp/NetSharp/ConnectionFactory.cs b/NetSharp/NetSharp/ConnectionFactory.cs @@ -0,0 +1,36 @@ +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using NetSharp.Logging; + +namespace NetSharp +{ + /// <summary> + /// Provides methods to construct and configure <see cref="Connection"/> instances. + /// </summary> + public static class ConnectionFactory + { + public static Connection Init(EndPoint localEndPoint, AddressFamily connectionAddressFamily, + SocketType connectionSocketType, ProtocolType connectionProtocolType, TimeSpan timeout, int objectPoolSize = 10, + bool preallocateBuffers = false, Stream? loggingStream = default, LogLevel minimumLoggedSeverity = LogLevel.Info) + { + Connection connection = new Connection(connectionAddressFamily, connectionSocketType, + connectionProtocolType, objectPoolSize, preallocateBuffers, loggingStream, minimumLoggedSeverity); + + connection.TryBind(localEndPoint, timeout); + + return connection; + } + + public static Connection InitTcp(EndPoint remoteEndPoint, int objectPoolSize = 10, bool preallocateBuffers = false, + Stream? loggingStream = default, LogLevel minimumLoggedSeverity = LogLevel.Info) + => Init(remoteEndPoint, AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, TimeSpan.FromSeconds(1), + objectPoolSize, preallocateBuffers, loggingStream, minimumLoggedSeverity); + + public static Connection InitUdp(EndPoint remoteEndPoint, int objectPoolSize = 10, bool preallocateBuffers = false, + Stream? loggingStream = default, LogLevel minimumLoggedSeverity = LogLevel.Info) + => Init(remoteEndPoint, AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp, TimeSpan.FromSeconds(1), + objectPoolSize, preallocateBuffers, loggingStream, minimumLoggedSeverity); + } +} +\ No newline at end of file diff --git a/NetSharp/NetSharp/Deprecated/Client.cs b/NetSharp/NetSharp/Deprecated/Client.cs @@ -4,16 +4,14 @@ using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using NetSharp.Interfaces; using NetSharp.Packets.Builtin; -using NetSharp.Utils.Socket_Options; -namespace NetSharp +namespace NetSharp.Deprecated { /// <summary> /// Provides methods for connecting to and talking with a <see cref="IServer"/> instance. /// </summary> - public abstract class Client : Connection, IClient, IDisposable + public abstract class Client : ServerClientConnection, IClient, IDisposable { /// <summary> /// Initialises a new instance of the <see cref="Client"/> class. @@ -55,16 +53,9 @@ namespace NetSharp /// <param name="socketType">The socket type for the underlying socket.</param> /// <param name="protocolType">The protocol type for the underlying socket.</param> /// <param name="socketManager">The <see cref="Utils.Socket_Options.SocketOptions"/> manager to use.</param> - protected Client(SocketType socketType, ProtocolType protocolType, SocketOptionManager socketManager) : this() + protected Client(SocketType socketType, ProtocolType protocolType) : this() { socket = new Socket(AddressFamily.InterNetwork, socketType, protocolType); - - socketOptions = socketManager switch - { - SocketOptionManager.Tcp => new TcpSocketOptions(ref socket) as SocketOptions, - SocketOptionManager.Udp => new UdpSocketOptions(ref socket) as SocketOptions, - _ => new DefaultSocketOptions(ref socket), - }; } /// <summary> diff --git a/NetSharp/NetSharp/Deprecated/ClientExtensions.cs b/NetSharp/NetSharp/Deprecated/ClientExtensions.cs @@ -2,9 +2,8 @@ using System.Net; using System.Threading; using System.Threading.Tasks; -using NetSharp.Interfaces; -namespace NetSharp.Extensions +namespace NetSharp.Deprecated { /// <summary> /// Provides additional methods and functionality to the <see cref="Client"/> class. diff --git a/NetSharp/NetSharp/Deprecated/DefaultSocketOptions.cs b/NetSharp/NetSharp/Deprecated/DefaultSocketOptions.cs @@ -1,7 +1,7 @@ using System; using System.Net.Sockets; -namespace NetSharp.Utils.Socket_Options +namespace NetSharp.Deprecated { /// <summary> /// Allows for manipulation of socket options. diff --git a/NetSharp/NetSharp/Deprecated/IClient.cs b/NetSharp/NetSharp/Deprecated/IClient.cs @@ -2,7 +2,7 @@ using System.Net; using System.Threading.Tasks; -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes a client capable of asynchronous communication with an <see cref="IServer"/> connection. diff --git a/NetSharp/NetSharp/Deprecated/INetworkSerialisable.cs b/NetSharp/NetSharp/Deprecated/INetworkSerialisable.cs @@ -1,6 +1,6 @@ using System; -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes an object that can be serialised to be sent across the network. diff --git a/NetSharp/NetSharp/Deprecated/IPacket.cs b/NetSharp/NetSharp/Deprecated/IPacket.cs @@ -1,4 +1,4 @@ -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes the methods and properties that every packet diff --git a/NetSharp/NetSharp/Deprecated/IPacketHandler.cs b/NetSharp/NetSharp/Deprecated/IPacketHandler.cs @@ -1,4 +1,4 @@ -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes a class capable of registering and deregistering packet handlers, and capable of diff --git a/NetSharp/NetSharp/Deprecated/IRequestPacket.cs b/NetSharp/NetSharp/Deprecated/IRequestPacket.cs @@ -1,4 +1,4 @@ -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes a request packet. diff --git a/NetSharp/NetSharp/Deprecated/IResponsePacket.cs b/NetSharp/NetSharp/Deprecated/IResponsePacket.cs @@ -1,4 +1,4 @@ -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes a response packet to a request packet. diff --git a/NetSharp/NetSharp/Deprecated/IServer.cs b/NetSharp/NetSharp/Deprecated/IServer.cs @@ -2,7 +2,7 @@ using System.Net; using System.Threading.Tasks; -namespace NetSharp.Interfaces +namespace NetSharp.Deprecated { /// <summary> /// Describes a server capable of asynchronously handling multiple <see cref="IClient"/> connections at once. diff --git a/NetSharp/NetSharp/Deprecated/SerialisedPacket.cs b/NetSharp/NetSharp/Deprecated/SerialisedPacket.cs @@ -1,7 +1,7 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Packets; -namespace NetSharp.Packets +namespace NetSharp.Deprecated { public readonly struct SerialisedPacket { diff --git a/NetSharp/NetSharp/Deprecated/Server.cs b/NetSharp/NetSharp/Deprecated/Server.cs @@ -5,12 +5,10 @@ using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using NetSharp.Interfaces; using NetSharp.Packets; using NetSharp.Packets.Builtin; -using NetSharp.Utils.Socket_Options; -namespace NetSharp +namespace NetSharp.Deprecated { /// <summary> /// Represents a method that receives a request packet of the given type (<typeparamref name="TReq"/>) and @@ -37,7 +35,7 @@ namespace NetSharp /// <summary> /// Provides methods for handling connected <see cref="IClient"/> instances. /// </summary> - public abstract class Server : Connection, IServer, IPacketHandler, IDisposable + public abstract class Server : ServerClientConnection, IServer, IPacketHandler, IDisposable { /// <summary> /// Maps a packet type id to the complex packet handler for that packet type. @@ -175,8 +173,8 @@ namespace NetSharp /// <param name="socketType">The socket type for the underlying socket.</param> /// <param name="protocolType">The protocol type for the underlying socket.</param> /// <param name="socketManager">The <see cref="Utils.Socket_Options.SocketOptions"/> implementation to use.</param> - protected Server(SocketType socketType, ProtocolType protocolType, SocketOptions socketManager) - : this(socketType, protocolType, socketManager, DefaultNetworkOperationTimeout) + protected Server(SocketType socketType, ProtocolType protocolType) + : this(socketType, protocolType, DefaultNetworkOperationTimeout) { } @@ -187,12 +185,11 @@ namespace NetSharp /// <param name="protocolType">The protocol type for the underlying socket.</param> /// <param name="socketManager">The <see cref="Utils.Socket_Options.SocketOptions"/> manager to use.</param> /// <param name="networkOperationTimeout">The timeout value for send and receive operations over the network.</param> - protected Server(SocketType socketType, ProtocolType protocolType, SocketOptions socketManager, - TimeSpan networkOperationTimeout) : this() + protected Server(SocketType socketType, ProtocolType protocolType, TimeSpan networkOperationTimeout) : this() { socket = new Socket(AddressFamily.InterNetwork, socketType, protocolType); - socketOptions = socketManager; + socketOptions = new DefaultSocketOptions(ref socket); NetworkOperationTimeout = networkOperationTimeout; } diff --git a/NetSharp/NetSharp/Deprecated/ServerClientConnection.cs b/NetSharp/NetSharp/Deprecated/ServerClientConnection.cs @@ -0,0 +1,89 @@ +using System; +using System.IO; +using System.Net; +using System.Runtime.CompilerServices; +using NetSharp.Logging; +using NetSharp.Utils; + +namespace NetSharp.Deprecated +{ + /// <summary> + /// Base class for connections, holding methods shared between the <see cref="Client"/> and <see cref="Server"/> classes. + /// </summary> + public abstract class ServerClientConnection : IDisposable + { + /// <summary> + /// The logger to which the server can log messages. + /// </summary> + protected Logger logger; + + /// <summary> + /// Initialises a new instance of the <see cref="ServerClientConnection"/> class. + /// </summary> + protected ServerClientConnection() + { + //networkManager = new NetworkOperationsManager(); + + logger = new Logger(Stream.Null); + } + + /// <summary> + /// Disposes of this <see cref="ServerClientConnection"/> instance. + /// </summary> + /// <param name="disposing">Whether this instance is being disposed.</param> + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + logger.Dispose(); + } + } + + /// <summary> + /// Invokes the <see cref="BytesReceived"/> event. + /// </summary> + /// <param name="remoteEndPoint">The remote endpoint from which the bytes were received.</param> + /// <param name="bytesReceived">The number of bytes that were received from the remote endpoint.</param> + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected void OnBytesReceived(EndPoint remoteEndPoint, int bytesReceived) => + BytesReceived?.Invoke(remoteEndPoint, bytesReceived); + + /// <summary> + /// Invokes the <see cref="BytesSent"/> event. + /// </summary> + /// <param name="remoteEndPoint">The remote endpoint to which the bytes were sent.</param> + /// <param name="bytesSent">The number of bytes that were sent to the remote endpoint.</param> + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected void OnBytesSent(EndPoint remoteEndPoint, int bytesSent) => + BytesSent?.Invoke(remoteEndPoint, bytesSent); + + /// <summary> + /// Signifies that some data has been received from the remote endpoint. + /// </summary> + public event Action<EndPoint, int>? BytesReceived; + + /// <summary> + /// Signifies that some data was sent to the remote endpoint. + /// </summary> + public event Action<EndPoint, int>? BytesSent; + + /// <summary> + /// Makes the client log to the given stream. + /// </summary> + /// <param name="loggingStream">The stream that new messages should be logged to.</param> + /// <param name="minimumMessageSeverityLevel"> + /// The minimum severity level that new messages must have to be logged to the stream. + /// </param> + public void ChangeLoggingStream(Stream loggingStream, LogLevel minimumMessageSeverityLevel = LogLevel.Info) + { + logger = new Logger(loggingStream, minimumMessageSeverityLevel); + } + + /// <inheritdoc /> + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + } +} +\ No newline at end of file diff --git a/NetSharp/NetSharp/Deprecated/ServerExtensions.cs b/NetSharp/NetSharp/Deprecated/ServerExtensions.cs @@ -1,9 +1,8 @@ using System.Net; -using System.Threading; using System.Threading.Tasks; using NetSharp.Utils; -namespace NetSharp.Extensions +namespace NetSharp.Deprecated { /// <summary> /// Provides additional methods and functionality to the <see cref="Server"/> class. diff --git a/NetSharp/NetSharp/Deprecated/SocketOptions.cs b/NetSharp/NetSharp/Deprecated/SocketOptions.cs @@ -1,7 +1,7 @@ using System.Net; using System.Net.Sockets; -namespace NetSharp.Utils.Socket_Options +namespace NetSharp.Deprecated { /// <summary> /// Allows for manipulation of socket options. @@ -31,8 +31,8 @@ namespace NetSharp.Utils.Socket_Options /// Whether sending a packet flushes underlying <see cref="NetworkStream"/>. /// </summary> /// <remarks> - /// This value is only used in a <see cref="TcpClient"/> instance, which uses a <see cref="NetworkStream"/> - /// to send and receive data. A <see cref="UdpClient"/> is unaffected by this value. + /// This value is only used in a <see cref="System.Net.Sockets.TcpClient"/> instance, which uses a <see cref="NetworkStream"/> + /// to send and receive data. A <see cref="System.Net.Sockets.UdpClient"/> is unaffected by this value. /// </remarks> public bool ForceFlush { get; set; } = true; diff --git a/NetSharp/NetSharp/Deprecated/TcpClient.cs b/NetSharp/NetSharp/Deprecated/TcpClient.cs @@ -1,13 +1,10 @@ using System; using System.Net.Sockets; -using System.Threading; using System.Threading.Tasks; using NetSharp.Packets; using NetSharp.Packets.Builtin; -using NetSharp.Servers; -using NetSharp.Utils.Socket_Options; -namespace NetSharp.Clients +namespace NetSharp.Deprecated { /// <summary> /// Provides methods for TCP communication with a connected <see cref="TcpServer"/> instance. @@ -15,7 +12,7 @@ namespace NetSharp.Clients public sealed class TcpClient : Client { /// <inheritdoc /> - public TcpClient() : base(SocketType.Stream, ProtocolType.Tcp, new TcpSocketOptions(ref socket)) + public TcpClient() : base(SocketType.Stream, ProtocolType.Tcp) { } @@ -43,11 +40,11 @@ namespace NetSharp.Clients request.BeforeSerialisation(); Memory<byte> serialisedRequest = request.Serialise(); SerialisedPacket rawRequest = new SerialisedPacket(serialisedRequest, packetTypeId); - await DoSendPacketAsync(socket, rawRequest, SocketFlags.None, timeout); + //await DoSendPacketAsync(socket, rawRequest, SocketFlags.None, timeout); - SerialisedPacket rawResponsePacket = await DoReceivePacketAsync(socket, SocketFlags.None, timeout); + //SerialisedPacket rawResponsePacket = await DoReceivePacketAsync(socket, SocketFlags.None, timeout); Rep responsePacket = new Rep(); - responsePacket.Deserialise(rawResponsePacket.Contents); + //responsePacket.Deserialise(rawResponsePacket.Contents); responsePacket.AfterDeserialisation(); return responsePacket; @@ -61,7 +58,7 @@ namespace NetSharp.Clients request.BeforeSerialisation(); Memory<byte> serialisedRequest = request.Serialise(); SerialisedPacket rawRequest = new SerialisedPacket(serialisedRequest, packetTypeId); - return await DoSendPacketAsync(socket, rawRequest, SocketFlags.None, timeout); + return false; //await DoSendPacketAsync(socket, rawRequest, SocketFlags.None, timeout); } } } \ No newline at end of file diff --git a/NetSharp/NetSharp/Deprecated/TcpServer.cs b/NetSharp/NetSharp/Deprecated/TcpServer.cs @@ -4,15 +4,13 @@ using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; -using NetSharp.Interfaces; using NetSharp.Packets; using NetSharp.Packets.Builtin; -using NetSharp.Utils.Socket_Options; -namespace NetSharp.Servers +namespace NetSharp.Deprecated { /// <summary> - /// Provides methods for TCP communication with connected <see cref="Clients.TcpClient"/> instances. + /// Provides methods for TCP communication with connected <see cref="TcpClient"/> instances. /// </summary> public sealed class TcpServer : Server { @@ -29,8 +27,7 @@ namespace NetSharp.Servers do { // receive a single raw packet from the network - SerialisedPacket rawRequest = await DoReceivePacketAsync(clientHandlerSocket, SocketFlags.None, - Timeout.InfiniteTimeSpan, cancellationToken); + SerialisedPacket rawRequest = SerialisedPacket.Null; //await DoReceivePacketAsync(clientHandlerSocket, SocketFlags.None, Timeout.InfiniteTimeSpan, cancellationToken); if (rawRequest.Equals(SerialisedPacket.Null) || rawRequest.Type == PacketRegistry.GetPacketId<DisconnectPacket>()) @@ -72,8 +69,7 @@ namespace NetSharp.Servers // SerialisedPacket rawResponse = new SerialisedPacket(responsePacket.Serialise(), responsePacketTypeId); // echo back the processed raw response to the network - bool sentCorrectly = await DoSendPacketAsync(clientHandlerSocket, rawResponse, SocketFlags.None, - NetworkOperationTimeout, cancellationToken); + bool sentCorrectly = false; //await DoSendPacketAsync(clientHandlerSocket, rawResponse, SocketFlags.None, NetworkOperationTimeout, cancellationToken); if (!sentCorrectly) { @@ -91,8 +87,7 @@ namespace NetSharp.Servers } /// <inheritdoc /> - public TcpServer(TimeSpan networkOperationTimeout) : base(SocketType.Stream, ProtocolType.Tcp, - SocketOptionManager.Tcp, networkOperationTimeout) + public TcpServer(TimeSpan networkOperationTimeout) : base(SocketType.Stream, ProtocolType.Tcp, networkOperationTimeout) { } diff --git a/NetSharp/NetSharp/Deprecated/TcpSocketOptions.cs b/NetSharp/NetSharp/Deprecated/TcpSocketOptions.cs @@ -1,6 +1,6 @@ using System.Net.Sockets; -namespace NetSharp.Utils.Socket_Options +namespace NetSharp.Deprecated { /// <summary> /// Allows for manipulation of TCP socket options. diff --git a/NetSharp/NetSharp/Deprecated/UdpClient.cs b/NetSharp/NetSharp/Deprecated/UdpClient.cs @@ -1,14 +1,10 @@ using System; -using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using NetSharp.Packets; using NetSharp.Packets.Builtin; -using NetSharp.Servers; -using NetSharp.Utils; -using NetSharp.Utils.Socket_Options; -namespace NetSharp.Clients +namespace NetSharp.Deprecated { /// <summary> /// Provides methods for UDP communication with a connected <see cref="UdpServer"/> instance. @@ -16,7 +12,7 @@ namespace NetSharp.Clients public sealed class UdpClient : Client { /// <inheritdoc /> - public UdpClient() : base(SocketType.Dgram, ProtocolType.Udp, SocketOptionManager.Udp) + public UdpClient() : base(SocketType.Dgram, ProtocolType.Udp) { } @@ -45,14 +41,13 @@ namespace NetSharp.Clients Memory<byte> serialisedRequest = request.Serialise(); SerialisedPacket rawRequest = new SerialisedPacket(serialisedRequest, packetTypeId); - bool sentPacket = await DoSendPacketToAsync(socket, remoteEndPoint, rawRequest, SocketFlags.None, timeout); + bool sentPacket = false; //await DoSendPacketToAsync(socket, remoteEndPoint, rawRequest, SocketFlags.None, timeout); - (SerialisedPacket rawResponsePacket, EndPoint responseEndPoint) = - await DoReceivePacketFromAsync(socket, remoteEndPoint, SocketFlags.None, timeout); - remoteEndPoint = responseEndPoint; + //(SerialisedPacket rawResponsePacket, EndPoint responseEndPoint) = await DoReceivePacketFromAsync(socket, remoteEndPoint, SocketFlags.None, timeout); + //remoteEndPoint = responseEndPoint; Rep responsePacket = new Rep(); - responsePacket.Deserialise(rawResponsePacket.Contents); + //responsePacket.Deserialise(rawResponsePacket.Contents); responsePacket.AfterDeserialisation(); return responsePacket; @@ -67,7 +62,7 @@ namespace NetSharp.Clients Memory<byte> serialisedRequest = request.Serialise(); SerialisedPacket rawRequest = new SerialisedPacket(serialisedRequest, packetTypeId); - return await DoSendPacketToAsync(socket, remoteEndPoint, rawRequest, SocketFlags.None, timeout); + return false; //await DoSendPacketToAsync(socket, remoteEndPoint, rawRequest, SocketFlags.None, timeout); } } } \ No newline at end of file diff --git a/NetSharp/NetSharp/Deprecated/UdpServer.cs b/NetSharp/NetSharp/Deprecated/UdpServer.cs @@ -6,16 +6,13 @@ using System.Text; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; -using NetSharp.Interfaces; using NetSharp.Packets; using NetSharp.Packets.Builtin; -using NetSharp.Utils; -using NetSharp.Utils.Socket_Options; -namespace NetSharp.Servers +namespace NetSharp.Deprecated { /// <summary> - /// Provides methods for UDP communication with connected <see cref="Clients.UdpClient"/> instances. + /// Provides methods for UDP communication with connected <see cref="UdpClient"/> instances. /// </summary> public sealed class UdpServer : Server { @@ -88,8 +85,7 @@ namespace NetSharp.Servers // SerialisedPacket rawResponse = new SerialisedPacket(responsePacket.Serialise(), responsePacketTypeId); // echo back the processed raw response to the network - bool sentCorrectly = await DoSendPacketToAsync(socket, clientEndPoint, rawResponse, SocketFlags.None, - NetworkOperationTimeout, cancellationToken); + bool sentCorrectly = false; //await DoSendPacketToAsync(socket, clientEndPoint, rawResponse, SocketFlags.None,NetworkOperationTimeout, cancellationToken); if (!sentCorrectly) { @@ -117,8 +113,7 @@ namespace NetSharp.Servers } /// <inheritdoc /> - public UdpServer(TimeSpan networkOperationTimeout) : base(SocketType.Dgram, ProtocolType.Udp, SocketOptionManager.Udp, - networkOperationTimeout) + public UdpServer(TimeSpan networkOperationTimeout) : base(SocketType.Dgram, ProtocolType.Udp, networkOperationTimeout) { activeClients = new ConcurrentDictionary<EndPoint, Channel<SerialisedPacket>>(); } @@ -145,10 +140,9 @@ namespace NetSharp.Servers while (runServer) { EndPoint nullEndPoint = new IPEndPoint(IPAddress.Any, 0); - (SerialisedPacket request, EndPoint remoteEndPoint) = - await DoReceivePacketFromAsync(socket, nullEndPoint, SocketFlags.None, Timeout.InfiniteTimeSpan, - serverShutdownCancellationToken); - EndPoint clientEndPoint = remoteEndPoint; + /* + //(SerialisedPacket request, EndPoint remoteEndPoint) = await DoReceivePacketFromAsync(socket, nullEndPoint, SocketFlags.None, Timeout.InfiniteTimeSpan, serverShutdownCancellationToken); + //EndPoint clientEndPoint = remoteEndPoint; if (request.Equals(SerialisedPacket.Null)) { @@ -164,8 +158,9 @@ namespace NetSharp.Servers await Task.Factory.StartNew(DoHandleClientAsync, args, serverShutdownCancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); } + */ - await activeClients[clientEndPoint].Writer.WriteAsync(request); + //await activeClients[clientEndPoint].Writer.WriteAsync(request); } OnServerStopped(); diff --git a/NetSharp/NetSharp/Deprecated/UdpSocketOptions.cs b/NetSharp/NetSharp/Deprecated/UdpSocketOptions.cs @@ -1,6 +1,6 @@ using System.Net.Sockets; -namespace NetSharp.Utils.Socket_Options +namespace NetSharp.Deprecated { /// <summary> /// Allows for manipulation of UDP socket options. diff --git a/NetSharp/NetSharp/Extensions/ConnectionExtensions.cs b/NetSharp/NetSharp/Extensions/ConnectionExtensions.cs @@ -0,0 +1,16 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using System.Threading.Tasks; +using NetSharp.Utils; + +namespace NetSharp.Extensions +{ + /// <summary> + /// Provides additional methods and functionality to the <see cref="Connection"/> class. + /// </summary> + public static class ConnectionExtensions + { + } +} +\ No newline at end of file diff --git a/NetSharp/NetSharp/NetSharp.csproj b/NetSharp/NetSharp/NetSharp.csproj @@ -23,7 +23,6 @@ </ItemGroup> <ItemGroup> - <Folder Include="Extensions\" /> <Folder Include="Interfaces\" /> </ItemGroup> </Project> \ No newline at end of file diff --git a/NetSharp/NetSharp/NetSharp.xml b/NetSharp/NetSharp/NetSharp.xml @@ -4,253 +4,144 @@ <name>NetSharp</name> </assembly> <members> - <member name="T:NetSharp.Client"> + <member name="M:NetSharp.Connection.Finalize"> <summary> - Provides methods for connecting to and talking with a <see cref="T:NetSharp.Interfaces.IServer"/> instance. + Destroys a <see cref="T:NetSharp.Connection"/> class instance, freeing all managed resources. </summary> </member> - <member name="M:NetSharp.Client.#ctor"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Client"/> class. - </summary> - </member> - <member name="M:NetSharp.Client.Finalize"> + <member name="F:NetSharp.Connection.logger"> <summary> - Destroys an instance of the <see cref="T:NetSharp.Client"/> class. + A logger object allowing for writing debug messages to an output stream. </summary> </member> - <member name="F:NetSharp.Client.socket"> + <member name="M:NetSharp.Connection.Dispose(System.Boolean)"> <summary> - The <see cref="T:System.Net.Sockets.Socket"/> underlying the connection. + Disposes of the managed and unmanaged resources held by this instance. </summary> + <param name="disposing">Whether this method is called by <see cref="M:NetSharp.Connection.Dispose"/> or by the finaliser.</param> </member> - <member name="F:NetSharp.Client.socketOptions"> - <summary> - Backing field for the <see cref="P:NetSharp.Client.SocketOptions"/> property. - </summary> + <member name="M:NetSharp.Connection.Dispose"> + <inheritdoc /> </member> - <member name="F:NetSharp.Client.remoteEndPoint"> + <member name="M:NetSharp.Connection.TryBind(System.Net.EndPoint,System.TimeSpan)"> <summary> - The remote endpoint with which this client communicates. + Attempts to synchronously bind the underlying socket to the given local endpoint. Blocks. + If the timeout is exceeded the binding attempt is aborted and the method returns false. </summary> + <param name="localEndPoint">The local endpoint to bind to.</param> + <param name="timeout">The timeout within which to attempt the binding.</param> + <returns>Whether the binding was successful or not.</returns> </member> - <member name="M:NetSharp.Client.#ctor(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,NetSharp.Utils.Socket_Options.SocketOptionManager)"> + <member name="M:NetSharp.Connection.TryBindAsync(System.Net.EndPoint,System.TimeSpan)"> <summary> - Initialises a new instance of the <see cref="T:NetSharp.Client"/> class. + Attempts to asynchronously bind the underlying socket to the given local endpoint. Does not block. + If the timeout is exceeded the binding attempt is aborted and the method returns false. </summary> - <param name="socketType">The socket type for the underlying socket.</param> - <param name="protocolType">The protocol type for the underlying socket.</param> - <param name="socketManager">The <see cref="T:NetSharp.Utils.Socket_Options.SocketOptions"/> manager to use.</param> + <param name="localEndPoint">The local endpoint to bind to.</param> + <param name="timeout">The timeout within which to attempt the binding.</param> + <returns>Whether the binding was successful or not.</returns> </member> - <member name="M:NetSharp.Client.Dispose(System.Boolean)"> + <member name="T:NetSharp.ConnectionFactory"> <summary> - Disposes of this <see cref="T:NetSharp.Client"/> instance. + Provides methods to construct and configure <see cref="T:NetSharp.Connection"/> instances. </summary> - <param name="disposing">Whether this instance is being disposed.</param> </member> - <member name="M:NetSharp.Client.OnConnected(System.Net.EndPoint)"> + <member name="T:NetSharp.Deprecated.Client"> <summary> - Invokes the <see cref="E:NetSharp.Client.Connected"/> event. + Provides methods for connecting to and talking with a <see cref="T:NetSharp.Deprecated.IServer"/> instance. </summary> - <param name="endPoint">The remote endpoint with which a connection was made.</param> </member> - <member name="M:NetSharp.Client.OnDisconnected(System.Net.EndPoint)"> + <member name="M:NetSharp.Deprecated.Client.#ctor"> <summary> - Invokes the <see cref="E:NetSharp.Client.Disconnected"/> event. + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.Client"/> class. </summary> - <param name="endPoint">The remote endpoint with which a connection was lost.</param> - </member> - <member name="E:NetSharp.Client.Connected"> - <inheritdoc /> </member> - <member name="E:NetSharp.Client.Disconnected"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Client.SocketOptions"> + <member name="M:NetSharp.Deprecated.Client.Finalize"> <summary> - The configured socket options for the underlying connection. + Destroys an instance of the <see cref="T:NetSharp.Deprecated.Client"/> class. </summary> </member> - <member name="M:NetSharp.Client.Disconnect"> + <member name="F:NetSharp.Deprecated.Client.socket"> <summary> - Disconnects the client from the remote endpoint. + The <see cref="T:System.Net.Sockets.Socket"/> underlying the connection. </summary> </member> - <member name="M:NetSharp.Client.SendBytesAsync(System.Byte[],System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Client.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Client.SendComplexAsync``2(``0,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Client.SendSimpleAsync``1(``0,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Client.TryBindAsync(System.Net.IPAddress,System.Nullable{System.Int32},System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Client.TryConnectAsync(System.Net.IPAddress,System.Int32,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="T:NetSharp.Clients.TcpClient"> + <member name="F:NetSharp.Deprecated.Client.socketOptions"> <summary> - Provides methods for TCP communication with a connected <see cref="T:NetSharp.Servers.TcpServer"/> instance. + Backing field for the <see cref="P:NetSharp.Deprecated.Client.SocketOptions"/> property. </summary> </member> - <member name="M:NetSharp.Clients.TcpClient.#ctor"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.TcpClient.SendBytesAsync(System.Byte[],System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.TcpClient.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.TcpClient.SendComplexAsync``2(``0,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.TcpClient.SendSimpleAsync``1(``0,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="T:NetSharp.Clients.UdpClient"> + <member name="F:NetSharp.Deprecated.Client.remoteEndPoint"> <summary> - Provides methods for UDP communication with a connected <see cref="T:NetSharp.Servers.UdpServer"/> instance. + The remote endpoint with which this client communicates. </summary> </member> - <member name="M:NetSharp.Clients.UdpClient.#ctor"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.UdpClient.SendBytesAsync(System.Byte[],System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.UdpClient.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.UdpClient.SendComplexAsync``2(``0,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Clients.UdpClient.SendSimpleAsync``1(``0,System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="T:NetSharp.Connection"> + <member name="M:NetSharp.Deprecated.Client.#ctor(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType)"> <summary> - Base class for connections, holding methods shared between the <see cref="T:NetSharp.Client"/> and <see cref="T:NetSharp.Server"/> classes. + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.Client"/> class. </summary> + <param name="socketType">The socket type for the underlying socket.</param> + <param name="protocolType">The protocol type for the underlying socket.</param> + <param name="socketManager">The <see cref="!:Utils.Socket_Options.SocketOptions"/> manager to use.</param> </member> - <member name="F:NetSharp.Connection.logger"> + <member name="M:NetSharp.Deprecated.Client.Dispose(System.Boolean)"> <summary> - The logger to which the server can log messages. + Disposes of this <see cref="T:NetSharp.Deprecated.Client"/> instance. </summary> + <param name="disposing">Whether this instance is being disposed.</param> </member> - <member name="M:NetSharp.Connection.#ctor"> + <member name="M:NetSharp.Deprecated.Client.OnConnected(System.Net.EndPoint)"> <summary> - Initialises a new instance of the <see cref="T:NetSharp.Connection"/> class. + Invokes the <see cref="E:NetSharp.Deprecated.Client.Connected"/> event. </summary> + <param name="endPoint">The remote endpoint with which a connection was made.</param> </member> - <member name="M:NetSharp.Connection.Dispose(System.Boolean)"> + <member name="M:NetSharp.Deprecated.Client.OnDisconnected(System.Net.EndPoint)"> <summary> - Disposes of this <see cref="T:NetSharp.Connection"/> instance. + Invokes the <see cref="E:NetSharp.Deprecated.Client.Disconnected"/> event. </summary> - <param name="disposing">Whether this instance is being disposed.</param> + <param name="endPoint">The remote endpoint with which a connection was lost.</param> </member> - <member name="M:NetSharp.Connection.DoReceivePacketAsync(System.Net.Sockets.Socket,System.Net.Sockets.SocketFlags,System.TimeSpan,System.Threading.CancellationToken)"> - <summary> - Listens for a packet to be received from the network. - </summary> - <param name="socket">The remote socket from which to receive data.</param> - <param name="socketFlags">The socket flags associated with the read operation.</param> - <param name="timeout"> - The timespan within which the packet should be received. After this timespan elapses, the receive task is cancelled. - </param> - <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - <returns>The packet that was received. <see cref="!:NullPacket"/> if not received correctly.</returns> + <member name="E:NetSharp.Deprecated.Client.Connected"> + <inheritdoc /> </member> - <member name="M:NetSharp.Connection.DoReceivePacketFromAsync(System.Net.Sockets.Socket,System.Net.EndPoint,System.Net.Sockets.SocketFlags,System.TimeSpan,System.Threading.CancellationToken)"> - <summary> - Listens for a packet to be received from the network. - </summary> - <param name="socket">The socket which will receive the packet.</param> - <param name="remoteEndPoint">The remote endpoint from which to receive the packet.</param> - <param name="socketFlags">The socket flags associated with the read operation.</param> - <param name="timeout"> - The timespan within which the packet should be received. After this timespan elapses, the receive task is cancelled. - </param> - <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - <returns> - The packet that was received and the associated transmission result. <see cref="!:NullPacket"/> if not received correctly. - </returns> + <member name="E:NetSharp.Deprecated.Client.Disconnected"> + <inheritdoc /> </member> - <member name="M:NetSharp.Connection.DoSendPacketAsync(System.Net.Sockets.Socket,NetSharp.Packets.SerialisedPacket,System.Net.Sockets.SocketFlags,System.TimeSpan,System.Threading.CancellationToken)"> + <member name="P:NetSharp.Deprecated.Client.SocketOptions"> <summary> - Sends the given packet to the network. + The configured socket options for the underlying connection. </summary> - <param name="remoteSocket">The remote socket to which to send the packet.</param> - <param name="packet">The packet to send.</param> - <param name="socketFlags">The socket flags associated with the write operation.</param> - <param name="timeout"> - The timespan within which the packet should be received. After this timespan elapses, the send task is cancelled. - </param> - <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - <returns>Whether the packet was successfully sent.</returns> </member> - <member name="M:NetSharp.Connection.DoSendPacketToAsync(System.Net.Sockets.Socket,System.Net.EndPoint,NetSharp.Packets.SerialisedPacket,System.Net.Sockets.SocketFlags,System.TimeSpan,System.Threading.CancellationToken)"> + <member name="M:NetSharp.Deprecated.Client.Disconnect"> <summary> - Sends the given packet to the network. + Disconnects the client from the remote endpoint. </summary> - <param name="socket">The socket which should send the packet.</param> - <param name="remoteEndPoint">The remote endpoint to which to send the packet.</param> - <param name="packet">The packet to send.</param> - <param name="socketFlags">The socket flags associated with the write operation.</param> - <param name="timeout"> - The timespan within which the packet should be received. After this timespan elapses, the send task is cancelled. - </param> - <param name="cancellationToken">A pre-existing cancellation token that should be observed alongside the timeout.</param> - <returns>Whether the packet was successfully sent.</returns> </member> - <member name="M:NetSharp.Connection.OnBytesReceived(System.Net.EndPoint,System.Int32)"> - <summary> - Invokes the <see cref="E:NetSharp.Connection.BytesReceived"/> event. - </summary> - <param name="remoteEndPoint">The remote endpoint from which the bytes were received.</param> - <param name="bytesReceived">The number of bytes that were received from the remote endpoint.</param> + <member name="M:NetSharp.Deprecated.Client.SendBytesAsync(System.Byte[],System.TimeSpan)"> + <inheritdoc /> </member> - <member name="M:NetSharp.Connection.OnBytesSent(System.Net.EndPoint,System.Int32)"> - <summary> - Invokes the <see cref="E:NetSharp.Connection.BytesSent"/> event. - </summary> - <param name="remoteEndPoint">The remote endpoint to which the bytes were sent.</param> - <param name="bytesSent">The number of bytes that were sent to the remote endpoint.</param> + <member name="M:NetSharp.Deprecated.Client.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> + <inheritdoc /> </member> - <member name="E:NetSharp.Connection.BytesReceived"> - <summary> - Signifies that some data has been received from the remote endpoint. - </summary> + <member name="M:NetSharp.Deprecated.Client.SendComplexAsync``2(``0,System.TimeSpan)"> + <inheritdoc /> </member> - <member name="E:NetSharp.Connection.BytesSent"> - <summary> - Signifies that some data was sent to the remote endpoint. - </summary> + <member name="M:NetSharp.Deprecated.Client.SendSimpleAsync``1(``0,System.TimeSpan)"> + <inheritdoc /> </member> - <member name="M:NetSharp.Connection.ChangeLoggingStream(System.IO.Stream,NetSharp.Logging.LogLevel)"> - <summary> - Makes the client log to the given stream. - </summary> - <param name="loggingStream">The stream that new messages should be logged to.</param> - <param name="minimumMessageSeverityLevel"> - The minimum severity level that new messages must have to be logged to the stream. - </param> + <member name="M:NetSharp.Deprecated.Client.TryBindAsync(System.Net.IPAddress,System.Nullable{System.Int32},System.TimeSpan)"> + <inheritdoc /> </member> - <member name="M:NetSharp.Connection.Dispose"> + <member name="M:NetSharp.Deprecated.Client.TryConnectAsync(System.Net.IPAddress,System.Int32,System.TimeSpan)"> <inheritdoc /> </member> - <member name="T:NetSharp.Extensions.ClientExtensions"> + <member name="T:NetSharp.Deprecated.ClientExtensions"> <summary> - Provides additional methods and functionality to the <see cref="T:NetSharp.Client"/> class. + Provides additional methods and functionality to the <see cref="T:NetSharp.Deprecated.Client"/> class. </summary> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendBytes(NetSharp.Client,System.Byte[])"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendBytes(NetSharp.Deprecated.Client,System.Byte[])"> <summary> Sends the given byte buffer to the connected remote endpoint. Blocks until the bytes are all sent, and does not timeout. @@ -258,7 +149,7 @@ <param name="instance">The instance on which this extension method should be called.</param> <param name="buffer">The bytes that should be sent to the connected remote endpoint.</param> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendBytes(NetSharp.Client,System.Byte[],System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendBytes(NetSharp.Deprecated.Client,System.Byte[],System.TimeSpan)"> <summary> Sends the given byte buffer to the connected remote endpoint. Blocks until the bytes are all sent, whilst observing a timeout of the given length. @@ -267,7 +158,7 @@ <param name="buffer">The bytes that should be sent to the connected remote endpoint.</param> <param name="timeout">The timeout after which to cancel the transmission attempt.</param> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendBytesAsync(NetSharp.Client,System.Byte[])"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendBytesAsync(NetSharp.Deprecated.Client,System.Byte[])"> <summary> Sends the given byte buffer to the connected remote endpoint asynchronously. Does not block, and does not timeout. @@ -275,7 +166,7 @@ <param name="instance">The instance on which this extension method should be called.</param> <param name="buffer">The bytes that should be sent to the connected remote endpoint.</param> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendBytesWithResponse(NetSharp.Client,System.Byte[])"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendBytesWithResponse(NetSharp.Deprecated.Client,System.Byte[])"> <summary> Sends the given byte buffer to the connected remote endpoint and waits for the response. Blocks until the bytes are all sent and the response has been received, and does not timeout. @@ -284,7 +175,7 @@ <param name="buffer">The bytes that should be sent to the connected remote endpoint.</param> <returns>The byte buffer that was received as a response.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendBytesWithResponse(NetSharp.Client,System.Byte[],System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendBytesWithResponse(NetSharp.Deprecated.Client,System.Byte[],System.TimeSpan)"> <summary> Sends the given byte buffer to the connected remote endpoint and waits for the response. Blocks until the bytes are all sent and the response has been received, whilst observing a timeout of the given length. @@ -294,7 +185,7 @@ <param name="timeout">The timeout after which to cancel the transmission attempt.</param> <returns>The byte buffer that was received as a response.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendBytesWithResponseAsync(NetSharp.Client,System.Byte[])"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendBytesWithResponseAsync(NetSharp.Deprecated.Client,System.Byte[])"> <summary> Sends the given byte buffer to the connected remote endpoint and waits for the response asynchronously. Does not block, and does not timeout. @@ -303,7 +194,7 @@ <param name="buffer">The bytes that should be sent to the connected remote endpoint.</param> <returns>The byte buffer received as a response to the sent buffer.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendComplex``2(NetSharp.Client,``0)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendComplex``2(NetSharp.Deprecated.Client,``0)"> <summary> Sends the given request and listens for a response of the given type. Blocks until the response is received. Does not timeout. @@ -314,7 +205,7 @@ <param name="request">The request packet to send.</param> <returns>The received instance.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendComplex``2(NetSharp.Client,``0,System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendComplex``2(NetSharp.Deprecated.Client,``0,System.TimeSpan)"> <summary> Sends the given request and listens for a response of the given type. Blocks until the response is received. Cancels the operation if the given timeout is exceeded. @@ -326,7 +217,7 @@ <param name="timeout">The timeout for which to wait for the operation to complete.</param> <returns>The received instance.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendComplexAsync``2(NetSharp.Client,``0)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendComplexAsync``2(NetSharp.Deprecated.Client,``0)"> <summary> Sends the given request and listens for a response of the given type asynchronously. Does not block. Does not timeout. </summary> @@ -336,7 +227,7 @@ <param name="request">The request packet to send.</param> <returns>The received instance.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendSimple``1(NetSharp.Client,``0)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendSimple``1(NetSharp.Deprecated.Client,``0)"> <summary> Sends the given request without listening for a response, blocking until it is sent. Does not timeout. </summary> @@ -344,7 +235,7 @@ <param name="instance">The instance on which this extension method should be called.</param> <param name="request">The request packet to send.</param> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendSimple``1(NetSharp.Client,``0,System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendSimple``1(NetSharp.Deprecated.Client,``0,System.TimeSpan)"> <summary> Sends the given request without listening for a response, blocking until it is sent. Cancels the operation if the given timeout is exceeded. @@ -354,7 +245,7 @@ <param name="request">The request packet to send.</param> <param name="timeout">The timeout for which to wait for the operation to complete.</param> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.SendSimpleAsync``1(NetSharp.Client,``0)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.SendSimpleAsync``1(NetSharp.Deprecated.Client,``0)"> <summary> Sends the given request asynchronously without listening for a response, not blocking until it is sent. Does not timeout. @@ -363,7 +254,7 @@ <param name="instance">The instance on which this extension method should be called.</param> <param name="request">The request packet to send.</param> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.TryBind(NetSharp.Client,System.Net.IPAddress,System.Nullable{System.Int32})"> + <member name="M:NetSharp.Deprecated.ClientExtensions.TryBind(NetSharp.Deprecated.Client,System.Net.IPAddress,System.Nullable{System.Int32})"> <summary> Attempts to synchronously bind the underlying socket to the given local address and port. Blocks. Does not timeout. </summary> @@ -372,7 +263,7 @@ <param name="localPort">The local port to bind to. Null if any port will suffice.</param> <returns>Whether the binding was successful or not.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.TryBind(NetSharp.Client,System.Net.IPAddress,System.Nullable{System.Int32},System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.TryBind(NetSharp.Deprecated.Client,System.Net.IPAddress,System.Nullable{System.Int32},System.TimeSpan)"> <summary> Attempts to synchronously bind the underlying socket to the given local address and port. Blocks. If the timeout is exceeded the binding attempt is aborted and the method returns false. @@ -383,7 +274,7 @@ <param name="timeout">The timeout within which to attempt the binding.</param> <returns>Whether the binding was successful or not.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.TryBindAsync(NetSharp.Client,System.Net.IPAddress,System.Nullable{System.Int32})"> + <member name="M:NetSharp.Deprecated.ClientExtensions.TryBindAsync(NetSharp.Deprecated.Client,System.Net.IPAddress,System.Nullable{System.Int32})"> <summary> Attempts to asynchronously bind the underlying socket to the given local address and port. Does not block. Does not timeout. @@ -393,9 +284,9 @@ <param name="localPort">The local port to bind to. Null if any port will suffice.</param> <returns>Whether the binding was successful or not.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.TryConnect(NetSharp.Client,System.Net.IPAddress,System.Int32)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.TryConnect(NetSharp.Deprecated.Client,System.Net.IPAddress,System.Int32)"> <summary> - Attempts to connect to the remote <see cref="T:NetSharp.Server"/> at the given <see cref="T:System.Net.IPAddress"/> and over the + Attempts to connect to the remote <see cref="T:NetSharp.Deprecated.Server"/> at the given <see cref="T:System.Net.IPAddress"/> and over the given port. Does not timeout. </summary> <param name="instance">The instance on which this extension method should be called.</param> @@ -403,9 +294,9 @@ <param name="remotePort">The remote port to connect over.</param> <returns>Whether the connection was successful or not.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.TryConnect(NetSharp.Client,System.Net.IPAddress,System.Int32,System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.TryConnect(NetSharp.Deprecated.Client,System.Net.IPAddress,System.Int32,System.TimeSpan)"> <summary> - Attempts to connect to the remote <see cref="T:NetSharp.Server"/> at the given <see cref="T:System.Net.IPAddress"/> and over the + Attempts to connect to the remote <see cref="T:NetSharp.Deprecated.Server"/> at the given <see cref="T:System.Net.IPAddress"/> and over the given port. If the timeout is exceeded the connection attempt is aborted and the method returns false. </summary> <param name="instance">The instance on which this extension method should be called.</param> @@ -414,9 +305,9 @@ <param name="timeout">The timeout within which to attempt the connection.</param> <returns>Whether the connection was successful or not.</returns> </member> - <member name="M:NetSharp.Extensions.ClientExtensions.TryConnectAsync(NetSharp.Client,System.Net.IPAddress,System.Int32)"> + <member name="M:NetSharp.Deprecated.ClientExtensions.TryConnectAsync(NetSharp.Deprecated.Client,System.Net.IPAddress,System.Int32)"> <summary> - Attempts to connect asynchronously to the remote <see cref="T:NetSharp.Server"/> at the given <see cref="T:System.Net.IPAddress"/> + Attempts to connect asynchronously to the remote <see cref="T:NetSharp.Deprecated.Server"/> at the given <see cref="T:System.Net.IPAddress"/> and over the given port. Does not timeout. </summary> <param name="instance">The instance on which this extension method should be called.</param> @@ -424,138 +315,48 @@ <param name="remotePort">The remote port to connect over.</param> <returns>Whether the connection was successful or not.</returns> </member> - <member name="T:NetSharp.Extensions.ServerExtensions"> - <summary> - Provides additional methods and functionality to the <see cref="T:NetSharp.Server"/> class. - </summary> - </member> - <member name="M:NetSharp.Extensions.ServerExtensions.Run(NetSharp.Server,System.Net.IPAddress,System.Int32)"> - <summary> - Starts the server synchronously and starts accepting client connections. Blocks. - </summary> - <param name="instance">The instance on which this extension method should be called.</param> - <param name="localAddress">The local IP address to bind to.</param> - <param name="localPort">The local port to bind to.</param> - </member> - <member name="M:NetSharp.Extensions.ServerExtensions.Run(NetSharp.Server,System.Net.IPAddress)"> + <member name="T:NetSharp.Deprecated.DefaultSocketOptions"> <summary> - Starts the server synchronously and starts accepting client connections. Blocks. Uses the default connection port. - </summary> - <param name="instance">The instance on which this extension method should be called.</param> - <param name="localAddress">The local IP address to bind to.</param> - </member> - <member name="M:NetSharp.Extensions.ServerExtensions.RunAsync(NetSharp.Server,System.Net.IPAddress)"> - <summary> - Starts the server asynchronously and starts accepting client connections. Does not block. Uses the default - connection port. - </summary> - <param name="instance">The instance on which this extension method should be called.</param> - <param name="localAddress">The local IP address to bind to.</param> - </member> - <member name="M:NetSharp.Extensions.ServerExtensions.RunAsync(NetSharp.Server,System.Net.IPAddress,System.Int32)"> - <summary> - Starts the server asynchronously and starts accepting client connections. Does not block. - </summary> - <param name="instance">The instance on which this extension method should be called.</param> - <param name="localAddress">The local IP address to bind to.</param> - <param name="localPort">The local port to bind to.</param> - </member> - <member name="T:NetSharp.Extensions.SocketExtensions"> - <summary> - Provides additional methods and functionality to the <see cref="T:System.Net.Sockets.Socket"/> class. - </summary> - </member> - <member name="M:NetSharp.Extensions.SocketExtensions.ReceiveAsync(System.Net.Sockets.Socket,NetSharp.Extensions.SocketTask)"> - <inheritdoc cref="M:System.Net.Sockets.Socket.ReceiveAsync(System.Net.Sockets.SocketAsyncEventArgs)"/> - </member> - <member name="M:NetSharp.Extensions.SocketExtensions.ReceiveFromAsync(System.Net.Sockets.Socket,NetSharp.Extensions.SocketTask)"> - <inheritdoc cref="M:System.Net.Sockets.Socket.ReceiveFromAsync(System.Net.Sockets.SocketAsyncEventArgs)"/> - </member> - <member name="M:NetSharp.Extensions.SocketExtensions.ReceiveMessageFromAsync(System.Net.Sockets.Socket,NetSharp.Extensions.SocketTask)"> - <inheritdoc cref="M:System.Net.Sockets.Socket.ReceiveMessageFromAsync(System.Net.Sockets.SocketAsyncEventArgs)"/> - </member> - <member name="M:NetSharp.Extensions.SocketExtensions.SendAsync(System.Net.Sockets.Socket,NetSharp.Extensions.SocketTask)"> - <inheritdoc cref="M:System.Net.Sockets.Socket.SendAsync(System.Net.Sockets.SocketAsyncEventArgs)"/> - </member> - <member name="M:NetSharp.Extensions.SocketExtensions.SendToAsync(System.Net.Sockets.Socket,NetSharp.Extensions.SocketTask)"> - <inheritdoc cref="M:System.Net.Sockets.Socket.SendToAsync(System.Net.Sockets.SocketAsyncEventArgs)"/> - </member> - <member name="T:NetSharp.Extensions.SocketTask"> - <summary> - Custom awaitable to ease the use of sockets with the TAP pattern. - Credit goes to https://devblogs.microsoft.com/pfxteam/awaiting-socket-operations/. - </summary> - </member> - <member name="F:NetSharp.Extensions.SocketTask.SentinelAction"> - <summary> - Representing a null action. - </summary> - </member> - <member name="F:NetSharp.Extensions.SocketTask.continuationAction"> - <summary> - The action that should be invoked upon the completion of the socket task. - </summary> - </member> - <member name="F:NetSharp.Extensions.SocketTask.eventArgs"> - <summary> - The underlying socket event args for this socket task. - </summary> - </member> - <member name="F:NetSharp.Extensions.SocketTask.wasCompleted"> - <summary> - Whether this socket task was completed. - </summary> - </member> - <member name="M:NetSharp.Extensions.SocketTask.Reset"> - <summary> - Resets this socket task to its default state, and sets <see cref="F:NetSharp.Extensions.SocketTask.continuationAction"/> to <c>default</c>. - </summary> - </member> - <member name="M:NetSharp.Extensions.SocketTask.#ctor(System.Net.Sockets.SocketAsyncEventArgs)"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Extensions.SocketTask"/> class. + Allows for manipulation of socket options. </summary> - <param name="asyncEventArgs">The socket event args that this socket task should wrap. Must not be <c>null</c>.</param> - <exception cref="T:System.ArgumentNullException">Thrown if the given <paramref name="asyncEventArgs"/> were <c>null</c>.</exception> </member> - <member name="P:NetSharp.Extensions.SocketTask.IsCompleted"> - <summary> - Whether this socket task has been completed. - </summary> + <member name="M:NetSharp.Deprecated.DefaultSocketOptions.#ctor(System.Net.Sockets.Socket@)"> + <inheritdoc /> </member> - <member name="M:NetSharp.Extensions.SocketTask.GetAwaiter"> - <summary> - Returns this socket task instance. - </summary> + <member name="P:NetSharp.Deprecated.DefaultSocketOptions.HopLimit"> + <inheritdoc /> + <exception cref="T:System.NotSupportedException"> + This property is not supported when using the default socket option manager. + </exception> </member> - <member name="M:NetSharp.Extensions.SocketTask.GetResult"> - <summary> - Throws a <see cref="T:System.Net.Sockets.SocketException"/> if the wrapped <see cref="P:System.Net.Sockets.SocketAsyncEventArgs.SocketError"/> - is not equal to <see cref="F:System.Net.Sockets.SocketError.Success"/>. - </summary> - <exception cref="T:System.Net.Sockets.SocketException"> - Thrown if the wrapped <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> did not complete successfully. + <member name="P:NetSharp.Deprecated.DefaultSocketOptions.IsRoutingEnabled"> + <inheritdoc /> + <exception cref="T:System.NotSupportedException"> + This property is not supported when using the default socket option manager. </exception> </member> - <member name="M:NetSharp.Extensions.SocketTask.OnCompleted(System.Action)"> + <member name="P:NetSharp.Deprecated.DefaultSocketOptions.UseLoopback"> <inheritdoc /> + <exception cref="T:System.NotSupportedException"> + This property is not supported when using the default socket option manager. + </exception> </member> - <member name="T:NetSharp.Interfaces.IClient"> + <member name="T:NetSharp.Deprecated.IClient"> <summary> - Describes a client capable of asynchronous communication with an <see cref="T:NetSharp.Interfaces.IServer"/> connection. + Describes a client capable of asynchronous communication with an <see cref="T:NetSharp.Deprecated.IServer"/> connection. </summary> </member> - <member name="E:NetSharp.Interfaces.IClient.Connected"> + <member name="E:NetSharp.Deprecated.IClient.Connected"> <summary> Signifies that a connection with the remote endpoint has been made. </summary> </member> - <member name="E:NetSharp.Interfaces.IClient.Disconnected"> + <member name="E:NetSharp.Deprecated.IClient.Disconnected"> <summary> Signifies that the connection with the remote endpoint was severed. </summary> </member> - <member name="M:NetSharp.Interfaces.IClient.SendBytesAsync(System.Byte[],System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.IClient.SendBytesAsync(System.Byte[],System.TimeSpan)"> <summary> Sends the given byte buffer to the connected remote endpoint asynchronously. Does not block, and observes a timeout of the given length. @@ -565,7 +366,7 @@ <param name="timeout">The timeout after which to cancel the transmission attempt.</param> <returns>Whether the transmission attempt was successful.</returns> </member> - <member name="M:NetSharp.Interfaces.IClient.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.IClient.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> <summary> Sends the given byte buffer to the connected remote endpoint and waits for the response asynchronously. Does not block, and observes a timeout of the given length. @@ -579,7 +380,7 @@ </param> <returns>The byte buffer received as a response to the sent buffer.</returns> </member> - <member name="M:NetSharp.Interfaces.IClient.SendComplexAsync``2(``0,System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.IClient.SendComplexAsync``2(``0,System.TimeSpan)"> <summary> Sends the given request and listens for a response of the given type asynchronously. Does not block. Cancels the operation if the given timeout is exceeded @@ -590,7 +391,7 @@ <param name="timeout">The timeout for which to wait for the operation to complete.</param> <returns>The received instance.</returns> </member> - <member name="M:NetSharp.Interfaces.IClient.SendSimpleAsync``1(``0,System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.IClient.SendSimpleAsync``1(``0,System.TimeSpan)"> <summary> Sends the given request asynchronously without listening for a response, not blocking until it is sent. Cancels the operation if the given timeout is exceeded. @@ -600,7 +401,7 @@ <param name="timeout">The timeout for which to wait for the operation to complete.</param> <returns>Whether the transmission attempt was successful.</returns> </member> - <member name="M:NetSharp.Interfaces.IClient.TryBindAsync(System.Net.IPAddress,System.Nullable{System.Int32},System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.IClient.TryBindAsync(System.Net.IPAddress,System.Nullable{System.Int32},System.TimeSpan)"> <summary> Attempts to asynchronously bind the underlying socket to the given local address and port. Does not block. If the timeout is exceeded the binding attempt is aborted and the method returns false. @@ -610,9 +411,9 @@ <param name="timeout">The timeout within which to attempt the binding.</param> <returns>Whether the binding was successful or not.</returns> </member> - <member name="M:NetSharp.Interfaces.IClient.TryConnectAsync(System.Net.IPAddress,System.Int32,System.TimeSpan)"> + <member name="M:NetSharp.Deprecated.IClient.TryConnectAsync(System.Net.IPAddress,System.Int32,System.TimeSpan)"> <summary> - Attempts to connect asynchronously to the remote <see cref="T:NetSharp.Server"/> at the given <see cref="T:System.Net.IPAddress"/> + Attempts to connect asynchronously to the remote <see cref="T:NetSharp.Deprecated.Server"/> at the given <see cref="T:System.Net.IPAddress"/> and over the given port. If the timeout is exceeded the connection attempt is aborted and the method returns false. </summary> <param name="remoteAddress">The remote IP address to connect to.</param> @@ -620,91 +421,45 @@ <param name="timeout">The timeout within which to attempt the connection.</param> <returns>Whether the connection was successful or not.</returns> </member> - <member name="T:NetSharp.Interfaces.INetworkSerialisable"> + <member name="T:NetSharp.Deprecated.INetworkSerialisable"> <summary> Describes an object that can be serialised to be sent across the network. </summary> </member> - <member name="M:NetSharp.Interfaces.INetworkSerialisable.Deserialise(System.ReadOnlyMemory{System.Byte})"> + <member name="M:NetSharp.Deprecated.INetworkSerialisable.Deserialise(System.ReadOnlyMemory{System.Byte})"> <summary> Deserialises the object instance from a byte array. </summary> <param name="serialisedObject">The memory containing the serialised object instance.</param> </member> - <member name="M:NetSharp.Interfaces.INetworkSerialisable.Serialise"> + <member name="M:NetSharp.Deprecated.INetworkSerialisable.Serialise"> <summary> Serialises the object instance into a byte array. </summary> <returns>The memory containing the serialised object instance.</returns> </member> - <member name="T:NetSharp.Interfaces.IPacket"> + <member name="T:NetSharp.Deprecated.IPacket"> <summary> Describes the methods and properties that every packet </summary> </member> - <member name="M:NetSharp.Interfaces.IPacket.AfterDeserialisation"> + <member name="M:NetSharp.Deprecated.IPacket.AfterDeserialisation"> <summary> Allows for custom fields to be converted from their serialised format, after being received from the network. </summary> </member> - <member name="M:NetSharp.Interfaces.IPacket.BeforeSerialisation"> + <member name="M:NetSharp.Deprecated.IPacket.BeforeSerialisation"> <summary> Allows for custom fields to be converted into another format prior to being sent via the network. </summary> </member> - <member name="T:NetSharp.Interfaces.IRequestPacket"> + <member name="T:NetSharp.Deprecated.IPacketHandler"> <summary> - Describes a request packet. - </summary> - </member> - <member name="T:NetSharp.Interfaces.IResponsePacket`1"> - <summary> - Describes a response packet to a request packet. - </summary> - <typeparam name="TReq">The request packet that this type is a response to.</typeparam> - </member> - <member name="P:NetSharp.Interfaces.IResponsePacket`1.RequestPacket"> - <summary> - The request packet that was handled with this response packet. - </summary> - </member> - <member name="T:NetSharp.Interfaces.IServer"> - <summary> - Describes a server capable of asynchronously handling multiple <see cref="T:NetSharp.Interfaces.IClient"/> connections at once. - </summary> - </member> - <member name="E:NetSharp.Interfaces.IServer.ClientConnected"> - <summary> - Signifies that a connection with a remote endpoint has been made. - </summary> - </member> - <member name="E:NetSharp.Interfaces.IServer.ClientDisconnected"> - <summary> - Signifies that a connection with a remote endpoint has been lost. - </summary> - </member> - <member name="E:NetSharp.Interfaces.IServer.ServerStarted"> - <summary> - Signifies that the server was started and clients will start being accepted. - </summary> - </member> - <member name="E:NetSharp.Interfaces.IServer.ServerStopped"> - <summary> - Signifies that the server was stopped and clients will stop being accepted. - </summary> - </member> - <member name="M:NetSharp.Interfaces.IServer.RunAsync(System.Net.EndPoint)"> - <summary> - Starts the server asynchronously and starts accepting client connections. Does not block. - </summary> - <param name="localEndPoint">The local endpoint to bind to.</param> - </member> - <member name="M:NetSharp.Interfaces.IServer.Shutdown"> - <summary> - Shuts down the server. + Describes a class capable of registering and deregistering packet handlers, and capable of + handling incoming packets according to the currently registered packet handlers. </summary> </member> - <member name="M:NetSharp.Interfaces.IServer.TryDeregisterComplexPacketHandler``2(NetSharp.ComplexPacketHandler{``0,``1}@)"> + <member name="M:NetSharp.Deprecated.IPacketHandler.TryDeregisterComplexPacketHandler``2(NetSharp.Deprecated.ComplexPacketHandler{``0,``1}@)"> <summary> Attempts to deregister the complex packet handler delegate for all packets of the given type. If a handler method doesn't exist for the given packet type, <paramref name="oldHandlerDelegate"/> will be <c>default</c>. @@ -714,7 +469,7 @@ <param name="oldHandlerDelegate">The old handler delegate method that was previously registered.</param> <returns>Whether the packet handler delegate was successfully deregistered.</returns> </member> - <member name="M:NetSharp.Interfaces.IServer.TryDeregisterSimplePacketHandler``1(NetSharp.SimplePacketHandler{``0}@)"> + <member name="M:NetSharp.Deprecated.IPacketHandler.TryDeregisterSimplePacketHandler``1(NetSharp.Deprecated.SimplePacketHandler{``0}@)"> <summary> Attempts to deregister the simple packet handler delegate for all packets of the given type. If a handler method doesn't exist for the given packet type, <paramref name="oldHandlerDelegate"/> will be <c>default</c>. @@ -723,7 +478,7 @@ <param name="oldHandlerDelegate">The old handler delegate method that was previously registered.</param> <returns>Whether the packet handler delegate was successfully deregistered.</returns> </member> - <member name="M:NetSharp.Interfaces.IServer.TryRegisterComplexPacketHandler``2(NetSharp.ComplexPacketHandler{``0,``1})"> + <member name="M:NetSharp.Deprecated.IPacketHandler.TryRegisterComplexPacketHandler``2(NetSharp.Deprecated.ComplexPacketHandler{``0,``1})"> <summary> Attempts to register a complex packet handler delegate for all packets of the given type. If a handler method already exists for the given packet type, it will be updated and replaced with the given one. @@ -733,7 +488,7 @@ <param name="handlerDelegate">The delegate method to register as the complex packet handler.</param> <returns>Whether the packet handler delegate was successfully registered.</returns> </member> - <member name="M:NetSharp.Interfaces.IServer.TryRegisterSimplePacketHandler``1(NetSharp.SimplePacketHandler{``0})"> + <member name="M:NetSharp.Deprecated.IPacketHandler.TryRegisterSimplePacketHandler``1(NetSharp.Deprecated.SimplePacketHandler{``0})"> <summary> Attempts to register a simple packet handler delegate for all packets of the given type. If a handler method already exists for the given packet type, it will be updated and replaced with the given one. @@ -742,49 +497,690 @@ <param name="handlerDelegate">The delegate method to register as the simple packet handler.</param> <returns>Whether the packet handler delegate was successfully registered.</returns> </member> - <member name="T:NetSharp.Logging.LogLevel"> + <member name="T:NetSharp.Deprecated.IRequestPacket"> <summary> - Specifies the severity level of a log message. + Describes a request packet. </summary> </member> - <member name="F:NetSharp.Logging.LogLevel.Info"> + <member name="T:NetSharp.Deprecated.IResponsePacket`1"> <summary> - The logged message contains some information. Lowest severity. + Describes a response packet to a request packet. </summary> + <typeparam name="TReq">The request packet that this type is a response to.</typeparam> </member> - <member name="F:NetSharp.Logging.LogLevel.Warn"> + <member name="P:NetSharp.Deprecated.IResponsePacket`1.RequestPacket"> <summary> - The logged message contains a warning. Higher severity. + The request packet that was handled with this response packet. </summary> </member> - <member name="F:NetSharp.Logging.LogLevel.Error"> + <member name="T:NetSharp.Deprecated.IServer"> <summary> - The logged message contains details about an error. Higher severity. + Describes a server capable of asynchronously handling multiple <see cref="T:NetSharp.Deprecated.IClient"/> connections at once. </summary> </member> - <member name="F:NetSharp.Logging.LogLevel.Exception"> + <member name="E:NetSharp.Deprecated.IServer.ClientConnected"> <summary> - The logged message contains details about an exception. Highest severity. + Signifies that a connection with a remote endpoint has been made. </summary> </member> - <member name="T:NetSharp.Logging.Logger"> + <member name="E:NetSharp.Deprecated.IServer.ClientDisconnected"> <summary> - A simple logger capable of writing text to a stream. + Signifies that a connection with a remote endpoint has been lost. </summary> </member> - <member name="F:NetSharp.Logging.Logger.loggingStream"> + <member name="E:NetSharp.Deprecated.IServer.ServerStarted"> <summary> - The stream to which messages will be logged. + Signifies that the server was started and clients will start being accepted. </summary> </member> - <member name="F:NetSharp.Logging.Logger.minimumSeverity"> + <member name="E:NetSharp.Deprecated.IServer.ServerStopped"> <summary> - The minimum severity that log messages need to be logged to the underlying stream. + Signifies that the server was stopped and clients will stop being accepted. </summary> </member> - <member name="F:NetSharp.Logging.Logger.writer"> + <member name="M:NetSharp.Deprecated.IServer.RunAsync(System.Net.EndPoint)"> <summary> - The text writer we will use to log messages to the underlying stream. + Starts the server asynchronously and starts accepting client connections. Does not block. + </summary> + <param name="localEndPoint">The local endpoint to bind to.</param> + </member> + <member name="M:NetSharp.Deprecated.IServer.Shutdown"> + <summary> + Shuts down the server. + </summary> + </member> + <member name="M:NetSharp.Deprecated.SerialisedPacket.From``1(``0)"> + <summary> + Serialises the given serialisable packet instance and returns the <see cref="T:NetSharp.Deprecated.SerialisedPacket"/> instance + that was generated. This method invokes <see cref="M:NetSharp.Deprecated.IPacket.BeforeSerialisation"/>. + </summary> + <typeparam name="T">The packet type that will be serialised.</typeparam> + <param name="serialisable">The packet instance that should be serialised.</param> + <returns>The serialised instance.</returns> + </member> + <member name="M:NetSharp.Deprecated.SerialisedPacket.To``1(NetSharp.Deprecated.SerialisedPacket@)"> + <summary> + Deserialises and returns a packet instance of the given type from the <see cref="T:NetSharp.Deprecated.SerialisedPacket"/> instance + that was given. This method invokes <see cref="M:NetSharp.Deprecated.IPacket.AfterDeserialisation"/>. + </summary> + <typeparam name="T">The packet type to which the packet should be deserialised.</typeparam> + <param name="instance">The serialised packet instance that should be deserialised.</param> + <returns>The deserialised instance.</returns> + </member> + <member name="T:NetSharp.Deprecated.ComplexPacketHandler`2"> + <summary> + Represents a method that receives a request packet of the given type (<typeparamref name="TReq"/>) and + handles the request, returning a response packet of the given type (<typeparamref name="TRep"/>). + </summary> + <typeparam name="TReq">The type of request packet handled by this delegate method.</typeparam> + <typeparam name="TRep">The type of response packet returned by this delegate method.</typeparam> + <param name="requestPacket">The request packet that should be handled by this delegate method.</param> + <param name="remoteEndPoint">The remote endpoint from which the request originated.</param> + <returns>The response packet to send back to the remote endpoint from which the request originated.</returns> + </member> + <member name="T:NetSharp.Deprecated.SimplePacketHandler`1"> + <summary> + Represents a method that receives a simple request packet of the given type (<typeparamref name="TReq"/>) and + handles the request, not returning any response packets. + </summary> + <typeparam name="TReq">The type of request packet handled by this delegate method.</typeparam> + <param name="requestPacket">The request packet that should be handled by this delegate method.</param> + <param name="remoteEndPoint">The remote endpoint from which the request originated.</param> + </member> + <member name="T:NetSharp.Deprecated.Server"> + <summary> + Provides methods for handling connected <see cref="T:NetSharp.Deprecated.IClient"/> instances. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.complexPacketHandlers"> + <summary> + Maps a packet type id to the complex packet handler for that packet type. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.requestPacketDeserialisers"> + <summary> + Maps a packet type id to the raw packet deserialiser that deserialises raw packets to + <see cref="T:NetSharp.Deprecated.IRequestPacket"/> implementors. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.serverShutdownCancellationTokenSource"> + <summary> + Cancellation token source to stop handling client sockets when the server should be shut down. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.simplePacketHandlers"> + <summary> + Maps a packet type id to the simple packet handler for that packet type. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.#ctor"> + <summary> + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.Server"/> class. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.Finalize"> + <summary> + Destroys an instance of the <see cref="T:NetSharp.Deprecated.Server"/> class. + </summary> + </member> + <member name="T:NetSharp.Deprecated.Server.RawRequestPacketDeserialiser"> + <summary> + Represents a method that receives a raw packet, and deserialises it into an <see cref="T:NetSharp.Deprecated.IRequestPacket"/> implementor. + </summary> + <param name="rawPacket">The raw packet that was received from the network.</param> + <returns>The deserialised instance of the packet.</returns> + </member> + <member name="M:NetSharp.Deprecated.Server.RegisterInternalPacketHandlers"> + <summary> + Registers packet handlers for every internal library packet. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.PendingConnectionBacklog"> + <summary> + The maximum number of connections that are allowed in the connection backlog. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.DefaultNetworkOperationTimeout"> + <summary> + The default timeout value for all network operations. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.serverShutdownCancellationToken"> + <summary> + The cancellation token that will be set when the server must be shut down. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.socket"> + <summary> + The <see cref="T:System.Net.Sockets.Socket"/> underlying the connection. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.socketOptions"> + <summary> + Backing field for the <see cref="P:NetSharp.Deprecated.Server.SocketOptions"/> property. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.runServer"> + <summary> + Whether the server should be ran. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.#ctor(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType)"> + <summary> + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.Server"/> class. + </summary> + <param name="socketType">The socket type for the underlying socket.</param> + <param name="protocolType">The protocol type for the underlying socket.</param> + <param name="socketManager">The <see cref="!:Utils.Socket_Options.SocketOptions"/> implementation to use.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.#ctor(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,System.TimeSpan)"> + <summary> + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.Server"/> class. + </summary> + <param name="socketType">The socket type for the underlying socket.</param> + <param name="protocolType">The protocol type for the underlying socket.</param> + <param name="socketManager">The <see cref="!:Utils.Socket_Options.SocketOptions"/> manager to use.</param> + <param name="networkOperationTimeout">The timeout value for send and receive operations over the network.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.DeserialiseRequestPacket(System.UInt32,NetSharp.Deprecated.SerialisedPacket@)"> + <summary> + Deserialises the given <see cref="T:NetSharp.Packets.NetworkPacket"/> struct into an <see cref="T:NetSharp.Deprecated.IRequestPacket"/> implementor. + </summary> + <param name="packetType">The type id of packet that we should deserialise to.</param> + <param name="rawRequestPacket">The packet that should be deserialised.</param> + <returns>The deserialised packet instance, cast to the <see cref="T:NetSharp.Deprecated.IRequestPacket"/> interface.</returns> + </member> + <member name="M:NetSharp.Deprecated.Server.Dispose(System.Boolean)"> + <summary> + Disposes of this <see cref="T:NetSharp.Deprecated.Server"/> instance. + </summary> + <param name="disposing">Whether this instance is being disposed.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.DoHandleClientAsync(System.Object)"> + <summary> + Provides a task that represents the handling of a client. Calls the abstract <see cref="M:NetSharp.Deprecated.Server.HandleClientAsync(NetSharp.Deprecated.Server.ClientHandlerArgs,System.Threading.CancellationToken)"/> method. + </summary> + <param name="clientHandlerArgsObj">The object representing the passed <see cref="T:NetSharp.Deprecated.Server.ClientHandlerArgs"/> instance.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.HandleClientAsync(NetSharp.Deprecated.Server.ClientHandlerArgs,System.Threading.CancellationToken)"> + <summary> + Handles a client asynchronously. + </summary> + <param name="args">The client handler arguments that should be passed to the client handler.</param> + <param name="cancellationToken">Cancellation token set when the server is shutting down.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.HandleRequestPacket(System.UInt32,NetSharp.Deprecated.IRequestPacket@,System.Net.EndPoint@)"> + <summary> + Handles the given request packet with a registered packet handler. In this case, a complex packet handler + will override any registered simple packet handlers. + </summary> + <param name="packetType">The type id of the packet that we should handle.</param> + <param name="requestPacket">The packet instance that should be handled.</param> + <param name="remoteEndPoint">The remote endpoint from which the request packet originated.</param> + <returns>The response packet that should be sent back to the remote endpoint.</returns> + </member> + <member name="M:NetSharp.Deprecated.Server.OnClientConnected(System.Net.EndPoint)"> + <summary> + Invokes the <see cref="E:NetSharp.Deprecated.Server.ClientConnected"/> event. + </summary> + <param name="remoteEndPoint">The remote endpoint with which a connection was made.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.OnClientDisconnected(System.Net.EndPoint)"> + <summary> + Invokes the <see cref="E:NetSharp.Deprecated.Server.ClientDisconnected"/> event. + </summary> + <param name="remoteEndPoint">The remote endpoint with which a connection was lost.</param> + </member> + <member name="M:NetSharp.Deprecated.Server.OnServerStarted"> + <summary> + Invokes the <see cref="E:NetSharp.Deprecated.Server.ServerStarted"/> event. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.OnServerStopped"> + <summary> + Invokes the <see cref="E:NetSharp.Deprecated.Server.ServerStopped"/> event. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.TryBind(System.Net.EndPoint,System.TimeSpan)"> + <summary> + Attempts to synchronously bind the underlying socket to the given local endpoint. Blocks. + If the timeout is exceeded the binding attempt is aborted and the method returns false. + </summary> + <param name="localEndPoint">The local endpoint to bind to.</param> + <param name="timeout">The timeout within which to attempt the binding.</param> + <returns>Whether the binding was successful or not.</returns> + </member> + <member name="M:NetSharp.Deprecated.Server.TryBindAsync(System.Net.EndPoint,System.TimeSpan)"> + <summary> + Attempts to asynchronously bind the underlying socket to the given local endpoint. Does not block. + If the timeout is exceeded the binding attempt is aborted and the method returns false. + </summary> + <param name="localEndPoint">The local endpoint to bind to.</param> + <param name="timeout">The timeout within which to attempt the binding.</param> + <returns>Whether the binding was successful or not.</returns> + </member> + <member name="T:NetSharp.Deprecated.Server.ClientHandlerArgs"> + <summary> + Holds information about the arguments passed to every client handler task. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.ClientHandlerArgs.#ctor(System.Net.EndPoint,System.Net.Sockets.Socket)"> + <summary> + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.Server.ClientHandlerArgs"/> struct. + </summary> + <param name="remoteEndPoint">The remote endpoint of the client that should be handled.</param> + <param name="handlerSocket">The handler socket of the client that should be handled.</param> + </member> + <member name="F:NetSharp.Deprecated.Server.ClientHandlerArgs.ClientEndPoint"> + <summary> + The remote endpoint for the client being handled. + </summary> + </member> + <member name="F:NetSharp.Deprecated.Server.ClientHandlerArgs.ClientSocket"> + <summary> + The client handler socket for the client being handled. Is only set if using TCP. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.ClientHandlerArgs.ForTcpClientHandler(System.Net.Sockets.Socket@)"> + <summary> + Constructs a new instance of the <see cref="T:NetSharp.Deprecated.Server.ClientHandlerArgs"/> for a TCP client. + </summary> + <returns>A new instance of the <see cref="T:NetSharp.Deprecated.Server.ClientHandlerArgs"/>, setup for a TCP client.</returns> + </member> + <member name="M:NetSharp.Deprecated.Server.ClientHandlerArgs.ForUdpClientHandler(System.Net.EndPoint@)"> + <summary> + Constructs a new instance of the <see cref="T:NetSharp.Deprecated.Server.ClientHandlerArgs"/> for a UDP client. + </summary> + <returns>A new instance of the <see cref="T:NetSharp.Deprecated.Server.ClientHandlerArgs"/>, setup for a UDP client.</returns> + </member> + <member name="E:NetSharp.Deprecated.Server.ClientConnected"> + <summary> + Signifies that a connection with a remote endpoint has been made. + </summary> + </member> + <member name="E:NetSharp.Deprecated.Server.ClientDisconnected"> + <summary> + Signifies that a connection with a remote endpoint has been lost. + </summary> + </member> + <member name="E:NetSharp.Deprecated.Server.ServerStarted"> + <summary> + Signifies that the server was started and clients will start being accepted. + </summary> + </member> + <member name="E:NetSharp.Deprecated.Server.ServerStopped"> + <summary> + Signifies that the server was stopped and clients will stop being accepted. + </summary> + </member> + <member name="P:NetSharp.Deprecated.Server.NetworkOperationTimeout"> + <summary> + The timeout value for network operations such as sending bytes or receiving bytes over the network. + </summary> + </member> + <member name="P:NetSharp.Deprecated.Server.SocketOptions"> + <summary> + The configured socket options for the underlying connection. + </summary> + </member> + <member name="M:NetSharp.Deprecated.Server.RunAsync(System.Net.EndPoint)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.Server.Shutdown"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.Server.TryDeregisterComplexPacketHandler``2(NetSharp.Deprecated.ComplexPacketHandler{``0,``1}@)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.Server.TryDeregisterSimplePacketHandler``1(NetSharp.Deprecated.SimplePacketHandler{``0}@)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.Server.TryRegisterComplexPacketHandler``2(NetSharp.Deprecated.ComplexPacketHandler{``0,``1})"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.Server.TryRegisterSimplePacketHandler``1(NetSharp.Deprecated.SimplePacketHandler{``0})"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.ServerClientConnection"> + <summary> + Base class for connections, holding methods shared between the <see cref="T:NetSharp.Deprecated.Client"/> and <see cref="T:NetSharp.Deprecated.Server"/> classes. + </summary> + </member> + <member name="F:NetSharp.Deprecated.ServerClientConnection.logger"> + <summary> + The logger to which the server can log messages. + </summary> + </member> + <member name="M:NetSharp.Deprecated.ServerClientConnection.#ctor"> + <summary> + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.ServerClientConnection"/> class. + </summary> + </member> + <member name="M:NetSharp.Deprecated.ServerClientConnection.Dispose(System.Boolean)"> + <summary> + Disposes of this <see cref="T:NetSharp.Deprecated.ServerClientConnection"/> instance. + </summary> + <param name="disposing">Whether this instance is being disposed.</param> + </member> + <member name="M:NetSharp.Deprecated.ServerClientConnection.OnBytesReceived(System.Net.EndPoint,System.Int32)"> + <summary> + Invokes the <see cref="E:NetSharp.Deprecated.ServerClientConnection.BytesReceived"/> event. + </summary> + <param name="remoteEndPoint">The remote endpoint from which the bytes were received.</param> + <param name="bytesReceived">The number of bytes that were received from the remote endpoint.</param> + </member> + <member name="M:NetSharp.Deprecated.ServerClientConnection.OnBytesSent(System.Net.EndPoint,System.Int32)"> + <summary> + Invokes the <see cref="E:NetSharp.Deprecated.ServerClientConnection.BytesSent"/> event. + </summary> + <param name="remoteEndPoint">The remote endpoint to which the bytes were sent.</param> + <param name="bytesSent">The number of bytes that were sent to the remote endpoint.</param> + </member> + <member name="E:NetSharp.Deprecated.ServerClientConnection.BytesReceived"> + <summary> + Signifies that some data has been received from the remote endpoint. + </summary> + </member> + <member name="E:NetSharp.Deprecated.ServerClientConnection.BytesSent"> + <summary> + Signifies that some data was sent to the remote endpoint. + </summary> + </member> + <member name="M:NetSharp.Deprecated.ServerClientConnection.ChangeLoggingStream(System.IO.Stream,NetSharp.Logging.LogLevel)"> + <summary> + Makes the client log to the given stream. + </summary> + <param name="loggingStream">The stream that new messages should be logged to.</param> + <param name="minimumMessageSeverityLevel"> + The minimum severity level that new messages must have to be logged to the stream. + </param> + </member> + <member name="M:NetSharp.Deprecated.ServerClientConnection.Dispose"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.ServerExtensions"> + <summary> + Provides additional methods and functionality to the <see cref="T:NetSharp.Deprecated.Server"/> class. + </summary> + </member> + <member name="M:NetSharp.Deprecated.ServerExtensions.Run(NetSharp.Deprecated.Server,System.Net.IPAddress,System.Int32)"> + <summary> + Starts the server synchronously and starts accepting client connections. Blocks. + </summary> + <param name="instance">The instance on which this extension method should be called.</param> + <param name="localAddress">The local IP address to bind to.</param> + <param name="localPort">The local port to bind to.</param> + </member> + <member name="M:NetSharp.Deprecated.ServerExtensions.Run(NetSharp.Deprecated.Server,System.Net.IPAddress)"> + <summary> + Starts the server synchronously and starts accepting client connections. Blocks. Uses the default connection port. + </summary> + <param name="instance">The instance on which this extension method should be called.</param> + <param name="localAddress">The local IP address to bind to.</param> + </member> + <member name="M:NetSharp.Deprecated.ServerExtensions.RunAsync(NetSharp.Deprecated.Server,System.Net.IPAddress)"> + <summary> + Starts the server asynchronously and starts accepting client connections. Does not block. Uses the default + connection port. + </summary> + <param name="instance">The instance on which this extension method should be called.</param> + <param name="localAddress">The local IP address to bind to.</param> + </member> + <member name="M:NetSharp.Deprecated.ServerExtensions.RunAsync(NetSharp.Deprecated.Server,System.Net.IPAddress,System.Int32)"> + <summary> + Starts the server asynchronously and starts accepting client connections. Does not block. + </summary> + <param name="instance">The instance on which this extension method should be called.</param> + <param name="localAddress">The local IP address to bind to.</param> + <param name="localPort">The local port to bind to.</param> + </member> + <member name="T:NetSharp.Deprecated.SocketOptions"> + <summary> + Allows for manipulation of socket options. + </summary> + </member> + <member name="F:NetSharp.Deprecated.SocketOptions.managedSocket"> + <summary> + The <see cref="T:System.Net.Sockets.Socket"/> instance whose settings are being managed. + </summary> + </member> + <member name="M:NetSharp.Deprecated.SocketOptions.#ctor(System.Net.Sockets.Socket@)"> + <summary> + Initialises a new instance of the <see cref="T:NetSharp.Deprecated.SocketOptions"/> class. + </summary> + <param name="socket">The <see cref="T:System.Net.Sockets.Socket"/> instance whose options should be managed.</param> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.DualMode"> + <summary> + Whether this <see cref="T:System.Net.Sockets.Socket"/> can operate in dual IPv4 / IPv6 mode. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.ForceFlush"> + <summary> + Whether sending a packet flushes underlying <see cref="T:System.Net.Sockets.NetworkStream"/>. + </summary> + <remarks> + This value is only used in a <see cref="T:System.Net.Sockets.TcpClient"/> instance, which uses a <see cref="T:System.Net.Sockets.NetworkStream"/> + to send and receive data. A <see cref="T:System.Net.Sockets.UdpClient"/> is unaffected by this value. + </remarks> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.Fragment"> + <summary> + Whether this <see cref="T:System.Net.Sockets.Socket"/> is allowed to fragment frames that are too large to send in one go. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.HopLimit"> + <summary> + The hop limit for packets sent by this <see cref="T:System.Net.Sockets.Socket"/>. Comparable to IPv4s TTL (Time To Live). + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.IsChecksumEnabled"> + <summary> + Whether a checksum should be created for each UDP packet sent. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.IsRoutingEnabled"> + <summary> + Whether the packet should be sent directly to its destination or allowed to be routed through multiple destinations + first. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.LocalEndPoint"> + <summary> + The local <see cref="T:System.Net.EndPoint"/> for the <see cref="F:NetSharp.Deprecated.SocketOptions.managedSocket"/>. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.LocalIPEndPoint"> + <summary> + The local <see cref="T:System.Net.IPEndPoint"/> for this <see cref="T:System.Net.Sockets.Socket"/> instance. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.RemoteEndPoint"> + <summary> + The remote <see cref="T:System.Net.EndPoint"/> for the <see cref="F:NetSharp.Deprecated.SocketOptions.managedSocket"/>. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.RemoteIPEndPoint"> + <summary> + The remote <see cref="T:System.Net.IPEndPoint"/> that this <see cref="T:System.Net.Sockets.Socket"/> instance communicates with. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.Ttl"> + <summary> + The 'Time To Live' for this <see cref="T:System.Net.Sockets.Socket"/>. + </summary> + </member> + <member name="P:NetSharp.Deprecated.SocketOptions.UseLoopback"> + <summary> + Whether this <see cref="T:System.Net.Sockets.Socket"/> should use a loopback address and bypass hardware. + </summary> + </member> + <member name="T:NetSharp.Deprecated.TcpClient"> + <summary> + Provides methods for TCP communication with a connected <see cref="T:NetSharp.Deprecated.TcpServer"/> instance. + </summary> + </member> + <member name="M:NetSharp.Deprecated.TcpClient.#ctor"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpClient.SendBytesAsync(System.Byte[],System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpClient.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpClient.SendComplexAsync``2(``0,System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpClient.SendSimpleAsync``1(``0,System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.TcpServer"> + <summary> + Provides methods for TCP communication with connected <see cref="T:NetSharp.Deprecated.TcpClient"/> instances. + </summary> + </member> + <member name="M:NetSharp.Deprecated.TcpServer.HandleClientAsync(NetSharp.Deprecated.Server.ClientHandlerArgs,System.Threading.CancellationToken)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpServer.#ctor(System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpServer.#ctor"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.TcpServer.RunAsync(System.Net.EndPoint)"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.TcpSocketOptions"> + <summary> + Allows for manipulation of TCP socket options. + </summary> + </member> + <member name="M:NetSharp.Deprecated.TcpSocketOptions.#ctor(System.Net.Sockets.Socket@)"> + <inheritdoc /> + </member> + <member name="P:NetSharp.Deprecated.TcpSocketOptions.HopLimit"> + <inheritdoc /> + </member> + <member name="P:NetSharp.Deprecated.TcpSocketOptions.IsRoutingEnabled"> + <inheritdoc /> + </member> + <member name="P:NetSharp.Deprecated.TcpSocketOptions.UseLoopback"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.UdpClient"> + <summary> + Provides methods for UDP communication with a connected <see cref="T:NetSharp.Deprecated.UdpServer"/> instance. + </summary> + </member> + <member name="M:NetSharp.Deprecated.UdpClient.#ctor"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpClient.SendBytesAsync(System.Byte[],System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpClient.SendBytesWithResponseAsync(System.Byte[],System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpClient.SendComplexAsync``2(``0,System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpClient.SendSimpleAsync``1(``0,System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.UdpServer"> + <summary> + Provides methods for UDP communication with connected <see cref="T:NetSharp.Deprecated.UdpClient"/> instances. + </summary> + </member> + <member name="F:NetSharp.Deprecated.UdpServer.clientChannelOptions"> + <summary> + The options that should be applied to every channel created to handle a client. + </summary> + </member> + <member name="F:NetSharp.Deprecated.UdpServer.activeClients"> + <summary> + Holds currently connected and active clients, as well as their current received packet queues. + </summary> + </member> + <member name="M:NetSharp.Deprecated.UdpServer.HandleClientAsync(NetSharp.Deprecated.Server.ClientHandlerArgs,System.Threading.CancellationToken)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpServer.#ctor(System.TimeSpan)"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpServer.#ctor"> + <inheritdoc /> + </member> + <member name="M:NetSharp.Deprecated.UdpServer.RunAsync(System.Net.EndPoint)"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Deprecated.UdpSocketOptions"> + <summary> + Allows for manipulation of UDP socket options. + </summary> + </member> + <member name="M:NetSharp.Deprecated.UdpSocketOptions.#ctor(System.Net.Sockets.Socket@)"> + <inheritdoc /> + </member> + <member name="P:NetSharp.Deprecated.UdpSocketOptions.HopLimit"> + <inheritdoc /> + </member> + <member name="P:NetSharp.Deprecated.UdpSocketOptions.IsRoutingEnabled"> + <inheritdoc /> + </member> + <member name="P:NetSharp.Deprecated.UdpSocketOptions.UseLoopback"> + <inheritdoc /> + </member> + <member name="T:NetSharp.Extensions.ConnectionExtensions"> + <summary> + Provides additional methods and functionality to the <see cref="T:NetSharp.Connection"/> class. + </summary> + </member> + <member name="T:NetSharp.Logging.LogLevel"> + <summary> + Specifies the severity level of a log message. + </summary> + </member> + <member name="F:NetSharp.Logging.LogLevel.Info"> + <summary> + The logged message contains some information. Lowest severity. + </summary> + </member> + <member name="F:NetSharp.Logging.LogLevel.Warn"> + <summary> + The logged message contains a warning. Higher severity. + </summary> + </member> + <member name="F:NetSharp.Logging.LogLevel.Error"> + <summary> + The logged message contains details about an error. Higher severity. + </summary> + </member> + <member name="F:NetSharp.Logging.LogLevel.Exception"> + <summary> + The logged message contains details about an exception. Highest severity. + </summary> + </member> + <member name="T:NetSharp.Logging.Logger"> + <summary> + A simple logger capable of writing text to a stream. + </summary> + </member> + <member name="F:NetSharp.Logging.Logger.loggingStream"> + <summary> + The stream to which messages will be logged. + </summary> + </member> + <member name="F:NetSharp.Logging.Logger.minimumSeverity"> + <summary> + The minimum severity that log messages need to be logged to the underlying stream. + </summary> + </member> + <member name="F:NetSharp.Logging.Logger.writer"> + <summary> + The text writer we will use to log messages to the underlying stream. </summary> </member> <member name="M:NetSharp.Logging.Logger.#ctor(System.IO.Stream,NetSharp.Logging.LogLevel)"> @@ -1098,11 +1494,6 @@ <param name="header">The header for the packet.</param> <param name="footer">The footer for the packet.</param> </member> - <member name="F:NetSharp.Packets.NetworkPacket.PacketSize"> - <summary> - The size of each packet, including its header, footer, and data segment. - </summary> - </member> <member name="F:NetSharp.Packets.NetworkPacket.DataSegmentSize"> <summary> The number of bytes allocated in each packet for user data. @@ -1118,6 +1509,11 @@ The number of bytes taken up in each packet by its header. </summary> </member> + <member name="F:NetSharp.Packets.NetworkPacket.PacketSize"> + <summary> + The size of each packet, including its header, footer, and data segment. + </summary> + </member> <member name="F:NetSharp.Packets.NetworkPacket.DataBuffer"> <summary> The data held in this packet. @@ -1244,428 +1640,181 @@ <typeparam name="TPacket">The packet type whose id to fetch.</typeparam> <returns>The id of the packet type given.</returns> </member> - <member name="M:NetSharp.Packets.PacketRegistry.GetPacketType(System.UInt32)"> - <summary> - Returns the packet type associated with the given id. - </summary> - <param name="packetTypeId">The packet id whose mapped type to fetch.</param> - <returns>The packet type mapped by the given id.</returns> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.GetRequestPacketType``1"> - <summary> - Returns the type of request packet mapped by the given response packet type. - </summary> - <typeparam name="TResponse">The response packet type whose request packet type to fetch.</typeparam> - <returns>The request packet type, <c>null</c> if no type is mapped.</returns> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.GetRequestPacketType(System.Type)"> - <summary> - Returns the type of request packet mapped by the given response packet type. - </summary> - <param name="responsePacketType">The response packet type whose request packet type to fetch.</param> - <returns>The request packet type, <c>null</c> if no type is mapped.</returns> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.GetResponsePacketType``1"> - <summary> - Returns the type of response packet mapped by the given request packet type. - </summary> - <typeparam name="TRequest">The request packet type whose response packet type to fetch.</typeparam> - <returns>The response packet type, <c>null</c> if no type is mapped.</returns> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.GetResponsePacketType(System.Type)"> - <summary> - Returns the type of response packet mapped by the given request packet type. - </summary> - <param name="requestPacketType">The request packet type whose response packet type to fetch.</param> - <returns>The response packet type, <c>null</c> if no type is mapped.</returns> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketSourceAssemblies(System.Reflection.Assembly[])"> - <summary> - Rebuilds the packet registry, by registering every <see cref="T:NetSharp.Interfaces.IPacket"/> inheritor in the given assemblies. - </summary> - <param name="packetSourceAssemblies"> - The assemblies from which the packet types to register are sourced. - </param> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketSourceAssembly(System.Reflection.Assembly)"> - <summary> - Registers all the <see cref="T:NetSharp.Interfaces.IPacket"/> implementors in the given assembly. - </summary> - <param name="packetSourceAssembly">The assembly whose packet types to register.</param> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketType(System.Type,System.Type)"> - <summary> - Registers the given packet type to the registry. - </summary> - <param name="requestPacketType">The request packet type to register, if it is not registered.</param> - <param name="responsePacketType">The response packet associated with the request packet.</param> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketTypes(System.Collections.Generic.Dictionary{System.Type,System.Type})"> - <summary> - Registers the given packet types to the registry. - </summary> - <param name="requestToResponsePacketTypeMap"> - The dictionary mapping the request packet types to register, to their relevant response packet types. - The response packet type can be null; then the request packet type is treated as a 'simple' packet. - </param> - </member> - <member name="M:NetSharp.Packets.PacketRegistry.#cctor"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Packets.PacketRegistry"/> class. - </summary> - </member> - <member name="T:NetSharp.Packets.PacketTypeIdAttribute"> - <summary> - Allows the placing of a custom packet type on a class or struct. This is used if the class or struct - inherits from <see cref="T:NetSharp.Interfaces.IRequestPacket"/> or <see cref="T:NetSharp.Interfaces.IResponsePacket`1"/>. - </summary> - </member> - <member name="M:NetSharp.Packets.PacketTypeIdAttribute.#ctor(System.UInt32)"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Packets.PacketTypeIdAttribute"/> attribute. - </summary> - <param name="type">The custom type id that the decorated packet type should have.</param> - </member> - <member name="P:NetSharp.Packets.PacketTypeIdAttribute.Id"> - <summary> - The custom type id that the decorated packet type should have. This overrides the automatically generated id. - </summary> - </member> - <member name="M:NetSharp.Packets.SerialisedPacket.From``1(``0)"> - <summary> - Serialises the given serialisable packet instance and returns the <see cref="T:NetSharp.Packets.SerialisedPacket"/> instance - that was generated. This method invokes <see cref="M:NetSharp.Interfaces.IPacket.BeforeSerialisation"/>. - </summary> - <typeparam name="T">The packet type that will be serialised.</typeparam> - <param name="serialisable">The packet instance that should be serialised.</param> - <returns>The serialised instance.</returns> - </member> - <member name="M:NetSharp.Packets.SerialisedPacket.To``1(NetSharp.Packets.SerialisedPacket@)"> - <summary> - Deserialises and returns a packet instance of the given type from the <see cref="T:NetSharp.Packets.SerialisedPacket"/> instance - that was given. This method invokes <see cref="M:NetSharp.Interfaces.IPacket.AfterDeserialisation"/>. - </summary> - <typeparam name="T">The packet type to which the packet should be deserialised.</typeparam> - <param name="instance">The serialised packet instance that should be deserialised.</param> - <returns>The deserialised instance.</returns> - </member> - <member name="T:NetSharp.ComplexPacketHandler`2"> - <summary> - Represents a method that receives a request packet of the given type (<typeparamref name="TReq"/>) and - handles the request, returning a response packet of the given type (<typeparamref name="TRep"/>). - </summary> - <typeparam name="TReq">The type of request packet handled by this delegate method.</typeparam> - <typeparam name="TRep">The type of response packet returned by this delegate method.</typeparam> - <param name="requestPacket">The request packet that should be handled by this delegate method.</param> - <param name="remoteEndPoint">The remote endpoint from which the request originated.</param> - <returns>The response packet to send back to the remote endpoint from which the request originated.</returns> - </member> - <member name="T:NetSharp.SimplePacketHandler`1"> - <summary> - Represents a method that receives a simple request packet of the given type (<typeparamref name="TReq"/>) and - handles the request, not returning any response packets. - </summary> - <typeparam name="TReq">The type of request packet handled by this delegate method.</typeparam> - <param name="requestPacket">The request packet that should be handled by this delegate method.</param> - <param name="remoteEndPoint">The remote endpoint from which the request originated.</param> - </member> - <member name="T:NetSharp.Server"> - <summary> - Provides methods for handling connected <see cref="T:NetSharp.Interfaces.IClient"/> instances. - </summary> - </member> - <member name="F:NetSharp.Server.complexPacketHandlers"> - <summary> - Maps a packet type id to the complex packet handler for that packet type. - </summary> - </member> - <member name="F:NetSharp.Server.requestPacketDeserialisers"> - <summary> - Maps a packet type id to the raw packet deserialiser that deserialises raw packets to - <see cref="T:NetSharp.Interfaces.IRequestPacket"/> implementors. - </summary> - </member> - <member name="F:NetSharp.Server.serverShutdownCancellationTokenSource"> - <summary> - Cancellation token source to stop handling client sockets when the server should be shut down. - </summary> - </member> - <member name="F:NetSharp.Server.simplePacketHandlers"> - <summary> - Maps a packet type id to the simple packet handler for that packet type. - </summary> - </member> - <member name="M:NetSharp.Server.#ctor"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Server"/> class. - </summary> - </member> - <member name="M:NetSharp.Server.Finalize"> - <summary> - Destroys an instance of the <see cref="T:NetSharp.Server"/> class. - </summary> - </member> - <member name="T:NetSharp.Server.RawRequestPacketDeserialiser"> - <summary> - Represents a method that receives a raw packet, and deserialises it into an <see cref="T:NetSharp.Interfaces.IRequestPacket"/> implementor. - </summary> - <param name="rawPacket">The raw packet that was received from the network.</param> - <returns>The deserialised instance of the packet.</returns> - </member> - <member name="M:NetSharp.Server.RegisterInternalPacketHandlers"> - <summary> - Registers packet handlers for every internal library packet. - </summary> - </member> - <member name="F:NetSharp.Server.PendingConnectionBacklog"> - <summary> - The maximum number of connections that are allowed in the connection backlog. - </summary> - </member> - <member name="F:NetSharp.Server.DefaultNetworkOperationTimeout"> - <summary> - The default timeout value for all network operations. - </summary> - </member> - <member name="F:NetSharp.Server.serverShutdownCancellationToken"> - <summary> - The cancellation token that will be set when the server must be shut down. - </summary> - </member> - <member name="F:NetSharp.Server.socket"> - <summary> - The <see cref="T:System.Net.Sockets.Socket"/> underlying the connection. - </summary> - </member> - <member name="F:NetSharp.Server.socketOptions"> - <summary> - Backing field for the <see cref="P:NetSharp.Server.SocketOptions"/> property. - </summary> - </member> - <member name="F:NetSharp.Server.runServer"> - <summary> - Whether the server should be ran. - </summary> - </member> - <member name="M:NetSharp.Server.#ctor(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,NetSharp.Utils.Socket_Options.SocketOptionManager)"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Server"/> class. - </summary> - <param name="socketType">The socket type for the underlying socket.</param> - <param name="protocolType">The protocol type for the underlying socket.</param> - <param name="socketManager">The <see cref="T:NetSharp.Utils.Socket_Options.SocketOptions"/> manager to use.</param> - </member> - <member name="M:NetSharp.Server.#ctor(System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,NetSharp.Utils.Socket_Options.SocketOptionManager,System.TimeSpan)"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Server"/> class. - </summary> - <param name="socketType">The socket type for the underlying socket.</param> - <param name="protocolType">The protocol type for the underlying socket.</param> - <param name="socketManager">The <see cref="T:NetSharp.Utils.Socket_Options.SocketOptions"/> manager to use.</param> - <param name="networkOperationTimeout">The timeout value for send and receive operations over the network.</param> - </member> - <member name="M:NetSharp.Server.DeserialiseRequestPacket(System.UInt32,NetSharp.Packets.SerialisedPacket@)"> - <summary> - Deserialises the given <see cref="T:NetSharp.Packets.NetworkPacket"/> struct into an <see cref="T:NetSharp.Interfaces.IRequestPacket"/> implementor. - </summary> - <param name="packetType">The type id of packet that we should deserialise to.</param> - <param name="rawRequestPacket">The packet that should be deserialised.</param> - <returns>The deserialised packet instance, cast to the <see cref="T:NetSharp.Interfaces.IRequestPacket"/> interface.</returns> - </member> - <member name="M:NetSharp.Server.Dispose(System.Boolean)"> - <summary> - Disposes of this <see cref="T:NetSharp.Server"/> instance. - </summary> - <param name="disposing">Whether this instance is being disposed.</param> - </member> - <member name="M:NetSharp.Server.DoHandleClientAsync(System.Object)"> - <summary> - Provides a task that represents the handling of a client. Calls the abstract <see cref="M:NetSharp.Server.HandleClientAsync(NetSharp.Server.ClientHandlerArgs,System.Threading.CancellationToken)"/> method. - </summary> - <param name="clientHandlerArgsObj">The object representing the passed <see cref="T:NetSharp.Server.ClientHandlerArgs"/> instance.</param> - </member> - <member name="M:NetSharp.Server.HandleClientAsync(NetSharp.Server.ClientHandlerArgs,System.Threading.CancellationToken)"> - <summary> - Handles a client asynchronously. - </summary> - <param name="args">The client handler arguments that should be passed to the client handler.</param> - <param name="cancellationToken">Cancellation token set when the server is shutting down.</param> - </member> - <member name="M:NetSharp.Server.HandleRequestPacket(System.UInt32,NetSharp.Interfaces.IRequestPacket@,System.Net.EndPoint@)"> - <summary> - Handles the given request packet with a registered packet handler. In this case, a complex packet handler - will override any registered simple packet handlers. - </summary> - <param name="packetType">The type id of the packet that we should handle.</param> - <param name="requestPacket">The packet instance that should be handled.</param> - <param name="remoteEndPoint">The remote endpoint from which the request packet originated.</param> - <returns>The response packet that should be sent back to the remote endpoint.</returns> - </member> - <member name="M:NetSharp.Server.OnClientConnected(System.Net.EndPoint)"> - <summary> - Invokes the <see cref="E:NetSharp.Server.ClientConnected"/> event. - </summary> - <param name="remoteEndPoint">The remote endpoint with which a connection was made.</param> - </member> - <member name="M:NetSharp.Server.OnClientDisconnected(System.Net.EndPoint)"> - <summary> - Invokes the <see cref="E:NetSharp.Server.ClientDisconnected"/> event. - </summary> - <param name="remoteEndPoint">The remote endpoint with which a connection was lost.</param> - </member> - <member name="M:NetSharp.Server.OnServerStarted"> - <summary> - Invokes the <see cref="E:NetSharp.Server.ServerStarted"/> event. - </summary> - </member> - <member name="M:NetSharp.Server.OnServerStopped"> - <summary> - Invokes the <see cref="E:NetSharp.Server.ServerStopped"/> event. - </summary> - </member> - <member name="M:NetSharp.Server.TryBind(System.Net.EndPoint,System.TimeSpan)"> - <summary> - Attempts to synchronously bind the underlying socket to the given local endpoint. Blocks. - If the timeout is exceeded the binding attempt is aborted and the method returns false. - </summary> - <param name="localEndPoint">The local endpoint to bind to.</param> - <param name="timeout">The timeout within which to attempt the binding.</param> - <returns>Whether the binding was successful or not.</returns> - </member> - <member name="M:NetSharp.Server.TryBindAsync(System.Net.EndPoint,System.TimeSpan)"> - <summary> - Attempts to asynchronously bind the underlying socket to the given local endpoint. Does not block. - If the timeout is exceeded the binding attempt is aborted and the method returns false. - </summary> - <param name="localEndPoint">The local endpoint to bind to.</param> - <param name="timeout">The timeout within which to attempt the binding.</param> - <returns>Whether the binding was successful or not.</returns> - </member> - <member name="T:NetSharp.Server.ClientHandlerArgs"> + <member name="M:NetSharp.Packets.PacketRegistry.GetPacketType(System.UInt32)"> <summary> - Holds information about the arguments passed to every client handler task. + Returns the packet type associated with the given id. </summary> + <param name="packetTypeId">The packet id whose mapped type to fetch.</param> + <returns>The packet type mapped by the given id.</returns> </member> - <member name="M:NetSharp.Server.ClientHandlerArgs.#ctor(System.Net.EndPoint,System.Net.Sockets.Socket)"> + <member name="M:NetSharp.Packets.PacketRegistry.GetRequestPacketType``1"> <summary> - Initialises a new instance of the <see cref="T:NetSharp.Server.ClientHandlerArgs"/> struct. + Returns the type of request packet mapped by the given response packet type. </summary> - <param name="remoteEndPoint">The remote endpoint of the client that should be handled.</param> - <param name="handlerSocket">The handler socket of the client that should be handled.</param> + <typeparam name="TResponse">The response packet type whose request packet type to fetch.</typeparam> + <returns>The request packet type, <c>null</c> if no type is mapped.</returns> </member> - <member name="F:NetSharp.Server.ClientHandlerArgs.ClientEndPoint"> + <member name="M:NetSharp.Packets.PacketRegistry.GetRequestPacketType(System.Type)"> <summary> - The remote endpoint for the client being handled. + Returns the type of request packet mapped by the given response packet type. </summary> + <param name="responsePacketType">The response packet type whose request packet type to fetch.</param> + <returns>The request packet type, <c>null</c> if no type is mapped.</returns> </member> - <member name="F:NetSharp.Server.ClientHandlerArgs.ClientSocket"> + <member name="M:NetSharp.Packets.PacketRegistry.GetResponsePacketType``1"> <summary> - The client handler socket for the client being handled. Is only set if using TCP. + Returns the type of response packet mapped by the given request packet type. </summary> + <typeparam name="TRequest">The request packet type whose response packet type to fetch.</typeparam> + <returns>The response packet type, <c>null</c> if no type is mapped.</returns> </member> - <member name="M:NetSharp.Server.ClientHandlerArgs.ForTcpClientHandler(System.Net.Sockets.Socket@)"> + <member name="M:NetSharp.Packets.PacketRegistry.GetResponsePacketType(System.Type)"> <summary> - Constructs a new instance of the <see cref="T:NetSharp.Server.ClientHandlerArgs"/> for a TCP client. + Returns the type of response packet mapped by the given request packet type. </summary> - <returns>A new instance of the <see cref="T:NetSharp.Server.ClientHandlerArgs"/>, setup for a TCP client.</returns> + <param name="requestPacketType">The request packet type whose response packet type to fetch.</param> + <returns>The response packet type, <c>null</c> if no type is mapped.</returns> </member> - <member name="M:NetSharp.Server.ClientHandlerArgs.ForUdpClientHandler(System.Net.EndPoint@)"> + <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketSourceAssemblies(System.Reflection.Assembly[])"> <summary> - Constructs a new instance of the <see cref="T:NetSharp.Server.ClientHandlerArgs"/> for a UDP client. + Rebuilds the packet registry, by registering every <see cref="T:NetSharp.Deprecated.IPacket"/> inheritor in the given assemblies. </summary> - <returns>A new instance of the <see cref="T:NetSharp.Server.ClientHandlerArgs"/>, setup for a UDP client.</returns> + <param name="packetSourceAssemblies"> + The assemblies from which the packet types to register are sourced. + </param> </member> - <member name="E:NetSharp.Server.ClientConnected"> + <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketSourceAssembly(System.Reflection.Assembly)"> <summary> - Signifies that a connection with a remote endpoint has been made. + Registers all the <see cref="T:NetSharp.Deprecated.IPacket"/> implementors in the given assembly. </summary> + <param name="packetSourceAssembly">The assembly whose packet types to register.</param> </member> - <member name="E:NetSharp.Server.ClientDisconnected"> + <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketType(System.Type,System.Type)"> <summary> - Signifies that a connection with a remote endpoint has been lost. + Registers the given packet type to the registry. </summary> + <param name="requestPacketType">The request packet type to register, if it is not registered.</param> + <param name="responsePacketType">The response packet associated with the request packet.</param> </member> - <member name="E:NetSharp.Server.ServerStarted"> + <member name="M:NetSharp.Packets.PacketRegistry.RegisterPacketTypes(System.Collections.Generic.Dictionary{System.Type,System.Type})"> <summary> - Signifies that the server was started and clients will start being accepted. + Registers the given packet types to the registry. </summary> + <param name="requestToResponsePacketTypeMap"> + The dictionary mapping the request packet types to register, to their relevant response packet types. + The response packet type can be null; then the request packet type is treated as a 'simple' packet. + </param> </member> - <member name="E:NetSharp.Server.ServerStopped"> + <member name="M:NetSharp.Packets.PacketRegistry.#cctor"> <summary> - Signifies that the server was stopped and clients will stop being accepted. + Initialises a new instance of the <see cref="T:NetSharp.Packets.PacketRegistry"/> class. </summary> </member> - <member name="P:NetSharp.Server.NetworkOperationTimeout"> + <member name="T:NetSharp.Packets.PacketTypeIdAttribute"> <summary> - The timeout value for network operations such as sending bytes or receiving bytes over the network. + Allows the placing of a custom packet type on a class or struct. This is used if the class or struct + inherits from <see cref="T:NetSharp.Deprecated.IRequestPacket"/> or <see cref="T:NetSharp.Deprecated.IResponsePacket`1"/>. </summary> </member> - <member name="P:NetSharp.Server.SocketOptions"> + <member name="M:NetSharp.Packets.PacketTypeIdAttribute.#ctor(System.UInt32)"> <summary> - The configured socket options for the underlying connection. + Initialises a new instance of the <see cref="T:NetSharp.Packets.PacketTypeIdAttribute"/> attribute. </summary> + <param name="type">The custom type id that the decorated packet type should have.</param> </member> - <member name="M:NetSharp.Server.RunAsync(System.Net.EndPoint)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Server.Shutdown"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Server.TryDeregisterComplexPacketHandler``2(NetSharp.ComplexPacketHandler{``0,``1}@)"> - <inheritdoc /> + <member name="P:NetSharp.Packets.PacketTypeIdAttribute.Id"> + <summary> + The custom type id that the decorated packet type should have. This overrides the automatically generated id. + </summary> </member> - <member name="M:NetSharp.Server.TryDeregisterSimplePacketHandler``1(NetSharp.SimplePacketHandler{``0}@)"> + <member name="P:NetSharp.Pipelines.PacketPipelineStage`2.StageInput"> <inheritdoc /> </member> - <member name="M:NetSharp.Server.TryRegisterComplexPacketHandler``2(NetSharp.ComplexPacketHandler{``0,``1})"> + <member name="P:NetSharp.Pipelines.PacketPipelineStage`2.StageOutput"> <inheritdoc /> </member> - <member name="M:NetSharp.Server.TryRegisterSimplePacketHandler``1(NetSharp.SimplePacketHandler{``0})"> + <member name="M:NetSharp.Pipelines.PacketPipelineStage`2.Process(`0)"> <inheritdoc /> </member> - <member name="T:NetSharp.Servers.TcpServer"> + <member name="T:NetSharp.Sockets.SocketAcceptor"> <summary> - Provides methods for TCP communication with connected <see cref="T:NetSharp.Clients.TcpClient"/> instances. + Helper class providing awaitable wrappers around asynchronous Accept, Connect, and Disconnect operations. </summary> </member> - <member name="M:NetSharp.Servers.TcpServer.HandleClientAsync(NetSharp.Server.ClientHandlerArgs,System.Threading.CancellationToken)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Servers.TcpServer.#ctor(System.TimeSpan)"> - <inheritdoc /> - </member> - <member name="M:NetSharp.Servers.TcpServer.#ctor"> - <inheritdoc /> + <member name="M:NetSharp.Sockets.SocketAcceptor.AcceptAsync(System.Net.Sockets.Socket,System.Threading.CancellationToken)"> + <summary> + Provides an awaitable wrapper around an asynchronous socket accept operation. + </summary> + <param name="socket">The socket which should be used to accept an incoming connection attempt.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> + <returns>The accepted socket.</returns> </member> - <member name="M:NetSharp.Servers.TcpServer.RunAsync(System.Net.EndPoint)"> - <inheritdoc /> + <member name="M:NetSharp.Sockets.SocketAcceptor.ConnectAsync(System.Net.Sockets.Socket,System.Net.EndPoint,System.Threading.CancellationToken)"> + <summary> + Provides an awaitable wrapper around an asynchronous socket connect operation. + </summary> + <param name="socket">The socket which should asynchronously connect to the remote endpoint.</param> + <param name="remoteEndPoint">The remote endpoint to which the socket should connect.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> </member> - <member name="T:NetSharp.Servers.UdpServer"> + <member name="M:NetSharp.Sockets.SocketAcceptor.DisconnectAsync(System.Net.Sockets.Socket,System.Threading.CancellationToken)"> <summary> - Provides methods for UDP communication with connected <see cref="T:NetSharp.Clients.UdpClient"/> instances. + Provides an awaitable wrapper around an asynchronous socket disconnect operation. </summary> + <param name="socket">The socket which should asynchronously disconnect from its remote endpoint.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> </member> - <member name="F:NetSharp.Servers.UdpServer.clientChannelOptions"> + <member name="T:NetSharp.Sockets.SocketReader"> <summary> - The options that should be applied to every channel created to handle a client. + Helper class providing awaitable wrappers around asynchronous Receive and ReceiveFrom operations. </summary> </member> - <member name="F:NetSharp.Servers.UdpServer.activeClients"> + <member name="M:NetSharp.Sockets.SocketReader.ReceiveAsync(System.Net.Sockets.Socket,System.Net.Sockets.SocketFlags,System.Memory{System.Byte},System.Threading.CancellationToken)"> <summary> - Holds currently connected and active clients, as well as their current received packet queues. + Provides an awaitable wrapper around an asynchronous socket receive operation. </summary> + <param name="socket">The socket which should receive data from the remote connection.</param> + <param name="socketFlags">The socket flags associated with the receive operation.</param> + <param name="inputBuffer">The memory buffer into which received data will be stored.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> + <returns>The result of the receive operation.</returns> </member> - <member name="M:NetSharp.Servers.UdpServer.HandleClientAsync(NetSharp.Server.ClientHandlerArgs,System.Threading.CancellationToken)"> - <inheritdoc /> + <member name="M:NetSharp.Sockets.SocketReader.ReceiveFromAsync(System.Net.Sockets.Socket,System.Net.EndPoint,System.Net.Sockets.SocketFlags,System.Memory{System.Byte},System.Threading.CancellationToken)"> + <summary> + Provides an awaitable wrapper around an asynchronous socket receive operation. + </summary> + <param name="socket">The socket which should receive data from the remote endpoint.</param> + <param name="remoteEndPoint">The remove endpoint from which data should be received.</param> + <param name="socketFlags">The socket flags associated with the receive operation.</param> + <param name="inputBuffer">The memory buffer into which received data will be stored.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> + <returns>The result of the receive operation.</returns> </member> - <member name="M:NetSharp.Servers.UdpServer.#ctor(System.TimeSpan)"> - <inheritdoc /> + <member name="T:NetSharp.Sockets.SocketWriter"> + <summary> + Helper class providing awaitable wrappers around asynchronous Send and SendTo operations. + </summary> </member> - <member name="M:NetSharp.Servers.UdpServer.#ctor"> - <inheritdoc /> + <member name="M:NetSharp.Sockets.SocketWriter.SendAsync(System.Net.Sockets.Socket,System.Net.Sockets.SocketFlags,System.Memory{System.Byte},System.Threading.CancellationToken)"> + <summary> + Provides an awaitable wrapper around an asynchronous socket send operation. + </summary> + <param name="socket">The socket which should send the data to its remote connection.</param> + <param name="socketFlags">The socket flags associated with the send operation.</param> + <param name="outputBuffer">The data buffer which should be sent.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> + <returns>The number of bytes of data which were written to the remote connection.</returns> </member> - <member name="M:NetSharp.Servers.UdpServer.RunAsync(System.Net.EndPoint)"> - <inheritdoc /> + <member name="M:NetSharp.Sockets.SocketWriter.SendToAsync(System.Net.Sockets.Socket,System.Net.EndPoint,System.Net.Sockets.SocketFlags,System.Memory{System.Byte},System.Threading.CancellationToken)"> + <summary> + Provides an awaitable wrapper around an asynchronous socket send operation. + </summary> + <param name="socket">The socket which should send the data to the remote endpoint.</param> + <param name="remoteEndPoint">The remote endpoint to which data should be written.</param> + <param name="socketFlags">The socket flags associated with the send operation.</param> + <param name="outputBuffer">The data buffer which should be sent.</param> + <param name="cancellationToken">The cancellation token to observe for the operation.</param> + <returns>The number of bytes of data which were written to the remote endpoint.</returns> </member> <member name="T:NetSharp.Utils.BiDictionary`2"> <summary> @@ -1866,269 +2015,16 @@ <member name="M:NetSharp.Utils.Conversion.EndianAwareBitConverter.ToUInt64(System.Span{System.Byte},System.Boolean)"> <inheritdoc cref="M:System.BitConverter.ToUInt64(System.ReadOnlySpan{System.Byte})"/> </member> - <member name="T:NetSharp.Utils.NetworkOperations"> - <summary> - Helper class for asynchronously performing common network operations, for both the UDP and TCP protocols. - </summary> - TODO: Implement cancellation support for network operations - TODO: Somehow dont run into the exception below - [Excep] Socket exception while reading bytes from 0.0.0.0:0: System.Net.Sockets.SocketException (10040): Komunikat wysłany na gniazdo datagramu był większy niż wewnętrzny bufor lub przekraczał inny sieciowy limit albo bufor używany do odbierania datagramów był mniejszy niż sam datagram. - at NetSharp.Extensions.SocketTask.GetResult() in G:\Git Repos\EnderRifter\NetSharp\NetSharp\NetSharp\Extensions\SocketExtensions.cs:line 158 - at NetSharp.Utils.NetworkOperations.ReadFromAsync(Socket socket, Int32 count, EndPoint remoteEndPoint, SocketFlags socketFlags) in G:\Git Repos\EnderRifter\NetSharp\NetSharp\NetSharp\Utils\NetworkOperations.cs:line 78 - at NetSharp.Utils.NetworkOperations.ReadPacketFromAsync(Socket socket, EndPoint remoteEndPoint, SocketFlags socketFlags, CancellationToken cancellationToken) in G:\Git Repos\EnderRifter\NetSharp\NetSharp\NetSharp\Utils\NetworkOperations.cs:line 225 - at NetSharp.Connection.DoReceivePacketFromAsync(Socket socket, EndPoint remoteEndPoint, SocketFlags socketFlags, TimeSpan timeout, CancellationToken cancellationToken) in G:\Git Repos\EnderRifter\NetSharp\NetSharp\NetSharp\Connection.cs:line 114 - </member> - <member name="M:NetSharp.Utils.NetworkOperations.ReadAsync(System.Net.Sockets.Socket,System.Int32,System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Reads the specified amount of data from the network, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the read. - </summary> - <param name="socket">The socket which should read data from the network.</param> - <param name="count">The number of bytes to read from the network.</param> - <param name="socketFlags">The socket flags associated with the receive operation.</param> - <returns>The result of the receive operation.</returns> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.ReadFromAsync(System.Net.Sockets.Socket,System.Int32,System.Net.EndPoint,System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Reads a datagram segment of the given length from the given remote endpoint, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the read. - </summary> - <param name="socket">The socket which should read data from the network.</param> - <param name="count">The number of bytes to read from the network.</param> - <param name="remoteEndPoint">The remote endpoint from which data should be read.</param> - <param name="socketFlags">The socket flags associated with the receive operation.</param> - <returns>The result of the receive operation.</returns> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.WriteAsync(System.Net.Sockets.Socket,System.Memory{System.Byte},System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Writes the given data buffer to the network, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the write, and the given <see cref="T:System.Threading.CancellationToken"/> - is used to allow for asynchronous task cancellation. - </summary> - <param name="socket">The socket which should write data to the network.</param> - <param name="buffer">The buffer that should be written to the network.</param> - <param name="socketFlags">The socket flags associated with the send operation.</param> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.WriteToAsync(System.Net.Sockets.Socket,System.Net.EndPoint,System.Memory{System.Byte},System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Writes the given data buffer to the given remote endpoint, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the write, and the given <see cref="T:System.Threading.CancellationToken"/> - is used to allow for asynchronous task cancellation. - </summary> - <param name="socket">The socket which should write data to the network.</param> - <param name="remoteEndPoint">The remote endpoint to which data should be written.</param> - <param name="buffer">The buffer that should be written to the network.</param> - <param name="socketFlags">The socket flags associated with the send operation.</param> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.ReadPacketAsync(System.Net.Sockets.Socket,System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Reads a packet from network, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the read. - </summary> - <param name="socket">The socket which should read the packet from the network.</param> - <param name="socketFlags">The socket flags associated with the receive operation.</param> - <param name="cancellationToken">The cancellation token that should be observed for the duration of the task.</param> - <returns>The read packet, and the endpoint from which it was read.</returns> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.ReadPacketFromAsync(System.Net.Sockets.Socket,System.Net.EndPoint,System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Reads a packet from the given remote endpoint, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the read. - </summary> - <param name="socket">The socket which should read the packet from the network.</param> - <param name="remoteEndPoint">The remote endpoint from which a packet should be read.</param> - <param name="socketFlags">The socket flags associated with the receive operation.</param> - <param name="cancellationToken">The cancellation token that should be observed for the duration of the task.</param> - <returns>The read packet, and the endpoint from which it was read.</returns> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.WritePacketAsync(System.Net.Sockets.Socket,NetSharp.Packets.SerialisedPacket,System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Writes the given packet to the network, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the write. - </summary> - <param name="socket">The socket which should write data to the network.</param> - <param name="serialisedPacket">The packet that should be written to the network.</param> - <param name="socketFlags">The socket flags associated with the send operation.</param> - <param name="cancellationToken">The cancellation token that should be observed for the duration of the task.</param> - </member> - <member name="M:NetSharp.Utils.NetworkOperations.WritePacketToAsync(System.Net.Sockets.Socket,System.Net.EndPoint,NetSharp.Packets.SerialisedPacket,System.Net.Sockets.SocketFlags,System.Threading.CancellationToken)"> - <summary> - Writes the given packet to the given remote endpoint, via the given socket. - The given <see cref="T:System.Net.Sockets.SocketFlags"/> are associated with the write. - </summary> - <param name="socket">The socket which should write data to the network.</param> - <param name="remoteEndPoint">The remote endpoint to which data should be written.</param> - <param name="serialisedPacket">The packet that should be written to the remote endpoint.</param> - <param name="socketFlags">The socket flags associated with the send operation.</param> - <param name="cancellationToken">The cancellation token that should be observed for the duration of the task.</param> - </member> - <member name="T:NetSharp.Utils.Socket_Options.DefaultSocketOptions"> - <summary> - Allows for manipulation of socket options. - </summary> - </member> - <member name="M:NetSharp.Utils.Socket_Options.DefaultSocketOptions.#ctor(System.Net.Sockets.Socket@)"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.DefaultSocketOptions.HopLimit"> - <inheritdoc /> - <exception cref="T:System.NotSupportedException"> - This property is not supported when using the default socket option manager. - </exception> - </member> - <member name="P:NetSharp.Utils.Socket_Options.DefaultSocketOptions.IsRoutingEnabled"> - <inheritdoc /> - <exception cref="T:System.NotSupportedException"> - This property is not supported when using the default socket option manager. - </exception> - </member> - <member name="P:NetSharp.Utils.Socket_Options.DefaultSocketOptions.UseLoopback"> - <inheritdoc /> - <exception cref="T:System.NotSupportedException"> - This property is not supported when using the default socket option manager. - </exception> - </member> - <member name="T:NetSharp.Utils.Socket_Options.SocketOptionManager"> - <summary> - Enumerates the possible socket option manager types to instantiate for a <see cref="T:NetSharp.Client"/> and <see cref="T:NetSharp.Server"/> - instance. - </summary> - </member> - <member name="F:NetSharp.Utils.Socket_Options.SocketOptionManager.Default"> - <summary> - Causes a <see cref="T:NetSharp.Utils.Socket_Options.DefaultSocketOptions"/> instance to be created as the socket option manager. - This means that certain socket options will throw an error, as the socket type is not specified. - </summary> - </member> - <member name="F:NetSharp.Utils.Socket_Options.SocketOptionManager.Tcp"> - <summary> - Causes a <see cref="T:NetSharp.Utils.Socket_Options.TcpSocketOptions"/> instance to be created as the socket option manager. - </summary> - </member> - <member name="F:NetSharp.Utils.Socket_Options.SocketOptionManager.Udp"> - <summary> - Causes a <see cref="T:NetSharp.Utils.Socket_Options.UdpSocketOptions"/> instance to be created as the socket option manager. - </summary> - </member> - <member name="T:NetSharp.Utils.Socket_Options.SocketOptions"> - <summary> - Allows for manipulation of socket options. - </summary> - </member> - <member name="F:NetSharp.Utils.Socket_Options.SocketOptions.managedSocket"> - <summary> - The <see cref="T:System.Net.Sockets.Socket"/> instance whose settings are being managed. - </summary> - </member> - <member name="M:NetSharp.Utils.Socket_Options.SocketOptions.#ctor(System.Net.Sockets.Socket@)"> - <summary> - Initialises a new instance of the <see cref="T:NetSharp.Utils.Socket_Options.SocketOptions"/> class. - </summary> - <param name="socket">The <see cref="T:System.Net.Sockets.Socket"/> instance whose options should be managed.</param> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.DualMode"> - <summary> - Whether this <see cref="T:System.Net.Sockets.Socket"/> can operate in dual IPv4 / IPv6 mode. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.ForceFlush"> - <summary> - Whether sending a packet flushes underlying <see cref="T:System.Net.Sockets.NetworkStream"/>. - </summary> - <remarks> - This value is only used in a <see cref="T:System.Net.Sockets.TcpClient"/> instance, which uses a <see cref="T:System.Net.Sockets.NetworkStream"/> - to send and receive data. A <see cref="T:System.Net.Sockets.UdpClient"/> is unaffected by this value. - </remarks> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.Fragment"> - <summary> - Whether this <see cref="T:System.Net.Sockets.Socket"/> is allowed to fragment frames that are too large to send in one go. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.HopLimit"> - <summary> - The hop limit for packets sent by this <see cref="T:System.Net.Sockets.Socket"/>. Comparable to IPv4s TTL (Time To Live). - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.IsChecksumEnabled"> - <summary> - Whether a checksum should be created for each UDP packet sent. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.IsRoutingEnabled"> - <summary> - Whether the packet should be sent directly to its destination or allowed to be routed through multiple destinations - first. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.LocalEndPoint"> - <summary> - The local <see cref="T:System.Net.EndPoint"/> for the <see cref="F:NetSharp.Utils.Socket_Options.SocketOptions.managedSocket"/>. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.LocalIPEndPoint"> - <summary> - The local <see cref="T:System.Net.IPEndPoint"/> for this <see cref="T:System.Net.Sockets.Socket"/> instance. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.RemoteEndPoint"> - <summary> - The remote <see cref="T:System.Net.EndPoint"/> for the <see cref="F:NetSharp.Utils.Socket_Options.SocketOptions.managedSocket"/>. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.RemoteIPEndPoint"> - <summary> - The remote <see cref="T:System.Net.IPEndPoint"/> that this <see cref="T:System.Net.Sockets.Socket"/> instance communicates with. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.Ttl"> - <summary> - The 'Time To Live' for this <see cref="T:System.Net.Sockets.Socket"/>. - </summary> - </member> - <member name="P:NetSharp.Utils.Socket_Options.SocketOptions.UseLoopback"> - <summary> - Whether this <see cref="T:System.Net.Sockets.Socket"/> should use a loopback address and bypass hardware. - </summary> - </member> - <member name="T:NetSharp.Utils.Socket_Options.TcpSocketOptions"> - <summary> - Allows for manipulation of TCP socket options. - </summary> - </member> - <member name="M:NetSharp.Utils.Socket_Options.TcpSocketOptions.#ctor(System.Net.Sockets.Socket@)"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.TcpSocketOptions.HopLimit"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.TcpSocketOptions.IsRoutingEnabled"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.TcpSocketOptions.UseLoopback"> - <inheritdoc /> - </member> - <member name="T:NetSharp.Utils.Socket_Options.UdpSocketOptions"> + <member name="T:NetSharp.Utils.TransmissionResult"> <summary> - Allows for manipulation of UDP socket options. + Represents the result of a socket transmission. </summary> </member> - <member name="M:NetSharp.Utils.Socket_Options.UdpSocketOptions.#ctor(System.Net.Sockets.Socket@)"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.UdpSocketOptions.HopLimit"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.UdpSocketOptions.IsRoutingEnabled"> - <inheritdoc /> - </member> - <member name="P:NetSharp.Utils.Socket_Options.UdpSocketOptions.UseLoopback"> - <inheritdoc /> - </member> - <member name="T:NetSharp.Utils.TransmissionResult"> + <member name="M:NetSharp.Utils.TransmissionResult.#ctor(System.Net.Sockets.SocketAsyncEventArgs)"> <summary> - Represents the result of a socket transmission. + Initialises a new instance of the <see cref="T:NetSharp.Utils.TransmissionResult"/> struct. </summary> + <param name="args">The socket arguments associated with the transmission.</param> </member> <member name="F:NetSharp.Utils.TransmissionResult.Buffer"> <summary> @@ -2145,13 +2041,10 @@ The remote endpoint to which the buffer was transmitted. </summary> </member> - <member name="M:NetSharp.Utils.TransmissionResult.#ctor(System.Memory{System.Byte},System.Int32,System.Net.EndPoint)"> + <member name="F:NetSharp.Utils.TransmissionResult.TransmissionArgs"> <summary> - Initialises a new instance of the <see cref="T:NetSharp.Utils.TransmissionResult"/> struct. + Socket arguments and other data associated with the transmission. </summary> - <param name="buffer">The byte buffer that was transmitted.</param> - <param name="count">The number of bytes that were transmitted.</param> - <param name="remoteEndPoint">The remote endpoint to which the buffer was transmitted.</param> </member> </members> </doc> diff --git a/NetSharp/NetSharp/Packets/Builtin/ConnectPacket.cs b/NetSharp/NetSharp/Packets/Builtin/ConnectPacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/ConnectResponsePacket.cs b/NetSharp/NetSharp/Packets/Builtin/ConnectResponsePacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/DataPacket.cs b/NetSharp/NetSharp/Packets/Builtin/DataPacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/DataResponsePacket.cs b/NetSharp/NetSharp/Packets/Builtin/DataResponsePacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/DisconnectPacket.cs b/NetSharp/NetSharp/Packets/Builtin/DisconnectPacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/PingPacket.cs b/NetSharp/NetSharp/Packets/Builtin/PingPacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/PingResponsePacket.cs b/NetSharp/NetSharp/Packets/Builtin/PingResponsePacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/Builtin/SimpleDataPacket.cs b/NetSharp/NetSharp/Packets/Builtin/SimpleDataPacket.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets.Builtin { diff --git a/NetSharp/NetSharp/Packets/NetworkPacket.cs b/NetSharp/NetSharp/Packets/NetworkPacket.cs @@ -24,11 +24,6 @@ namespace NetSharp.Packets } /// <summary> - /// The size of each packet, including its header, footer, and data segment. - /// </summary> - internal const int PacketSize = 1024; - - /// <summary> /// The number of bytes allocated in each packet for user data. /// </summary> public const int DataSegmentSize = PacketSize - HeaderSize - FooterSize; @@ -44,6 +39,11 @@ namespace NetSharp.Packets public const int HeaderSize = NetworkPacketHeader.Size; /// <summary> + /// The size of each packet, including its header, footer, and data segment. + /// </summary> + public const int PacketSize = 1024; + + /// <summary> /// The data held in this packet. /// </summary> public readonly ReadOnlyMemory<byte> DataBuffer; diff --git a/NetSharp/NetSharp/Packets/PacketRegistry.cs b/NetSharp/NetSharp/Packets/PacketRegistry.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using NetSharp.Interfaces; +using NetSharp.Deprecated; using NetSharp.Utils; namespace NetSharp.Packets diff --git a/NetSharp/NetSharp/Packets/PacketTypeIdAttribute.cs b/NetSharp/NetSharp/Packets/PacketTypeIdAttribute.cs @@ -1,5 +1,5 @@ using System; -using NetSharp.Interfaces; +using NetSharp.Deprecated; namespace NetSharp.Packets { diff --git a/NetSharp/NetSharp/Pipelines/PacketPipeline.cs b/NetSharp/NetSharp/Pipelines/PacketPipeline.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Channels; +using System.Threading.Tasks; +using NetSharp.Packets; + +namespace NetSharp.Pipelines +{ + public interface IPacketPipelineStage<TInput, TOutput> + { + ChannelReader<TInput> StageInput { get; } + + ChannelWriter<TOutput> StageOutput { get; } + + TOutput Process(TInput input); + } + + // TODO: Implement a packet pipeline, with multiple transform stages to allow encryption, compression, and various other bytewise manipulation stages. + public readonly struct PacketPipeline<TInput, TIntermediate, TOutput> + { + private readonly IPacketPipelineStage<TIntermediate, TOutput> finalPipelineStage; + private readonly IPacketPipelineStage<TInput, TIntermediate> initialPipelineStage; + private readonly IEnumerable<IPacketPipelineStage<TIntermediate, TIntermediate>> intermediatePipelineStages; + private readonly Channel<TInput> pipelineInput; + private readonly Channel<TOutput> pipelineOutput; + private readonly CancellationToken pipelineShutdownToken; + + internal PacketPipeline(CancellationToken shutdownToken, + IPacketPipelineStage<TInput, TIntermediate> firstStage, + IPacketPipelineStage<TIntermediate, TOutput> lastStage, + IEnumerable<IPacketPipelineStage<TIntermediate, TIntermediate>> intermediateStages) + { + pipelineShutdownToken = shutdownToken; + + UnboundedChannelOptions inputOptions = new UnboundedChannelOptions + { + SingleReader = true, + SingleWriter = true, + }; + pipelineInput = Channel.CreateUnbounded<TInput>(inputOptions); + + UnboundedChannelOptions outputOptions = new UnboundedChannelOptions + { + SingleReader = true, + SingleWriter = true, + }; + pipelineOutput = Channel.CreateUnbounded<TOutput>(outputOptions); + + initialPipelineStage = firstStage; + finalPipelineStage = lastStage; + + intermediatePipelineStages = intermediateStages; + foreach (IPacketPipelineStage<TIntermediate, TIntermediate> stage in intermediatePipelineStages) + { + } + } + + public async Task<TOutput> DequeuePacketAsync() + { + return await pipelineOutput.Reader.ReadAsync(pipelineShutdownToken); + } + + public async Task EnqueuePacketAsync(TInput pipelineInput) + { + await this.pipelineInput.Writer.WriteAsync(pipelineInput, pipelineShutdownToken); + } + } + + public readonly struct PacketPipelineStage<TInput, TOutput> : IPacketPipelineStage<TInput, TOutput> + { + /// <inheritdoc /> + public ChannelReader<TInput> StageInput { get; } + + /// <inheritdoc /> + public ChannelWriter<TOutput> StageOutput { get; } + + /// <inheritdoc /> + public TOutput Process(TInput input) + { + throw new NotImplementedException(); + } + } +} +\ No newline at end of file diff --git a/NetSharp/NetSharp/Sockets/SocketAcceptor.cs b/NetSharp/NetSharp/Sockets/SocketAcceptor.cs @@ -7,6 +7,9 @@ using Microsoft.Extensions.ObjectPool; namespace NetSharp.Sockets { + /// <summary> + /// Helper class providing awaitable wrappers around asynchronous Accept, Connect, and Disconnect operations. + /// </summary> public sealed class SocketAcceptor { private readonly ObjectPool<SocketAsyncEventArgs> acceptAsyncEventArgsPool; @@ -133,17 +136,17 @@ namespace NetSharp.Sockets internal SocketAcceptor(int maxPooledObjects = 10) { - acceptAsyncEventArgsPool = new LeakTrackingObjectPool<SocketAsyncEventArgs>( + acceptAsyncEventArgsPool = new DefaultObjectPool<SocketAsyncEventArgs>(new DefaultPooledObjectPolicy<SocketAsyncEventArgs>(), - maxPooledObjects)); + maxPooledObjects); - connectAsyncEventArgsPool = new LeakTrackingObjectPool<SocketAsyncEventArgs>( + connectAsyncEventArgsPool = new DefaultObjectPool<SocketAsyncEventArgs>(new DefaultPooledObjectPolicy<SocketAsyncEventArgs>(), - maxPooledObjects)); + maxPooledObjects); - disconnectAsyncEventArgsPool = new LeakTrackingObjectPool<SocketAsyncEventArgs>( + disconnectAsyncEventArgsPool = new DefaultObjectPool<SocketAsyncEventArgs>(new DefaultPooledObjectPolicy<SocketAsyncEventArgs>(), - maxPooledObjects)); + maxPooledObjects); for (int i = 0; i < maxPooledObjects; i++) { @@ -161,6 +164,12 @@ namespace NetSharp.Sockets } } + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket accept operation. + /// </summary> + /// <param name="socket">The socket which should be used to accept an incoming connection attempt.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> + /// <returns>The accepted socket.</returns> public Task<Socket> AcceptAsync(Socket socket, CancellationToken cancellationToken = default) { TaskCompletionSource<Socket> tcs = new TaskCompletionSource<Socket>(); @@ -168,6 +177,20 @@ namespace NetSharp.Sockets SocketAsyncEventArgs args = acceptAsyncEventArgsPool.Get(); args.UserToken = new AsyncAcceptToken(tcs, cancellationToken); + // register cleanup action for when the cancellation token is thrown + cancellationToken.Register(() => + { + tcs.SetCanceled(); + + //TODO this is probably a hideous solution. find a better one + args.Completed -= HandleIOCompleted; + args.Dispose(); + + SocketAsyncEventArgs newArgs = new SocketAsyncEventArgs(); + newArgs.Completed += HandleIOCompleted; + acceptAsyncEventArgsPool.Return(newArgs); + }); + // if the accept operation doesn't complete synchronously, return the awaitable task if (socket.AcceptAsync(args)) return tcs.Task; @@ -178,6 +201,12 @@ namespace NetSharp.Sockets return Task.FromResult(result); } + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket connect operation. + /// </summary> + /// <param name="socket">The socket which should asynchronously connect to the remote endpoint.</param> + /// <param name="remoteEndPoint">The remote endpoint to which the socket should connect.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> public Task ConnectAsync(Socket socket, EndPoint remoteEndPoint, CancellationToken cancellationToken = default) { TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); @@ -186,6 +215,20 @@ namespace NetSharp.Sockets args.RemoteEndPoint = remoteEndPoint; args.UserToken = new AsyncConnectToken(tcs, cancellationToken); + // register cleanup action for when the cancellation token is thrown + cancellationToken.Register(() => + { + tcs.SetCanceled(); + + //TODO this is probably a hideous solution. find a better one + args.Completed -= HandleIOCompleted; + args.Dispose(); + + SocketAsyncEventArgs newArgs = new SocketAsyncEventArgs(); + newArgs.Completed += HandleIOCompleted; + connectAsyncEventArgsPool.Return(newArgs); + }); + // if the connect operation doesn't complete synchronously, return the awaitable task if (socket.ConnectAsync(args)) return tcs.Task; @@ -194,6 +237,11 @@ namespace NetSharp.Sockets return Task.CompletedTask; } + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket disconnect operation. + /// </summary> + /// <param name="socket">The socket which should asynchronously disconnect from its remote endpoint.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> public Task DisconnectAsync(Socket socket, CancellationToken cancellationToken = default) { TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); @@ -201,6 +249,20 @@ namespace NetSharp.Sockets SocketAsyncEventArgs args = connectAsyncEventArgsPool.Get(); args.UserToken = new AsyncDisconnectToken(tcs, cancellationToken); + // register cleanup action for when the cancellation token is thrown + cancellationToken.Register(() => + { + tcs.SetCanceled(); + + //TODO this is probably a hideous solution. find a better one + args.Completed -= HandleIOCompleted; + args.Dispose(); + + SocketAsyncEventArgs newArgs = new SocketAsyncEventArgs(); + newArgs.Completed += HandleIOCompleted; + disconnectAsyncEventArgsPool.Return(newArgs); + }); + // if the disconnect operation doesn't complete synchronously, return the awaitable task if (socket.DisconnectAsync(args)) return tcs.Task; diff --git a/NetSharp/NetSharp/Sockets/SocketReader.cs b/NetSharp/NetSharp/Sockets/SocketReader.cs @@ -10,8 +10,12 @@ using NetSharp.Utils; namespace NetSharp.Sockets { + /// <summary> + /// Helper class providing awaitable wrappers around asynchronous Receive and ReceiveFrom operations. + /// </summary> public sealed class SocketReader { + private readonly int PacketBufferLength; private readonly ObjectPool<SocketAsyncEventArgs> receiveAsyncEventArgsPool; private readonly ArrayPool<byte> receiveBufferPool; @@ -108,9 +112,9 @@ namespace NetSharp.Sockets receiveBufferPool = ArrayPool<byte>.Create(packetBufferLength, maxPooledObjects); - receiveAsyncEventArgsPool = new LeakTrackingObjectPool<SocketAsyncEventArgs>( + receiveAsyncEventArgsPool = new DefaultObjectPool<SocketAsyncEventArgs>(new DefaultPooledObjectPolicy<SocketAsyncEventArgs>(), - maxPooledObjects)); + maxPooledObjects); for (int i = 0; i < maxPooledObjects; i++) { @@ -120,10 +124,16 @@ namespace NetSharp.Sockets } } - public int PacketBufferLength { get; } - + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket receive operation. + /// </summary> + /// <param name="socket">The socket which should receive data from the remote connection.</param> + /// <param name="socketFlags">The socket flags associated with the receive operation.</param> + /// <param name="inputBuffer">The memory buffer into which received data will be stored.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> + /// <returns>The result of the receive operation.</returns> public Task<TransmissionResult> ReceiveAsync(Socket socket, SocketFlags socketFlags, - Memory<byte> outputBuffer, CancellationToken cancellationToken = default) + Memory<byte> inputBuffer, CancellationToken cancellationToken = default) { TaskCompletionSource<TransmissionResult> tcs = new TaskCompletionSource<TransmissionResult>(); @@ -133,12 +143,28 @@ namespace NetSharp.Sockets SocketAsyncEventArgs args = receiveAsyncEventArgsPool.Get(); args.SetBuffer(rentedReceiveBufferMemory); args.SocketFlags = socketFlags; - args.UserToken = new AsyncReadToken(rentedReceiveBuffer, outputBuffer, tcs, cancellationToken); + args.UserToken = new AsyncReadToken(rentedReceiveBuffer, inputBuffer, tcs, cancellationToken); + + // register cleanup action for when the cancellation token is thrown + cancellationToken.Register(() => + { + tcs.SetCanceled(); + + receiveBufferPool.Return(rentedReceiveBuffer, true); + + //TODO this is probably a hideous solution. find a better one + args.Completed -= HandleIOCompleted; + args.Dispose(); + + SocketAsyncEventArgs newArgs = new SocketAsyncEventArgs(); + newArgs.Completed += HandleIOCompleted; + receiveAsyncEventArgsPool.Return(newArgs); + }); // if the receive operation doesn't complete synchronously, returns the awaitable task if (socket.ReceiveAsync(args)) return tcs.Task; - args.MemoryBuffer.CopyTo(outputBuffer); + args.MemoryBuffer.CopyTo(inputBuffer); TransmissionResult result = new TransmissionResult(args); @@ -148,8 +174,17 @@ namespace NetSharp.Sockets return Task.FromResult(result); } + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket receive operation. + /// </summary> + /// <param name="socket">The socket which should receive data from the remote endpoint.</param> + /// <param name="remoteEndPoint">The remove endpoint from which data should be received.</param> + /// <param name="socketFlags">The socket flags associated with the receive operation.</param> + /// <param name="inputBuffer">The memory buffer into which received data will be stored.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> + /// <returns>The result of the receive operation.</returns> public Task<TransmissionResult> ReceiveFromAsync(Socket socket, EndPoint remoteEndPoint, SocketFlags socketFlags, - Memory<byte> outputBuffer, CancellationToken cancellationToken = default) + Memory<byte> inputBuffer, CancellationToken cancellationToken = default) { TaskCompletionSource<TransmissionResult> tcs = new TaskCompletionSource<TransmissionResult>(); @@ -160,12 +195,28 @@ namespace NetSharp.Sockets args.SetBuffer(rentedReceiveFromBufferMemory); args.SocketFlags = socketFlags; args.RemoteEndPoint = remoteEndPoint; - args.UserToken = new AsyncReadToken(rentedReceiveFromBuffer, outputBuffer, tcs, cancellationToken); + args.UserToken = new AsyncReadToken(rentedReceiveFromBuffer, inputBuffer, tcs, cancellationToken); + + // register cleanup action for when the cancellation token is thrown + cancellationToken.Register(() => + { + tcs.SetCanceled(); + + receiveBufferPool.Return(rentedReceiveFromBuffer, true); + + //TODO this is probably a hideous solution. find a better one + args.Completed -= HandleIOCompleted; + args.Dispose(); + + SocketAsyncEventArgs newArgs = new SocketAsyncEventArgs(); + newArgs.Completed += HandleIOCompleted; + receiveAsyncEventArgsPool.Return(newArgs); + }); // if the receive operation doesn't complete synchronously, returns the awaitable task if (socket.ReceiveFromAsync(args)) return tcs.Task; - args.MemoryBuffer.CopyTo(outputBuffer); + args.MemoryBuffer.CopyTo(inputBuffer); TransmissionResult result = new TransmissionResult(args); diff --git a/NetSharp/NetSharp/Sockets/SocketWriter.cs b/NetSharp/NetSharp/Sockets/SocketWriter.cs @@ -9,8 +9,12 @@ using NetSharp.Packets; namespace NetSharp.Sockets { + /// <summary> + /// Helper class providing awaitable wrappers around asynchronous Send and SendTo operations. + /// </summary> public sealed class SocketWriter { + private readonly int PacketBufferLength; private readonly ObjectPool<SocketAsyncEventArgs> sendAsyncEventArgsPool; private readonly ArrayPool<byte> sendBufferPool; @@ -40,7 +44,6 @@ namespace NetSharp.Sockets sendBufferPool.Return(asyncSendToken.RentedBuffer, true); sendAsyncEventArgsPool.Return(args); - break; case SocketAsyncOperation.SendTo: @@ -65,7 +68,6 @@ namespace NetSharp.Sockets sendBufferPool.Return(asyncSendToToken.RentedBuffer, true); sendAsyncEventArgsPool.Return(args); - break; default: @@ -97,9 +99,9 @@ namespace NetSharp.Sockets sendBufferPool = ArrayPool<byte>.Create(packetBufferLength, maxPooledObjects); - sendAsyncEventArgsPool = new LeakTrackingObjectPool<SocketAsyncEventArgs>( + sendAsyncEventArgsPool = new DefaultObjectPool<SocketAsyncEventArgs>(new DefaultPooledObjectPolicy<SocketAsyncEventArgs>(), - maxPooledObjects)); + maxPooledObjects); for (int i = 0; i < maxPooledObjects; i++) { @@ -109,8 +111,14 @@ namespace NetSharp.Sockets } } - public int PacketBufferLength { get; } - + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket send operation. + /// </summary> + /// <param name="socket">The socket which should send the data to its remote connection.</param> + /// <param name="socketFlags">The socket flags associated with the send operation.</param> + /// <param name="outputBuffer">The data buffer which should be sent.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> + /// <returns>The number of bytes of data which were written to the remote connection.</returns> public Task<int> SendAsync(Socket socket, SocketFlags socketFlags, Memory<byte> outputBuffer, CancellationToken cancellationToken = default) { @@ -137,6 +145,15 @@ namespace NetSharp.Sockets return Task.FromResult(result); } + /// <summary> + /// Provides an awaitable wrapper around an asynchronous socket send operation. + /// </summary> + /// <param name="socket">The socket which should send the data to the remote endpoint.</param> + /// <param name="remoteEndPoint">The remote endpoint to which data should be written.</param> + /// <param name="socketFlags">The socket flags associated with the send operation.</param> + /// <param name="outputBuffer">The data buffer which should be sent.</param> + /// <param name="cancellationToken">The cancellation token to observe for the operation.</param> + /// <returns>The number of bytes of data which were written to the remote endpoint.</returns> public Task<int> SendToAsync(Socket socket, EndPoint remoteEndPoint, SocketFlags socketFlags, Memory<byte> outputBuffer, CancellationToken cancellationToken = default) { @@ -153,6 +170,22 @@ namespace NetSharp.Sockets args.RemoteEndPoint = remoteEndPoint; args.UserToken = new AsyncWriteToken(rentedSendToBuffer, tcs, cancellationToken); + // register cleanup action for when the cancellation token is thrown + cancellationToken.Register(() => + { + tcs.SetCanceled(); + + sendBufferPool.Return(rentedSendToBuffer, true); + + //TODO this is probably a hideous solution. find a better one + args.Completed -= HandleIOCompleted; + args.Dispose(); + + SocketAsyncEventArgs newArgs = new SocketAsyncEventArgs(); + newArgs.Completed += HandleIOCompleted; + sendAsyncEventArgsPool.Return(newArgs); + }); + // if the send operation doesn't complete synchronously, return the awaitable task if (socket.SendToAsync(args)) return tcs.Task; diff --git a/NetSharp/NetSharp/Utils/NetworkOperationsManager.cs b/NetSharp/NetSharp/Utils/NetworkOperationsManager.cs @@ -1,330 +0,0 @@ -using System; -using System.Buffers; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.ObjectPool; -using NetSharp.Packets; - -namespace NetSharp.Utils -{ - /// <summary> - /// Helper class for asynchronously performing common network operations in an efficient manner, for both the UDP and TCP protocols. - /// </summary> - public sealed class NetworkOperationsManager - { - private readonly ArrayPool<byte> receiveBufferPool; - private readonly ArrayPool<byte> receiveFromBufferPool; - private readonly ArrayPool<byte> sendBufferPool; - private readonly ArrayPool<byte> sendToBufferPool; - private readonly ObjectPool<SocketAsyncEventArgs> socketAsyncEventArgsPool; - - private void HandleIOCompleted(object? sender, SocketAsyncEventArgs eventArgs) - { - bool closed = false; - - switch (eventArgs.LastOperation) - { - case SocketAsyncOperation.Send: - AsyncWriteToken asyncSendToken = (AsyncWriteToken)eventArgs.UserToken; - - if (asyncSendToken.CancellationToken.IsCancellationRequested) - { - asyncSendToken.CompletionSource.SetCanceled(); - } - else - { - if (eventArgs.SocketError != SocketError.Success) - { - asyncSendToken.CompletionSource.SetException( - new SocketException((int)eventArgs.SocketError)); - } - else - { - asyncSendToken.CompletionSource.SetResult(eventArgs.BytesTransferred); - } - } - - sendBufferPool.Return(asyncSendToken.RentedBuffer, true); - socketAsyncEventArgsPool.Return(eventArgs); - - break; - - case SocketAsyncOperation.SendTo: - AsyncWriteToken asyncSendToToken = (AsyncWriteToken)eventArgs.UserToken; - - if (asyncSendToToken.CancellationToken.IsCancellationRequested) - { - asyncSendToToken.CompletionSource.SetCanceled(); - } - else - { - if (eventArgs.SocketError != SocketError.Success) - { - asyncSendToToken.CompletionSource.SetException( - new SocketException((int)eventArgs.SocketError)); - } - else - { - asyncSendToToken.CompletionSource.SetResult(eventArgs.BytesTransferred); - } - } - - sendToBufferPool.Return(asyncSendToToken.RentedBuffer, true); - socketAsyncEventArgsPool.Return(eventArgs); - - break; - - case SocketAsyncOperation.Receive: - AsyncReadToken asyncReceiveToken = (AsyncReadToken)eventArgs.UserToken; - - if (asyncReceiveToken.CancellationToken.IsCancellationRequested) - { - asyncReceiveToken.CompletionSource.SetCanceled(); - } - else - { - if (eventArgs.SocketError != SocketError.Success) - { - asyncReceiveToken.CompletionSource.SetException( - new SocketException((int)eventArgs.SocketError)); - } - else - { - eventArgs.MemoryBuffer.CopyTo(asyncReceiveToken.UserBuffer); - - TransmissionResult result = new TransmissionResult(eventArgs); - - asyncReceiveToken.CompletionSource.SetResult(result); - } - } - - receiveBufferPool.Return(asyncReceiveToken.RentedBuffer, true); - - break; - - case SocketAsyncOperation.ReceiveFrom: - AsyncReadToken asyncReceiveFromToken = (AsyncReadToken)eventArgs.UserToken; - - if (asyncReceiveFromToken.CancellationToken.IsCancellationRequested) - { - asyncReceiveFromToken.CompletionSource.SetCanceled(); - } - else - { - if (eventArgs.SocketError != SocketError.Success) - { - asyncReceiveFromToken.CompletionSource.SetException( - new SocketException((int)eventArgs.SocketError)); - } - else - { - eventArgs.MemoryBuffer.CopyTo(asyncReceiveFromToken.UserBuffer); - TransmissionResult result = new TransmissionResult(eventArgs); - - asyncReceiveFromToken.CompletionSource.SetResult(result); - } - } - - receiveFromBufferPool.Return(asyncReceiveFromToken.RentedBuffer, true); - - break; - - case SocketAsyncOperation.Disconnect: - closed = true; - break; - - case SocketAsyncOperation.Accept: - case SocketAsyncOperation.Connect: - case SocketAsyncOperation.ReceiveMessageFrom: - case SocketAsyncOperation.SendPackets: - case SocketAsyncOperation.None: - throw new NotImplementedException(); - - default: - throw new ArgumentOutOfRangeException(); - } - - if (closed) - { - // handle the client closing the connection on tcp servers at some point - } - } - - private readonly struct AsyncReadToken - { - public readonly CancellationToken CancellationToken; - public readonly TaskCompletionSource<TransmissionResult> CompletionSource; - public readonly byte[] RentedBuffer; - public readonly Memory<byte> UserBuffer; - - public AsyncReadToken(byte[] rentedBuffer, Memory<byte> userBuffer, TaskCompletionSource<TransmissionResult> tcs, - CancellationToken cancellationToken = default) - { - RentedBuffer = rentedBuffer; - UserBuffer = userBuffer; - - CompletionSource = tcs; - CancellationToken = cancellationToken; - } - } - - private readonly struct AsyncWriteToken - { - public readonly CancellationToken CancellationToken; - public readonly TaskCompletionSource<int> CompletionSource; - public readonly byte[] RentedBuffer; - - public AsyncWriteToken(byte[] rentedBuffer, TaskCompletionSource<int> tcs, - CancellationToken cancellationToken = default) - { - RentedBuffer = rentedBuffer; - - CompletionSource = tcs; - CancellationToken = cancellationToken; - } - } - - public const int DefaultMaximumPooledObjects = 10; - - public NetworkOperationsManager(int bufferSize = NetworkPacket.PacketSize, - int maxPooledObjectCount = DefaultMaximumPooledObjects, bool preallocateBuffers = false) - { - MaxPooledObjects = maxPooledObjectCount; - BufferSize = bufferSize; - - sendBufferPool = ArrayPool<byte>.Create(bufferSize, maxPooledObjectCount); - receiveBufferPool = ArrayPool<byte>.Create(bufferSize, maxPooledObjectCount); - - sendToBufferPool = ArrayPool<byte>.Create(bufferSize, maxPooledObjectCount); - receiveFromBufferPool = ArrayPool<byte>.Create(bufferSize, maxPooledObjectCount); - - socketAsyncEventArgsPool = new LeakTrackingObjectPool<SocketAsyncEventArgs>( - new DefaultObjectPool<SocketAsyncEventArgs>(new DefaultPooledObjectPolicy<SocketAsyncEventArgs>(), - maxPooledObjectCount)); - - for (int i = 0; i < MaxPooledObjects; i++) - { - SocketAsyncEventArgs args = new SocketAsyncEventArgs(); - args.Completed += HandleIOCompleted; - - socketAsyncEventArgsPool.Return(args); - } - - if (preallocateBuffers) - { - // TODO: Allocate and return array pool buffers - } - } - - public int BufferSize { get; } - - public int MaxPooledObjects { get; } - - public Task<TransmissionResult> ReceiveAsync(Socket socket, SocketFlags socketFlags, Memory<byte> outputBuffer, - CancellationToken cancellationToken = default) - { - TaskCompletionSource<TransmissionResult> tcs = new TaskCompletionSource<TransmissionResult>(); - - byte[] rentedReceiveBuffer = receiveBufferPool.Rent(BufferSize); - Memory<byte> rentedReceiveBufferMemory = new Memory<byte>(rentedReceiveBuffer); - - SocketAsyncEventArgs args = socketAsyncEventArgsPool.Get(); - - args.SetBuffer(rentedReceiveBufferMemory); - args.SocketFlags = socketFlags; - args.UserToken = new AsyncReadToken(rentedReceiveBuffer, outputBuffer, tcs, cancellationToken); - - // if the receive operation doesn't complete synchronously, returns the awaitable task - if (socket.ReceiveAsync(args)) return tcs.Task; - - args.MemoryBuffer.CopyTo(outputBuffer); - - TransmissionResult result = new TransmissionResult(args); - - receiveBufferPool.Return(rentedReceiveBuffer, true); - - return Task.FromResult(result); - } - - public Task<TransmissionResult> ReceiveFromAsync(Socket socket, EndPoint remoteEndPoint, SocketFlags socketFlags, - Memory<byte> outputBuffer, CancellationToken cancellationToken = default) - { - TaskCompletionSource<TransmissionResult> tcs = new TaskCompletionSource<TransmissionResult>(); - - byte[] rentedReceiveFromBuffer = receiveFromBufferPool.Rent(BufferSize); - Memory<byte> rentedReceiveFromBufferMemory = new Memory<byte>(rentedReceiveFromBuffer); - - SocketAsyncEventArgs args = socketAsyncEventArgsPool.Get(); - - args.SetBuffer(rentedReceiveFromBufferMemory); - args.SocketFlags = socketFlags; - args.RemoteEndPoint = remoteEndPoint; - args.UserToken = new AsyncReadToken(rentedReceiveFromBuffer, outputBuffer, tcs, cancellationToken); - - // if the receive operation doesn't complete synchronously, returns the awaitable task - if (socket.ReceiveFromAsync(args)) return tcs.Task; - - args.MemoryBuffer.CopyTo(outputBuffer); - - TransmissionResult result = new TransmissionResult(args); - - receiveFromBufferPool.Return(rentedReceiveFromBuffer, true); - - return Task.FromResult(result); - } - - public Task<int> SendAsync(Socket socket, SocketAsyncEventArgs receiveArgs, SocketFlags socketFlags, - Memory<byte> inputBuffer, CancellationToken cancellationToken = default) - { - TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(); - - byte[] rentedSendBuffer = sendBufferPool.Rent(BufferSize); - Memory<byte> rentedSendBufferMemory = new Memory<byte>(rentedSendBuffer); - - inputBuffer.CopyTo(rentedSendBufferMemory); - - SocketAsyncEventArgs args = receiveArgs; - args.SetBuffer(rentedSendBufferMemory); - args.SocketFlags = socketFlags; - args.UserToken = new AsyncWriteToken(rentedSendBuffer, tcs, cancellationToken); - - // if the send operation doesn't complete synchronously, return the awaitable task - if (socket.SendAsync(args)) return tcs.Task; - - int result = args.BytesTransferred; - - sendBufferPool.Return(rentedSendBuffer, true); - socketAsyncEventArgsPool.Return(args); - - return Task.FromResult(result); - } - - public Task<int> SendToAsync(Socket socket, SocketAsyncEventArgs receiveFromArgs, SocketFlags socketFlags, - Memory<byte> inputBuffer, CancellationToken cancellationToken = default) - { - TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(); - - byte[] rentedSendToBuffer = sendToBufferPool.Rent(BufferSize); - Memory<byte> rentedSendToBufferMemory = new Memory<byte>(rentedSendToBuffer); - - inputBuffer.CopyTo(rentedSendToBufferMemory); - - SocketAsyncEventArgs args = receiveFromArgs; - args.SetBuffer(rentedSendToBufferMemory); - args.SocketFlags = socketFlags; - args.UserToken = new AsyncWriteToken(rentedSendToBuffer, tcs, cancellationToken); - - // if the send operation doesn't complete synchronously, return the awaitable task - if (socket.SendToAsync(args)) return tcs.Task; - - int result = args.BytesTransferred; - - sendToBufferPool.Return(rentedSendToBuffer, true); - socketAsyncEventArgsPool.Return(args); - - return Task.FromResult(result); - } - } -} -\ No newline at end of file diff --git a/NetSharp/NetSharp/Utils/RingBuffer.cs b/NetSharp/NetSharp/Utils/RingBuffer.cs @@ -0,0 +1,50 @@ +using System.Threading; + +namespace NetSharp.Utils +{ + public class RingBuffer<T> + { + private readonly T[] buffer; + + private int currentIndex; + + public RingBuffer(int capacity) + { + buffer = new T[capacity]; + + Capacity = capacity; + Count = 0; + } + + public int Capacity { get; } + + public int Count { get; } + + public T Pop() + { + T removedItem = buffer[currentIndex--]; + + currentIndex = currentIndex < 0 ? currentIndex + Capacity : currentIndex; + + return removedItem; + } + + public bool Push(T newItem, out T removedItem) + { + bool overwroteItem = false; + removedItem = default; + + if (buffer[currentIndex] != null) + { + removedItem = buffer[currentIndex]; + overwroteItem = true; + } + + buffer[currentIndex] = newItem; + + currentIndex = (currentIndex + 1) % Capacity; + + return overwroteItem; + } + } +} +\ No newline at end of file diff --git a/NetSharp/NetSharp/Utils/TransmissionResult.cs b/NetSharp/NetSharp/Utils/TransmissionResult.cs @@ -10,6 +10,18 @@ namespace NetSharp.Utils public readonly struct TransmissionResult { /// <summary> + /// Initialises a new instance of the <see cref="TransmissionResult"/> struct. + /// </summary> + /// <param name="args">The socket arguments associated with the transmission.</param> + internal TransmissionResult(SocketAsyncEventArgs args) + { + TransmissionArgs = args; + Buffer = args.MemoryBuffer; + Count = args.BytesTransferred; + RemoteEndPoint = args.RemoteEndPoint; + } + + /// <summary> /// The byte buffer that was transmitted across the network. /// </summary> public readonly Memory<byte> Buffer; @@ -28,17 +40,5 @@ namespace NetSharp.Utils /// Socket arguments and other data associated with the transmission. /// </summary> public readonly SocketAsyncEventArgs TransmissionArgs; - - /// <summary> - /// Initialises a new instance of the <see cref="TransmissionResult"/> struct. - /// </summary> - /// <param name="args">The socket arguments associated with the transmission.</param> - public TransmissionResult(SocketAsyncEventArgs args) - { - TransmissionArgs = args; - Buffer = args.MemoryBuffer; - Count = args.BytesTransferred; - RemoteEndPoint = args.RemoteEndPoint; - } } } \ No newline at end of file diff --git a/NetSharp/NetSharpExamples/Program.cs b/NetSharp/NetSharpExamples/Program.cs @@ -2,14 +2,12 @@ using System.Diagnostics; using System.IO; using System.Net; +using System.Net.Sockets; using System.Text; -using System.Threading; using System.Threading.Tasks; using NetSharp; -using NetSharp.Clients; -using NetSharp.Extensions; -using NetSharp.Logging; -using NetSharp.Servers; +using NetSharp.Packets; +using NetSharp.Utils; namespace NetSharpExamples { @@ -30,27 +28,13 @@ namespace NetSharpExamples Console.WriteLine("Test server (y/n): "); if (Console.ReadLine()?.ToLower().Equals("y") ?? false) { - try - { - await TestServer(); - } - catch (Exception ex) - { - Console.WriteLine($"Exception: {ex}"); - } + await TestServer(); Console.ReadLine(); } else { - try - { - await TestClient(); - } - catch (Exception ex) - { - Console.WriteLine($"Exception: {ex}"); - } + await TestClient(); Console.ReadLine(); } @@ -60,82 +44,46 @@ namespace NetSharpExamples { TimeSpan socketTimeout = TimeSpan.FromSeconds(newtorkTimeout); - const int clientCount = 1; + const int clientCount = 10; const int sentPacketCount = 1_000_000; - static Client ClientFactory() + EndPoint serverEndPoint = new IPEndPoint(serverAddress, serverPort); + + static Connection ClientFactory() { - return new UdpClient(); + return ConnectionFactory.InitUdp(new IPEndPoint(IPAddress.Loopback, 0)); } + Console.WriteLine($"Testing client connections..."); + for (int i = 0; i < clientCount; i++) { - await Task.Factory.StartNew(async () => + await Task.Factory.StartNew(async clientId => { - using Client client = ClientFactory(); + Console.WriteLine($"Starting client {clientId}"); - client.ChangeLoggingStream(Console.OpenStandardOutput(), LogLevel.Warn); + using Connection client = ClientFactory(); + TimeSpan timeout = TimeSpan.FromMilliseconds(1); - if (await client.TryBindAsync(null, null, socketTimeout)) - { - Console.WriteLine($"Socket bound successfully: {client.SocketOptions.LocalIPEndPoint}"); - - if (await client.TryConnectAsync(serverAddress, serverPort, socketTimeout)) - { - Console.WriteLine( - $"Socket connected successfully: {client.SocketOptions.RemoteIPEndPoint}, sending messages to server..."); - - //var message = new SimpleRequestPacket { Message = "Hello World" }; - byte[] message = Encoding.UTF8.GetBytes("Hello World!"); - bool failedToSend = false; - - Stopwatch messageStopwatch = Stopwatch.StartNew(); - - for (int j = 0; j < sentPacketCount; j++) - { - if (!await client.SendBytesAsync(message, socketTimeout)) - { - failedToSend = true; - break; - } - - //Console.WriteLine($"[{j}] Sent message to server."); - - //byte[] response = await client.SendBytesWithResponseAsync(message, socketTimeout); - //Console.WriteLine($"[{j}] Received response: {Encoding.UTF8.GetString(response)}"); - - //await Task.Delay(new Random(DateTime.Now.Millisecond).Next(200, 500)); - } - - messageStopwatch.Stop(); - - if (!failedToSend) - { - Console.WriteLine( - $"Sending {sentPacketCount} packets of {message.Length} bytes long took {messageStopwatch.Elapsed}"); - - double bandwidth = message.Length * sentPacketCount / (messageStopwatch.ElapsedMilliseconds / 1000.0); - - Console.WriteLine($"Approximate bandwidth for single connection is {bandwidth} Bytes per second"); - } - else - { - Console.WriteLine("Could not successfully send all packets to server."); - } - - client.Disconnect(); - Console.WriteLine($"Sent disconnect packet to server."); - } - else - { - Console.WriteLine("Socket could not connect"); - } - } - else + byte[] message = Encoding.UTF8.GetBytes("Hello World!"); + Memory<byte> messageBuffer = new Memory<byte>(message); + + byte[] response = new byte[NetworkPacket.PacketSize]; + Memory<byte> responseBuffer = new Memory<byte>(response); + + for (int j = 0; j < sentPacketCount; j++) { - Console.WriteLine("Socket could not be bound"); + int sentBytes = await client.SendToAsync(serverEndPoint, messageBuffer, SocketFlags.None, timeout); + + Console.WriteLine($"[Client {clientId}] Sent {sentBytes} bytes to {serverEndPoint}"); + + TransmissionResult result = await client.ReceiveFromAsync(serverEndPoint, responseBuffer, SocketFlags.None, timeout); + + Console.WriteLine($"[Client {clientId}] Received {result.Count} bytes from {result.RemoteEndPoint}"); + + //await Task.Delay(10); } - }, TaskCreationOptions.LongRunning); + }, i, TaskCreationOptions.LongRunning); } Console.ReadLine(); @@ -147,17 +95,34 @@ namespace NetSharpExamples File.Delete(serverLogFile); await using Stream serverOutputStream = File.OpenWrite(serverLogFile); - using Server server = new UdpServer(); - server.ChangeLoggingStream(Console.OpenStandardOutput(), LogLevel.Warn); + EndPoint serverEndPoint = new IPEndPoint(serverAddress, serverPort); + + using Connection server = ConnectionFactory.InitUdp(serverEndPoint); + //server.SetLoggingStream(Console.OpenStandardOutput(), LogLevel.Info); //server.ChangeLoggingStream(serverOutputStream, LogLevel.Error); Console.WriteLine("Starting server..."); - await server.RunAsync(serverAddress, serverPort); + + EndPoint nullEndPoint = new IPEndPoint(IPAddress.Any, 0); + + byte[] request = new byte[NetworkPacket.PacketSize]; + Memory<byte> requestBuffer = new Memory<byte>(request); + + while (true) + { + TransmissionResult result = + await server.ReceiveFromAsync(nullEndPoint, requestBuffer, SocketFlags.None); + + Console.WriteLine($"[Server] Received {result.Count} bytes from {result.RemoteEndPoint}"); + + int sentBytes = await server.SendToAsync(result.RemoteEndPoint, requestBuffer, SocketFlags.None); + + Console.WriteLine($"[Server] Sent {sentBytes} bytes tp {result.RemoteEndPoint}"); + } + Console.WriteLine("Server stopped"); Console.ReadLine(); - - serverOutputStream.Close(); } } } \ No newline at end of file