Пример #1
0
		public static void ProcessReceive( BlockingCollection<byte[]> inboundQueue, ConcurrentQueue<InProcPacket> pendingPackets, MessageContext context, CancellationToken cancellationToken )
		{
			InProcPacket packet;
			if ( !pendingPackets.TryPeek( out packet ) )
			{
				byte[] data = inboundQueue.Take( cancellationToken );
				packet = new InProcPacket( data );
				pendingPackets.Enqueue( packet );
			}

			int copying = Math.Min( context.SocketContext.Count, packet.Data.Count );
			Buffer.BlockCopy( packet.Data.Array, packet.Data.Offset, context.Buffer, context.Offset, copying );
			context.SetBytesTransferred( copying );

			if ( copying == packet.Data.Count )
			{
				InProcPacket dummy;
				pendingPackets.TryDequeue( out dummy );
			}
			else
			{
				var oldData = packet.Data;
				packet.Data = new ArraySegment<byte>( oldData.Array, oldData.Offset + copying, oldData.Count - copying );
			}
		}
Пример #2
0
        public static void ProcessReceive(BlockingCollection <byte[]> inboundQueue, ConcurrentQueue <InProcPacket> pendingPackets, MessageContext context, CancellationToken cancellationToken)
        {
            InProcPacket packet;

            if (!pendingPackets.TryPeek(out packet))
            {
                byte[] data = inboundQueue.Take(cancellationToken);
                packet = new InProcPacket(data);
                pendingPackets.Enqueue(packet);
            }

            int copying = Math.Min(context.SocketContext.Count, packet.Data.Count);

            Buffer.BlockCopy(packet.Data.Array, packet.Data.Offset, context.Buffer, context.Offset, copying);
            context.SetBytesTransferred(copying);

            if (copying == packet.Data.Count)
            {
                InProcPacket dummy;
                pendingPackets.TryDequeue(out dummy);
            }
            else
            {
                var oldData = packet.Data;
                packet.Data = new ArraySegment <byte>(oldData.Array, oldData.Offset + copying, oldData.Count - copying);
            }
        }