// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Network; /// /// Extension methods for . /// public static class ConnectionExtensions { /// /// Sends a message asynchronously. /// /// The connection. /// The packet builder which writes to the and returns the length of the packet in bytes. public static async ValueTask SendAsync(this IConnection connection, Func packetBuilder) { if (!connection.Connected) { return; } using var l = await connection.OutputLock.LockAsync().ConfigureAwait(false); var length = packetBuilder(); connection.Output.Advance(length); await connection.Output.FlushAsync().ConfigureAwait(false); } }