public void SendOne(int connectionId, ArraySegment <byte> source) { ArrayBuffer buffer = bufferPool.Take(source.Count); buffer.CopyFrom(source); server.Send(connectionId, buffer); }
public override void Send(ArraySegment <byte> segment) { ArrayBuffer buffer = bufferPool.Take(segment.Count); buffer.CopyFrom(segment); conn.sendQueue.Enqueue(buffer); conn.sendPending.Set(); }
void onMessage(IntPtr bufferPtr, int count) { try { ArrayBuffer buffer = bufferPool.Take(count); buffer.CopyFrom(bufferPtr, count); receiveQueue.Enqueue(new Message(buffer)); } catch (Exception e) { Log.Error($"onData {e.GetType()}: {e.Message}\n{e.StackTrace}"); receiveQueue.Enqueue(new Message(e)); } }
public void SendAll(List <int> connectionIds, ArraySegment <byte> source) { ArrayBuffer buffer = bufferPool.Take(source.Count); buffer.CopyFrom(source); buffer.SetReleasesRequired(connectionIds.Count); // make copy of array before for each, data sent to each client is the same foreach (int id in connectionIds) { server.Send(id, buffer); } }
static ArrayBuffer CopyMessageToBuffer(BufferPool bufferPool, bool expectMask, byte[] buffer, int msgOffset, int payloadLength) { ArrayBuffer arrayBuffer = bufferPool.Take(payloadLength); if (expectMask) { int maskOffset = msgOffset - Constants.MaskSize; // write the result of toggle directly into arrayBuffer to avoid 2nd copy call MessageProcessor.ToggleMask(buffer, msgOffset, arrayBuffer, payloadLength, buffer, maskOffset); } else { arrayBuffer.CopyFrom(buffer, msgOffset, payloadLength); } return(arrayBuffer); }
static void HandleArrayMessage(Config config, byte[] buffer, int msgOffset, int payloadLength) { (Connection conn, int _, bool expectMask, ConcurrentQueue <Message> queue, BufferPool bufferPool) = config; ArrayBuffer arrayBuffer = bufferPool.Take(payloadLength); if (expectMask) { int maskOffset = msgOffset - Constants.MaskSize; // write the result of toggle directly into arrayBuffer to avoid 2nd copy call MessageProcessor.ToggleMask(buffer, msgOffset, arrayBuffer, payloadLength, buffer, maskOffset); } else { arrayBuffer.CopyFrom(buffer, msgOffset, payloadLength); } // dump after mask off Log.DumpBuffer($"Message", arrayBuffer); queue.Enqueue(new Message(conn.connId, arrayBuffer)); }