Skip to content

Add Memory support to SendPacketElements #45267

@geoffkizer

Description

@geoffkizer

Proposed API

namespace System.Net.Sockets
{
    public class SendPacketsElement
    {
        // Existing APIs:
        public SendPacketsElement(byte[] buffer);
        public SendPacketsElement(byte[] buffer, int offset, int count);
        public SendPacketsElement(byte[] buffer, int offset, int count, bool endOfPacket);

        public byte[]? Buffer { get; }
        public int Offset { get; }
        public int Count { get; }

        // Proposed APIs:
        public SendPacketsElement(ReadOnlyMemory<byte> buffer);
        public SendPacketsElement(ReadOnlyMemory<byte> buffer, bool endOfPacket);

        public ReadOnlyMemory<byte>? MemoryBuffer { get; }
    }
}

This is modeled on how we added Memory support to SocketAsyncEventArgs.

If you use a new Memory constructor overload, then:

  • MemoryBuffer will return the ReadOnlyMemory that you passed to the constructor
  • Buffer will return null
  • Offset will return 0
  • Count will return MemoryBuffer.Length

If you use an old byte[] constructor overload, then:

  • MemoryBuffer will return a ReadOnlyMemory constructed from the byte[], offset, and count you passed to the constructor.
  • Buffer, Offset, and Count will return the values you passed to the constructor (as today)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions