Sending byte array with length (and possible offset)

Open
#384 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
networking

Research direction

Start by locating the Send and Broadcast methods that currently accept byte[] and inspect their related call paths. Determine how a length, and possibly an offset, should be represented consistently across those methods. Done means callers can send the used portion of an existing buffer without copying it, with behavior covered by the repository’s relevant existing tests.

Written by the indexing model from the issue text.

Description

The Send & Broadcast methods support a byte[] argument. Would it be possible to also provide an override that takes a length argument. At the moment I receive a large amount of data into a byte array buffer, and then have to copy it into a know sized array for the Send/Broadcast methods. This is expensive to perform frequently e.g.

int read = ips.Read(data, 0, 64 * 1024);
Console.WriteLine($"Processing {read} bytes");
if (read > 0)
{
byte[] broadcast = new byte[read];
Buffer.BlockCopy(data, 0, broadcast, 0, read); // <--- Have to block copy my array
socketServer.WebSocketServices["/1"].Sessions.Broadcast(broadcast);
}

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sta/websocket-sharp

All issues in sta/websocket-sharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.