Skip to content

Commit

Permalink
refactor: SOCKS5 udp data use ReadOnlyMemory instead
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Aug 13, 2021
1 parent a1fdaf1 commit 8f59eab
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Socks5/Models/Socks5UdpReceivePacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public struct Socks5UdpReceivePacket
public IPAddress? Address;
public string? Domain;
public ushort Port;
public Memory<byte> Data;
public ReadOnlyMemory<byte> Data;
}
}
3 changes: 1 addition & 2 deletions Socks5/Utils/Unpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;

namespace Socks5.Utils
Expand Down Expand Up @@ -145,7 +144,7 @@ public static Socks5UdpReceivePacket Udp(ReadOnlyMemory<byte> buffer)
offset += DestinationAddress(res.Type, span[offset..], out res.Address, out res.Domain);

res.Port = BinaryPrimitives.ReadUInt16BigEndian(span[offset..]);
res.Data = MemoryMarshal.AsMemory(buffer[(offset + 2)..]);
res.Data = buffer[(offset + 2)..];

return res;
}
Expand Down

0 comments on commit 8f59eab

Please sign in to comment.