DeliveryConnection.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Runtime.CompilerServices;
  4. using Sers.CL.Socket.Iocp.Base;
  5. using Vit.Core.Module.Log;
  6. using Vit.Extensions;
  7. namespace Sers.CL.Socket.Iocp.Mode.Simple
  8. {
  9. public class DeliveryConnection : DeliveryConnection_Base
  10. {
  11. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  12. public override void SendFrameAsync(Vit.Core.Util.Pipelines.ByteData data)
  13. {
  14. if (data == null || socket == null) return;
  15. try
  16. {
  17. Int32 len = data.Count();
  18. data.Insert(0, len.Int32ToArraySegmentByte());
  19. var bytes = data.ToBytes();
  20. _securityManager?.Encryption(new ArraySegment<byte>(bytes, 4, bytes.Length - 4));
  21. socket.SendAsync(bytes.BytesToArraySegmentByte(), SocketFlags.None);
  22. //socket.SendAsync(data, SocketFlags.None);
  23. }
  24. catch (Exception ex)
  25. {
  26. Logger.Error(ex);
  27. Close();
  28. }
  29. }
  30. }
  31. }