Пример #1
0
        private bool CheckRequests()
        {
            LinkedListNode <HttpBase3.AsyncRequestState> linkedListNode = this._requestCache.First;

            while (linkedListNode != null)
            {
                LinkedListNode <HttpBase3.AsyncRequestState> node = linkedListNode;
                linkedListNode = linkedListNode.Next;
                if (node.Value.Request.isDone)
                {
                    this.GetResponse(node.Value);
                    this._requestCache.Remove(node);
                }
                else if (node.Value.IsTimedOut)
                {
                    HttpBase3.AsyncRequestState asyncRequestState = node.Value;
                    asyncRequestState.Abort();
                    if (this.debugOut >= DebugLevel.WARNING)
                    {
                        this.Listener.DebugReturn(DebugLevel.WARNING, string.Format("Request {0} for pid={1} cid={2} aborted by timeout", (object)asyncRequestState.id, (object)this.HttpPeerID, (object)this._challengId));
                    }
                    this.EnqueueErrorDisconnect(StatusCode.TimeoutDisconnect);
                    this._requestCache.Remove(node);
                    return(true);
                }
            }
            return(true);
        }
Пример #2
0
        private void GetResponse(HttpBase3.AsyncRequestState state)
        {
            WWW request = state.Request;

            if (request.error != null)
            {
                this._webExceptionHandler(state, request);
            }
            else
            {
                try
                {
                    if (request.bytes != null && request.bytes.Length > 0)
                    {
                        this.ReceiveIncomingCommands(request.bytes, request.bytes.Length);
                    }
                    Interlocked.Exchange(ref this._grossErrorCount, 0);
                }
                catch (Exception ex)
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, string.Format("exception: msg - {0}\n Stack\n{1}", (object)ex.StackTrace));
                    return;
                }
                this._checkAckCondition();
                state.Request.Dispose();
                state.OutgoingData = (byte[])null;
            }
        }
Пример #3
0
 private void _webExceptionHandler(HttpBase3.AsyncRequestState state, WWW request)
 {
     if (state.IsDisconnect)
     {
         return;
     }
     if ((this.peerConnectionState != PeerBase.ConnectionStateValue.Disconnecting || this.peerConnectionState != PeerBase.ConnectionStateValue.Disconnected) && !state.restarting && this.debugOut >= DebugLevel.ERROR)
     {
         this.Listener.DebugReturn(DebugLevel.ERROR, string.Format("Request {0} for pid={1} cid={2} failed with error: {3}", (object)state.id, (object)this.HttpPeerID, (object)this._challengId, (object)request.error));
     }
     if (this.peerConnectionState == PeerBase.ConnectionStateValue.Connecting)
     {
         this.EnqueueErrorDisconnect(StatusCode.ExceptionOnConnect);
     }
     else
     {
         if (this.peerConnectionState != PeerBase.ConnectionStateValue.Connected)
         {
             return;
         }
         if (HttpBase3.gotIgnoreStatus(this.getResponseStatus(request)))
         {
             if (this.debugOut < DebugLevel.ALL)
             {
                 return;
             }
             this.Listener.DebugReturn(DebugLevel.ALL, "got statues which we ignore");
         }
         else
         {
             this.EnqueueErrorDisconnect(StatusCode.DisconnectByServer);
         }
     }
 }
Пример #4
0
        internal void Request(byte[] data, string urlParameter, HttpBase3.MessageType type)
        {
            int num = Interlocked.Increment(ref this._stateIdBase);

            this._addAckId(ref urlParameter);
            HttpBase3.AsyncRequestState state = new HttpBase3.AsyncRequestState()
            {
                OutgoingData = data,
                type         = type,
                id           = num
            };
            this._requestCache.AddLast(state);
            this.Request(state, urlParameter);
        }
Пример #5
0
        private void Request(HttpBase3.AsyncRequestState state, string urlParamter)
        {
            urlParamter = !this.UseGet ? urlParamter + string.Format("&seq={0}", (object)state.id) : urlParamter + string.Format("&seq={0}&data={1}", (object)state.id, (object)Convert.ToBase64String(state.OutgoingData, Base64FormattingOptions.None));
            if (state.type == HttpBase3.MessageType.DISCONNECT)
            {
                urlParamter += "&dis";
            }
            if (this.debugOut >= DebugLevel.ALL)
            {
                this.Listener.DebugReturn(DebugLevel.ALL, string.Format("url for request is {0}", (object)urlParamter));
            }
            string url = this.ServerAddress + urlParamter + this.HttpUrlParameters;

            if (this.UseGet)
            {
                state.Request = new WWW(url);
            }
            else
            {
                state.Request = new WWW(url, this.GetPOSTRequestData(state));
            }
        }
Пример #6
0
 private byte[] GetPOSTRequestData(HttpBase3.AsyncRequestState state)
 {
     return(state.OutgoingData);
 }