DecodeInitialOfferMessage() публичный статический Метод

Unmarshal the initial offer message.
public static DecodeInitialOfferMessage ( byte byteArr ) : INITIAL_OFFER_MESSAGE
byteArr byte The payload.
Результат INITIAL_OFFER_MESSAGE
Пример #1
0
        /// <summary>
        /// Expect the INITIAL_OFFER_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 INITIAL_OFFER_MESSAGE received.</returns>
        /// <exception cref="NoINITIALOFFERMESSAGEReceivedException">
        /// Throw when no INITIAL_OFFER_MESSAGE request from the client.
        /// </exception>
        public INITIAL_OFFER_MESSAGE ExpectInitialOfferMessage(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;

            // Waiting for the initial offer message request until timeout.
            while (this.initialQueue.Count == 0)
            {
                // Waiting 100 milliseconds for the reqest.
                Thread.Sleep(100);
                if ((DateTime.Now - startTime).TotalMilliseconds > timeout.TotalMilliseconds)
                {
                    if (this.logger != null)
                    {
                        this.logger.AddWarning(string.Format(
                                                   "Waiting for {0} milliseconds, no expected INITIAL_OFFER_MESSAGE is received.",
                                                   timeout.TotalMilliseconds));
                    }

                    throw new NoINITIALOFFERMESSAGEReceivedException(string.Format(
                                                                         "Waiting for {0} milliseconds, no expected INITIAL_OFFER_MESSAGE is received.",
                                                                         timeout.TotalMilliseconds));
                }
            }

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

                this.httpRequest = this.initialQueue.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.DecodeInitialOfferMessage(this.httpRequestPayload));
        }