예제 #1
0
		private void ProcessOpen() {
			messageSource.Process();
			while (messageSource.AvailableMessageNo > 0) {
				byte[] message = messageSource.EmitMessage();
				if (message != null && message.Length > 0) {
					DecodeMessage(message);
				}
			}
			if (messageSource.State == WebChannelState.Closed || messageSource.State == WebChannelState.InitFailed) {
				State = WebChannelState.Closed;
			}
		}
예제 #2
0
 public void Process()
 {
     // test for invalid state
     if (State == WebChannelState.Closed || State == WebChannelState.InitFailed)
     {
         return;
     }
     source.Process();
     if (source.State == WebChannelState.Closed)
     {
         State = WebChannelState.Closed;
         return;
     }
     if (State == WebChannelState.InitFailed)
     {
         State = WebChannelState.InitFailed;
         return;
     }
     if (State == WebChannelState.Initializing)
     {
         // only snoop new messages if still initializing
         int messageNo = source.AvailableMessageNo;
         while (messageNo > snoopedBitNo)
         {
             byte[] bit = source.SnoopMessage(snoopedBitNo);
             if (bit.Length <= 0)
             {
                 throw new InvalidOperationException();
             }
             messageBits.Add(bit);
             snoopedBitNo += 1;
         }
         // try to extract a header
         if (messageHeader.Length == 0)
         {
             int headerLength = ExtractHeaderLength();
             if (headerLength > 0)
             {
                 messageHeader        = ExtractHeader(headerLength);
                 missingContentLength = ExtractContentLength(messageHeader);
             }
         }
         // try to extract message content
         if (messageHeader.Length > 0 && missingContentLength > 0)
         {
             messageContent = ExtractContent(messageHeader.Length, missingContentLength);
             if (messageContent.Length >= 0)
             {
                 // first message extraction successful
                 PostMessage(messageHeader.Length, missingContentLength);
                 BecomeOpen();
             }
         }
         // or go with no content if this is not required
         if (messageHeader.Length > 0 && missingContentLength == 0)
         {
             PostMessage(messageHeader.Length, 0);
             BecomeOpen();
         }
     }
     else
     {
         // read new messages
         int messageNo = source.AvailableMessageNo;
         if (messageNo > 0)
         {
             byte[] bit = source.EmitMessage();
             if (bit.Length == 0)
             {
                 throw new InvalidOperationException();
             }
             messageBits.Add(bit);
         }
         // try to extract a header
         if (messageHeader.Length == 0)
         {
             int headerLength = ExtractHeaderLength();
             if (headerLength > 0)
             {
                 messageHeader        = ExtractHeader(headerLength);
                 missingContentLength = ExtractContentLength(messageHeader);
             }
         }
         // try to extract message content
         if (messageHeader.Length > 0 && missingContentLength > 0)
         {
             messageContent = ExtractContent(messageHeader.Length, missingContentLength);
             if (messageContent.Length >= 0)
             {
                 PostMessage(messageHeader.Length, missingContentLength);
             }
         }
     }
 }