Main Page | Class Hierarchy | Class List | File List | Class Members

SmartDeviceClient/SmartProtocolStack/RemoteHost/ReceiveQueue.cs

00001 using System;
00002 using System.Threading;
00003 using System.Collections;
00004 using GPRSWeb.SmartDeviceClient.Common;
00005 
00006 namespace GPRSWeb.SmartDeviceClient.SmartProtocolStack.RemoteHost
00007 {
00013         public class ReceiveQueue : Queue
00014         {
00016                 RemoteHostComms thisRemoteHost;
00017                 Segment workingSegment;
00018                 Thread processingThread;
00019 
00023                 public ReceiveQueue(RemoteHostComms thisRemoteHost) : base() {
00024                         this.thisRemoteHost = thisRemoteHost;
00025                 }
00026 
00027                 public void EnqueueBlocking(Segment seg) {
00028                         lock(SyncRoot) {
00029                                 base.Enqueue(seg);
00030                                 Monitor.PulseAll(SyncRoot);
00031                         }
00032                 }
00033                 
00034                 public Segment DequeueBlocking() {
00035                         Segment result;
00036                         lock(SyncRoot) {
00037                                 while (Count == 0) {
00038                                         Monitor.Wait(SyncRoot);
00039                                 }
00040                                 result = (Segment)base.Dequeue();
00041                                 Monitor.PulseAll(SyncRoot);
00042                         }
00043                         return result;
00044                 }
00045 
00046                 public void Start() {
00047                         if (processingThread == null || !processingThread.IsAlive) {
00048                                 processingThread = new Thread(new ThreadStart(ProcessQueue));
00049                                 processingThread.Start();
00050                         }
00051                 }
00052 
00053                 public void Stop() {
00054                         if (processingThread.IsAlive) {
00055                                 processingThread.Abort();
00056                                 processingThread.Join();
00057                         }
00058                 }
00059 
00060 
00064                 void ProcessQueue() {
00065                         while(true) {
00066                                 workingSegment = this.DequeueBlocking(); // blocks
00067                                 // Discard any duplicate or old segments
00068                                 if (thisRemoteHost.SeqManager.IsProcessable(workingSegment.Headers)) {
00069                                         ProcessSegmentHeaders(workingSegment.Headers, workingSegment.Data.DataLength);
00070                                         // send it for processing
00071                                         thisRemoteHost.MessageAssembler.Process(workingSegment);
00072                                 } // else drop and noop;        
00073                         }
00074                 }
00075 
00081                 private void ProcessSegmentHeaders(SegmentHeaders myHeaders, uint dataLength) {
00082                         /* updates protocol sequence number state, issues NACKs for missing segments */
00083                         thisRemoteHost.SeqManager.ProcessReceivedSegmentHeaders(ref myHeaders);
00084                         /* update ACK state*/
00085                         thisRemoteHost.AckManager.ProcessReceivedSegmentHeaders(ref myHeaders);
00086                         /* retransmit if we need to */
00087                         thisRemoteHost.NackManager.ProcessReceivedSegmentHeaders(ref myHeaders);
00088                         /* make new rate calculations */
00089                         thisRemoteHost.RateManager.ProcessReceivedSegmentHeaders(ref myHeaders, dataLength);
00090                 }
00091         }
00092 
00093 
00094 
00095 }

Generated on Mon May 8 22:07:27 2006 by  doxygen 1.3.9.1