예제 #1
0
 private void thread_do_recv()
 {
     Thread.CurrentThread.IsBackground = true;
     IPEndPoint srv = new IPEndPoint(IPAddress.Any, 0);
     MemoryStream ms;
     while (this.go)
     {
         //Console.WriteLine("waiting..." + Thread.CurrentThread.Name);
         byte[] data = this.Receive(ref srv);
         //Console.WriteLine("NW-" + myID + " Recv: " + data.Length + " bytes");
         Packet p = new Packet();
         //p.data = new byte[200];
         p.Dest = srv;
         ms = new MemoryStream(data);
         p.ptype = (Packet.PacketType)ms.ReadByte();
         ms.Read(p.data, 0, (int)ms.Length - 1);
         lock (readBuffer)
         {
             readBuffer.Enqueue(p);
             //if (readBuffer.Count > 50)
             //{
             //    Console.WriteLine("ReadBuffer falling behind {0}:" + Thread.CurrentThread.Name, readBuffer.Count);
             //}
         }
         this.nextSem.Release();
     }
 }
예제 #2
0
 public void commitPacket(Packet p)
 {
     lock (this.buffer)
     {
         this.buffer.Enqueue(p);
         //Console.WriteLine("Backlog Commit: {0} "+Thread.CurrentThread.Name, buffer.Count);
     }
     this.sendSem.Release();
 }