Exemple #1
0
        private void ReassembleChunksAndDispatch(IReadOnlyList <MultiPartChunkDto> chunks)
        {
//         Console.WriteLine(chunks.First().MultiPartMessageId.ToString("n").Substring(0, 6) + " Got to reassemble!");
            RemoveAssemblerFromCache(chunks.First().MultiPartMessageId);

            var payloadLength = chunks.Sum(c => c.BodyLength);
            var payloadBytes  = new byte[payloadLength];

            for (int i = 0, offset = 0; i < chunks.Count; i++)
            {
                var chunk = chunks[i];
                Buffer.BlockCopy(chunk.Body, 0, payloadBytes, offset, chunk.BodyLength);
                offset += chunk.BodyLength;
            }

            var e = inboundDataEventPool.TakeObject();

            e.Data       = payloadBytes;
            e.DataOffset = 0;
            e.DataLength = payloadLength;

//         Console.WriteLine(chunks.First().MultiPartMessageId.ToString("n").Substring(0, 6) + " Dispatching to HIDE!");
            dispatcher.HandleInboundDataEvent(
                e,
                _ => {
                e.Data = null;
                inboundDataEventPool.ReturnObject(e);
            });
        }
        private void HandleReceiveCompleted(object sender, SocketAsyncEventArgs e)
        {
            BeginReceive(e.AcceptSocket, (IPEndPoint)e.UserToken);

            var sw = new Stopwatch();

            sw.Start();

            var inboundSomethingEvent = inboundSomethingEventPool.TakeObject();

            inboundSomethingEvent.UdpClient      = this;
            inboundSomethingEvent.SocketArgs     = e;
            inboundSomethingEvent.DataBufferPool = sendReceiveBufferPool;
            inboundSomethingEvent.Data           = e.Buffer;
            inboundSomethingEvent.DataOffset     = 0;
            inboundSomethingEvent.DataLength     = e.BytesTransferred;
            inboundSomethingEvent.RemoteInfo     = new UdpClientRemoteInfo {
                IPEndpoint = (IPEndPoint)e.RemoteEndPoint,
                Socket     = e.AcceptSocket
            };
            inboundSomethingEvent.StopWatch = sw;

            udpDispatcher.HandleInboundDataEvent(inboundSomethingEvent, HandleInboundDataEventCompletionCallback);
        }