Example #1
0
        /// <summary>
        /// Add a message for sending
        /// </summary>
        /// <param name="lightMessage"></param>
		public void Set(MemoryStream lightMessage)
		{
            lock (locker)
            {
                var id = Interlocked.Increment(ref msgId);
                LightSeparator newSep = null;
                if (used.Count > 0)
                {
                    newSep = used[0];
                    used.RemoveAt(0);
                }
                else
                    newSep = new LightSeparator();
                newSep.Initialize(lightMessage, id);
                queue.Add(newSep);
            }
		}
Example #2
0
		public void TestSendAndReceiveBasics(MemoryStream sendStream)
		{
			Console.WriteLine ("Test Send And Receive for size " + sendStream.Length+" b");
			var sep = new LightSeparator ();

			var asm = new QuantumReceiver ();

			MemoryStream received = null;

			asm.OnLightMessage+= (QuantumReceiver arg1, QuantumHead arg2, MemoryStream arg3) => 
			{
				received = new MemoryStream();
				arg3.WriteTo(received);
			};
			asm.OnCollectingError += (QuantumReceiver arg1, QuantumHead arg2, byte[] arg3) => {
				throw new Exception("Error during collecting");
			};
			Stopwatch tmr = new Stopwatch ();
			tmr.Start ();

			sep.Initialize (sendStream, 42);
			while (sep.DataLeft > 0) {
				var snd = sep.Next (500);
				asm.Set (snd);
			}

			if (received==null)
				throw new Exception ("No Receive");

			if (received.Length != sendStream.Length)
				throw new Exception ("Sended and received size are not equal");

			received.Position = 0;
			sendStream.Position = 0;

			tmr.Stop ();
			while (sendStream.Position < sendStream.Length) {
				var Bsended = sendStream.ReadByte ();
				var Breceived = received.ReadByte ();
				if (Bsended != Breceived)
					throw new Exception ("received and sended values are not equal");
			}

			Console.WriteLine ("SR done in " + tmr.ElapsedMilliseconds);

		}