DecodeSegmentInfoMessage() public static method

Unmarshal the segment info message.
public static DecodeSegmentInfoMessage ( byte byteArr ) : SEGMENT_INFO_MESSAGE
byteArr byte The payload.
return SEGMENT_INFO_MESSAGE
Esempio n. 1
0
        /// <summary>
        /// Expect the SEGMENT_INFO_MESSAGE request from the client.
        /// </summary>
        /// <param name="ipaddress">The expected ipAddress of the remote endpoint which send request.</param>
        /// <param name="timeout">The waiting timeout.</param>
        /// <returns>Return the SEGMENT_INFO_MESSAGE received.</returns>
        /// <exception cref="NoSEGMENTINFOMESSAGEReceivedException">
        /// Throw when no SEGMENT_INFO_MESSAGE request from the client.
        /// </exception>
        public SEGMENT_INFO_MESSAGE ExpectSegmentInfoMessage(string ipaddress, TimeSpan timeout)
        {
            // Make sure the timeout is not less than 1000 milliseconds.
            if (timeout.TotalMilliseconds < 1000)
            {
                if (this.logger != null)
                {
                    this.logger.AddWarning(string.Format(
                                               "The timeout total milliseconds: {0} from the param \"timeout\" is too small.",
                                               timeout.TotalMilliseconds));
                }

                // Set the timeout to the default 5000 milliseconds.
                timeout = TimeSpan.FromMilliseconds(double.Parse("5000"));

                if (this.logger != null)
                {
                    this.logger.AddInfo(string.Format(
                                            "The timeout total milliseconds from the param \"timeout\" is set to the default value: {0} milliseconds.",
                                            timeout.TotalMilliseconds));
                }
            }

            DateTime startTime = DateTime.Now;

            while (this.segmentQueue.Count == 0)
            {
                // Waiting for the reqest.
                Thread.Sleep(100);
                if ((DateTime.Now - startTime).TotalMilliseconds > timeout.TotalMilliseconds)
                {
                    throw new NoSEGMENTINFOMESSAGEReceivedException(string.Format(
                                                                        "Waiting for {0} milliseconds, no expected SEGMENT_INFO_MESSAGE is received.",
                                                                        timeout.TotalMilliseconds));
                }
            }

            while (!this.segmentQueue.Peek().Request.RemoteEndPoint.Address.Equals(IPAddress.Parse(ipaddress)))
            {
                this.segmentQueue.Dequeue();
                if (this.segmentQueue.Count == 0)
                {
                    throw new InvalidOperationException();
                }

                this.httpRequest = this.segmentQueue.Peek().Request;
            }

            try
            {
                this.DecomposeHttpRequest(this.httpRequest);
            }
            catch (ObjectDisposedException e)
            {
                if (this.logger != null)
                {
                    this.logger.AddWarning(
                        string.Format("Object disposed exception is catched, detailed information: {0}.", e.Message));
                }
                else
                {
                    throw;
                }
            }

            return(DecodeMessage.DecodeSegmentInfoMessage(this.httpRequestPayload));
        }